%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

\documentclass[$fontsize$, a4paper]{article}
\usepackage{fontspec}

% LAYOUT
%--------------------------------
\usepackage{geometry}
\geometry{$geometry$}

% No page numbers
\pagenumbering{gobble}

% Left align
\usepackage[document]{ragged2e}

% Trim excessive whitespace before lists
\usepackage{enumitem}
\setlist{nolistsep}

$if(page-background)$
\usepackage[pages=all]{background}
$endif$

$if(letterhead)$
\usepackage{wallpaper}
\addtolength{\wpXoffset}{-5cm}
\addtolength{\wpYoffset}{11cm}
% \ThisULCornerWallPaper{1}{letterhead-front.pdf} % Uncomment to include a different letterhead on the first page
\CenterWallPaper{0.2}{$letterhead$}
$endif$

\usepackage{fontawesome5}

% LANGUAGE
%--------------------------------
$if(lang)$
\usepackage{polyglossia}
\setmainlanguage{$lang$}
$endif$

% TYPOGRAPHY
%--------------------------------
\usepackage{xunicode}
\usepackage{xltxtra}
\usepackage[protrusion=true,final]{microtype}

% converts LaTeX specials (quotes, dashes etc.) to Unicode
\defaultfontfeatures{Mapping=tex-text}
\setromanfont [Ligatures={Common}, Numbers={OldStyle}]{$mainfont$}
\setsansfont[Scale=0.9]{$altfont$}
\setmonofont[Scale=0.8]{$monofont$}

% Set paragraph break
\setlength{\parskip}{1em}

% Custom ampersand
\newcommand{\amper}{{\fontspec[Scale=.95]{$mainfont$}\selectfont\itshape\&}}

$if(mainfont)$
    \setmainfont{$mainfont$}
$endif$
$if(altfont)$
    \setsansfont{$altfont$}
$endif$

% Command required by how Pandoc handles the list conversion
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}

% PDF SETUP
%--------------------------------
\usepackage[xetex, bookmarks, colorlinks, breaklinks]{hyperref}
\hypersetup
{
  pdfauthor={$author$},
  pdfsubject={$subject$},
  pdftitle={$subject$},
  colorlinks,breaklinks,
  filecolor=black,
  urlcolor=[rgb]{0.117,0.682,0.858},
  linkcolor=[rgb]{0.117,0.682,0.858},
  linkcolor=[rgb]{0.117,0.682,0.858},
  citecolor=[rgb]{0.117,0.682,0.858}
}

% To display custom date in the example
$if(customdate)$
\usepackage[$lang$]{datetime2}
\DTMsavedate{customdate}{$customdate$}
$endif$

$if(page-background)$
\backgroundsetup{
scale=1,
color=black,
opacity=$if(page-background-opacity)$$page-background-opacity$$else$0.2$endif$,
angle=0,
contents={%
  \includegraphics[width=\paperwidth,height=\paperheight]{$page-background$}
  }%
}
$endif$

% remove section numbering
\setcounter{secnumdepth}{-\maxdimen} 

% DOCUMENT
%--------------------------------
\begin{document}
\small

\textsc{\textbf{$author$}\\$affiliation1$}\\ \textsc{$affiliation2$}\\ 
$for(from)$
\textsc{$from$}
$endfor$

%$for(contact)$
%\textsc{$contact$}
%$endfor$

\vspace{2em}

\normalsize \sffamily
$for(to)$
$to$\\
$endfor$

%\vspace{3em}

\rmfamily
\begin{flushright}
  $city$ \textbullet{} $if(customdate)$\DTMusedate{customdate}$else$\today$endif$
\end{flushright}

%\vspace{1em}

%$if(subject)$
%\textbf{$subject$}
%$endif$

%\vspace{1em}

%$salutation$ $toname$:

$body$

$if(signature)$
  \begin{FlushRight}  
    \IfFileExists{$signature$}
    {
      \includegraphics[height=5.5\baselineskip]{$signature$} \par
    }
    {
      \vspace{5.5\baselineskip}
    }
    $author$  
  \end{FlushRight}
$endif$

\end{document}
