\documentclass{default}

{{- if .Layout }}
{{- if eq (default "standard" .Layout.Density) "compact" }}
\AtBeginDocument{\setdensitycompact}
{{- else if eq .Layout.Density "detailed" }}
\AtBeginDocument{\setdensityrelaxed}
{{- end }}
{{- if eq (default "classic" .Layout.Typography) "modern" }}
\AtBeginDocument{\settypographymodern}
{{- else if eq .Layout.Typography "elegant" }}
\AtBeginDocument{\settypographyelegant}
{{- end }}
{{- end }}

\begin{document}

% ============================================================================
% HEADER
% ============================================================================
\resumename{ {{- escape .Contact.Name -}} }
{{- if .Contact.Headline }}
\resumetitle{ {{- escape .Contact.Headline -}} }
{{- end }}

\resumecontact{%
    \email{ {{- escape .Contact.Email -}} }%
    {{- if .Contact.Phone }}
    \sep%
    \phone{ {{- escape .Contact.Phone -}} }%
    {{- end }}
    {{- if .Contact.Credentials }}
    \sep%
    {{ escape .Contact.Credentials }}%
    {{- end }}
{{- range .Contact.Links }}
    \sep%
    {{ fmtLinkWithDomain . }}%
{{- end }}
}

{{/* ============================================================================
     SECTION DEFINITIONS
     ============================================================================ */}}

{{- define "latex-section-summary" -}}
{{- if .Summary }}

% SUMMARY
\section*{Professional Summary}
{{ emphasize .Summary .Layout }}
{{- end }}
{{- end -}}

{{- define "latex-section-certifications" -}}
{{- if .Certifications }}
{{- if .Certifications.Items }}

% CERTIFICATIONS
\section*{{ "{" }}{{ escape (default "Certifications" .Certifications.Title) }}{{ "}" }}
\begin{itemize}
{{- range .Certifications.Items }}
    \item {{ escape .Name }}{{- if .Issuer }} --- {{ escape .Issuer }}{{- end }}{{- if .Notes }} ({{ escape .Notes }}){{- end }}
{{- end }}
\end{itemize}
{{- end }}
{{- end }}
{{- end -}}

{{- define "latex-section-experience" -}}
{{- if .Experience.Positions }}

% EXPERIENCE
\section*{{ "{" }}{{ escape (default "Experience" .Experience.Title) }}{{ "}" }}
{{- range sortExperienceByOrder .Experience.Positions }}
{{- if .Location }}
\resumeentry{ {{- escape .Title -}} }{ {{- escape .Company -}} }{ {{- fmtDates .Dates -}} }
{{- else }}
\resumeentry{ {{- escape .Title -}} }{ {{- escape .Company -}} }{ {{- fmtDates .Dates -}} }
{{- end }}
{{- if .Technologies }}
\vspace{1pt}
\noindent\textit{ {{- formatList .Technologies -}} }
{{- end }}
{{- $high := filterEmpty .Highlights }}
{{- if $high }}
\begin{itemize}
{{- range $high }}
    \item {{ emphasize . $.Layout }}
{{- end }}
\end{itemize}
{{- end }}
{{- end }}
{{- end }}
{{- end -}}

{{- define "latex-section-education" -}}
{{- if .Education.Institutions }}

% EDUCATION
\section*{{ "{" }}{{ escape (default "Education" .Education.Title) }}{{ "}" }}
{{- range sortEducationByOrder .Education.Institutions }}
{{- if .Location }}
\resumeeducation{ {{- escape .Institution -}} }{ {{- escape .Degree.Name -}} }{ {{- fmtDates .Dates -}} }{ {{- fmtLocation .Location -}} }
{{- else }}
\resumeeducation{ {{- escape .Institution -}} }{ {{- escape .Degree.Name -}} }{ {{- fmtDates .Dates -}} }{}
{{- end }}
{{- $descriptions := filterEmpty .Degree.Descriptions }}
{{- if .GPA }}
\begin{description}
    \item[GPA:] {{ formatGPA .GPA }}
\end{description}
{{- end }}
{{- if $descriptions }}
\begin{itemize}
    {{- range $descriptions }}
    \item {{ emphasize . $.Layout }}
    {{- end }}
\end{itemize}
{{- end }}
{{- if .Thesis }}
\vspace{0.3ex}
\noindent \textbf{Honours Thesis: {{ escape .Thesis.Title }}} {{- if .Thesis.Link.URI }} \hfill \href{ {{- .Thesis.Link.URI -}} }{ {{- extractDisplayURL .Thesis.Link.URI -}} }{{- end }}
{{- if .Thesis.Highlights }}
\begin{itemize}
{{- range .Thesis.Highlights }}
    \item {{ emphasize . $.Layout }}
{{- end }}
\end{itemize}
{{- end }}
\par\vspace{0.3ex}
{{- end }}
{{- end }}
{{- end }}
{{- end -}}

{{- define "latex-section-skills" -}}
{{- if .Skills.Categories }}

% SKILLS
\section*{{ "{" }}{{ escape (default "Skills" .Skills.Title) }}{{ "}" }}
\begin{description}
{{- range .Skills.Categories }}
    \item[{{ escape .Category }}:] {{ formatList .Items }}
{{- end }}
\end{description}
{{- end }}
{{- end -}}

{{- define "latex-section-projects" -}}
{{- if .Projects }}
{{- if .Projects.Projects }}

% PROJECTS
\section*{{ "{" }}{{ escape (default "Projects" .Projects.Title) }}{{ "}" }}
{{- range sortProjectsByOrder .Projects.Projects }}
{{- if .Link.URI }}
\noindent \textbf{ {{ escape .Name }} } \hfill \href{ {{- .Link.URI -}} }{ {{- extractDisplayURL .Link.URI -}} } \par
{{- else }}
\noindent \textbf{ {{ escape .Name }} } \par
{{- end }}
{{- if .Technologies }}
\noindent\textit{ {{- formatList .Technologies -}} }
{{- end }}
{{- $high := filterEmpty .Highlights }}
{{- if $high }}
    \begin{itemize}
    {{- range $high }}
        \item {{ emphasize . $.Layout }}
    {{- end }}
    \end{itemize}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end -}}

{{- define "latex-section-languages" -}}
{{- if .Languages }}
{{- if .Languages.Languages }}

% LANGUAGES
\section*{{ "{" }}{{ escape (default "Languages" .Languages.Title) }}{{ "}" }}
\begin{itemize}
{{- range .Languages.Languages }}
    \item {{ escape .Name }}{{- if .Proficiency }} --- {{ escape .Proficiency }}{{- end }}
{{- end }}
\end{itemize}
{{- end }}
{{- end }}
{{- end -}}

{{/* ============================================================================
     SECTION DISPATCH
     ============================================================================ */}}

{{- $root := . -}}
{{- range .SectionOrder -}}
{{- if eq . "summary"}}{{template "latex-section-summary" $root}}
{{- else if eq . "certifications"}}{{template "latex-section-certifications" $root}}
{{- else if eq . "experience"}}{{template "latex-section-experience" $root}}
{{- else if eq . "education"}}{{template "latex-section-education" $root}}
{{- else if eq . "skills"}}{{template "latex-section-skills" $root}}
{{- else if eq . "projects"}}{{template "latex-section-projects" $root}}
{{- else if eq . "languages"}}{{template "latex-section-languages" $root}}
{{- end}}
{{- end}}

{{- if and .Layout .Layout.References }}

\vfill
\begin{center}\textit{References available upon request}\end{center}
{{- end }}

\end{document}
