((# IMPORT MACROS #))
((* from "components/section_contents.tex.j2" import section_contents with context *))
((* from "components/header.tex.j2" import header with context *))

\documentclass[<<design.font_size>>, <<design.page_size>>]{article}

% Packages:
\usepackage[
        ignoreheadfoot, % set margins without considering header and footer
        top=<<theme_options.margins.page.top>>, % seperation between body and page edge from the top
        bottom=<<theme_options.margins.page.bottom>>, % seperation between body and page edge from the bottom
        left=<<theme_options.margins.page.left>>, % seperation between body and page edge from the left
        right=<<theme_options.margins.page.right>>, % seperation between body and page edge from the right
        % showframe % for debugging
    ]{geometry} % for adjusting page geometry
\usepackage{fontspec} % for loading fonts
\usepackage[explicit]{titlesec} % for customizing section titles
\usepackage{tabularx} % for making tables with fixed width columns
\usepackage{array} % tabularx requires this
\usepackage[dvipsnames]{xcolor} % for coloring text
\definecolor{primaryColor}{RGB}{<<theme_options.primary_color.as_rgb_tuple()|join(", ")>>} % define primary color
\usepackage{enumitem} % for customizing lists
\usepackage{fontawesome5} % for using icons
\usepackage[
    pdftitle={<<cv.name>>'s CV},
    pdfauthor={<<cv.name>>},
    colorlinks=true,
    urlcolor=primaryColor
]{hyperref} % for links, metadata and bookmarks
\usepackage[pscoord]{eso-pic} % for floating text on the page
\usepackage{calc} % for calculating lengths

% Some settings:
\pagestyle{empty} % no header or footer
\setcounter{secnumdepth}{0} % no section numbering
\setlength{\parindent}{0pt} % no indentation
\setlength{\topskip}{0pt} % no top skip
\pagenumbering{gobble} % no page numbering


\setmainfont{<<design.font>>}[
    Path= fonts/,
    Extension = .ttf,
    UprightFont = *-Regular,
    ItalicFont = *-Italic,
    BoldFont = *-Bold,
    BoldItalicFont = *-BoldItalic
]

\titleformat{\section}{
        % make the font size of the section title large and color it with the primary color
        \Large\color{primaryColor}
    }{
    }{
    }{
        % print bold title, give 0.15 cm space and draw a line of 0.8 pt thickness
        % from the end of the title to the end of the body
        \textbf{#1}\hspace{0.15cm}\titlerule[0.8pt]
    }[] % section title formatting

\titlespacing{\section}{
        % left space:
        0pt
    }{
        % top space:
        <<theme_options.margins.section_title.top>>
    }{
        % bottom space:
        <<theme_options.margins.section_title.bottom>>
    } % section title spacing

\newcolumntype{L}[1]{
    >{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}
} % left-aligned fixed width column type
\newcolumntype{R}[1]{
    >{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}
} % right-aligned fixed width column type
\newcolumntype{K}[1]{
    >{\raggedright\let\newline\\\arraybackslash\hspace{-0.2cm}\hspace{#1}}X
} % left-aligned flexible width column type

\newenvironment{highlights}{
        \begin{itemize}[
                topsep=0pt,
                parsep=<<theme_options.margins.highlights_area.vertical_between_bullet_points>>,
                partopsep=0pt,
                itemsep=0pt,
                after=\vspace*{-1\baselineskip},
                leftmargin=<<theme_options.margins.highlights_area.left>> + 3pt
            ]
    }{
        \end{itemize}
    } % new environment for highlights

\newenvironment{header}{
        \setlength{\topsep}{0pt}\par\kern\topsep\centering\color{primaryColor}\linespread{1.5}
    }{
        \par\kern\topsep
    } % new environment for the header

\newcommand{\placelastupdatedtext}{% \placetextbox{<horizontal pos>}{<vertical pos>}{<stuff>}
  \AddToShipoutPictureFG*{% Add <stuff> to current page foreground
    \put(
        \LenToUnit{\paperwidth-<<theme_options.margins.page.right>>},
        \LenToUnit{\paperheight-<<theme_options.margins.page.top|divide_length_by(2)>>}
    ){\vtop{{\null}\makebox[0pt][c]{
        \small\color{gray}\emph{Last updated on <<today>>} \hspace{\widthof{Last updated on <<today>>}}
    }}}%
  }%
}%

\newcommand{\hrefExternal}[2]{\href{#1}{#2\, \raisebox{.1ex}{\footnotesize \faExternalLink*}}} % new command for external links

\begin{document}
((* if theme_options.show_last_updated_date *))
    \placelastupdatedtext
((* endif *))

    <<header(name=cv.name, connections=cv.connections)|indent(4)>>
((* if cv.summary is not none *))
    \section{Summary}

    \setlength{\leftskip}{<<theme_options.margins.entry_area.left>>}
    \setlength{\rightskip}{<<theme_options.margins.entry_area.right>>}

    <<cv.summary>>

    \setlength{\leftskip}{0cm}
    \setlength{\rightskip}{0cm}
((* endif *))

((* for section in cv.sections *))
    \section{<<section.title>>}
    
    <<section_contents(title=section.title, entries=section.entries, entry_type=section.entry_type, link_text=section.link_text)|indent(4)>>

((* endfor *))

\end{document}