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

%\documentclass[$fontsize$, a4paper]{article}
\documentclass[$fontsize$, a4paper, headings=small, markcase=upper]{scrartcl}
\usepackage{fontspec}
\usepackage{amsmath}

% KOMASCRIPT
%--------------------------------
\DeclareOldFontCommand{\rm}{\normalfont\rmfamily}{\mathrm}
\DeclareOldFontCommand{\sf}{\normalfont\sffamily}{\mathsf}
\DeclareOldFontCommand{\tt}{\normalfont\ttfamily}{\mathtt}
\DeclareOldFontCommand{\bf}{\normalfont\bfseries}{\mathbf}
\DeclareOldFontCommand{\it}{\normalfont\itshape}{\mathit}
\DeclareOldFontCommand{\sl}{\normalfont\slshape}{\@nomath\sl}
\DeclareOldFontCommand{\sc}{\normalfont\scshape}{\@nomath\sc}
\DeclareRobustCommand*\cal{\@fontswitch\relax\mathcal}
\DeclareRobustCommand*\mit{\@fontswitch\relax\mathnormal}
\makeatletter

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

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

% Spacing after section headers
\RedeclareSectionCommand[
  beforeskip=-\baselineskip,
  afterskip=.1\baselineskip]{section}
\RedeclareSectionCommand[
  beforeskip=-.75\baselineskip,
  afterskip=.1\baselineskip]{subsection}
\RedeclareSectionCommand[
  beforeskip=-.5\baselineskip,
  afterskip=.1\baselineskip]{subsubsection}
\RedeclareSectionCommand[
  beforeskip=.5\baselineskip,
  afterskip=-1em]{paragraph}
\RedeclareSectionCommand[
  beforeskip=-.5\baselineskip,
  afterskip=-1em]{subparagraph}

% Multi-column support
$if(multicol)$
\usepackage{multicol}
\setlength{\columnsep}{$columnsep$}
$endif$

% Header and footer
\usepackage[headsepline,automark]{scrlayer-scrpage}
\pagestyle{scrheadings}
\ihead{$course$ - $title$$if(subtitle)$ - $subtitle$$endif$}
\ohead[]{\headmark}
\chead{}
%\renewcommand*{\titlepagestyle}{scrheadings}

% Figure floats
\usepackage{float}
\let\origfigure=\figure
\let\endorigfigure=\endfigure
\renewenvironment{figure}[1][]{%
  \origfigure[H]
}{%
  \endorigfigure
}

% 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$}
\setromanfont[Ligatures={Common}]{$mainfont$}
\setsansfont[Scale=1]{$altfont$}
\setmonofont[Scale=0.8]{$monofont$}

% Set paragraph break
\setlength{\parskip}{$parskip$}
\setlength{\parindent}{$parindent$}

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

% Upper-case section headings
\renewcommand\sectionlinesformat[4]{%
  \@hangfrom{\hskip#2#3}{\MakeUppercase{#4}}%
}

% Remove numbers from section headings
\renewcommand*{\sectionformat}{}
\renewcommand*{\subsectionformat}{}
\renewcommand*{\subsubsectionformat}{}

% Make section headings slightly bigger than subsection headings
\addtokomafont{section}{\large}

% Center sectionheads
%\let\raggedsection\centering

$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={$course$},
  pdftitle={$course$ - $title$},
  colorlinks,breaklinks,
  filecolor=black,
  urlcolor=[rgb]{0,0,0.7},
  linkcolor=[rgb]{0,0,0.7},
  citecolor=[rgb]{0,0,0.7}
  %urlcolor=[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$

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

\subject{\vspace{-6ex}$course$\vspace{-1.5ex}}
\title{$title$}
$if(subtitle)$
\subtitle{$subtitle$}
$endif$
\author{\vspace{-1ex}$author_name$, $author_group$, $author_id$}
\date{\vspace{-1ex}
\today}
%\begin{spacing}{1}
%\maketitle \end{spacing}
\maketitle

$if(multicol)$
\begin{multicols}{$columns$}
$endif$

$body$

$if(multicol)$
\end{multicols}
$endif$

\end{document}
