%%
%% this template copied a few sections from the eisvogel template,
%% thus follows its license.
%%

%%
% Copyright (c) 2017 - 2026, Pascal Wagler;
% Copyright (c) 2014 - 2026, John MacFarlane
%
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions
% are met:
%
% - Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
%
% - Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in the
% documentation and/or other materials provided with the distribution.
%
% - Neither the name of John MacFarlane nor the names of other
% contributors may be used to endorse or promote products derived
% from this software without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
% FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
% COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
% INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
% BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
% LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
% ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%%

\documentclass[
$if(fontsize)$
    $fontsize$,
$else$
    12pt,
$endif$
$for(classoption)$
    $classoption$$sep$,
$endfor$
    a4paper
]{article}

\usepackage{lmodern}
\usepackage{xcolor}
\usepackage{amsmath,amssymb}
\usepackage{parskip}

\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}

% -------------
% code listings
% -------------
\usepackage{listings}
\usepackage{listingsutf8}
\usepackage{colortbl}

\definecolor{lstforeground}{HTML}{000000}
\definecolor{lstbackground}{HTML}{F2F2F2}
\definecolor{lstkeywords}{HTML}{008AD4}
\definecolor{lstcomments}{HTML}{9C9C9C}
\definecolor{lstnumbers}{HTML}{9C9C9C}
\definecolor{lststrings}{HTML}{AE81FF}
\definecolor{lstidentifiers}{HTML}{734526}

\lstdefinelanguage{none}{
  identifierstyle=
}

\lstdefinestyle{listingstyle}{
    backgroundcolor=\color{lstbackground},
    commentstyle=\color{lstcomments}\itshape,
    keywordstyle=\color{lstkeywords}\bfseries,
    numberstyle=\color{lstnumbers}\ttfamily\small,
    stringstyle=\color{lststrings},
    identifierstyle  = \color{lstidentifiers},
    basicstyle=\ttfamily\small\color{lstforeground},
    xleftmargin      = 2.7em,
    framexleftmargin = 2.5em,
    frame            = single,
    framesep         = 0.19em,
    aboveskip        = 1.0em,
    belowskip        = 0.1em,
    abovecaptionskip = 0em,
    belowcaptionskip = 1.0em,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    keepspaces=true,
    numbers=left,
    numbersep=5pt,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    tabsize=4,
    inputencoding=utf8,
    extendedchars=true,
    columns=fullflexible,
    literate=
    {á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1
    {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1
    {à}{{\`a}}1 {è}{{\`e}}1 {ì}{{\`i}}1 {ò}{{\`o}}1 {ù}{{\`u}}1
    {À}{{\`A}}1 {È}{{\`E}}1 {Ì}{{\`I}}1 {Ò}{{\`O}}1 {Ù}{{\`U}}1
    {ä}{{\"a}}1 {ë}{{\"e}}1 {ï}{{\"i}}1 {ö}{{\"o}}1 {ü}{{\"u}}1
    {Ä}{{\"A}}1 {Ë}{{\"E}}1 {Ï}{{\"I}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1
    {â}{{\^a}}1 {ê}{{\^e}}1 {î}{{\^i}}1 {ô}{{\^o}}1 {û}{{\^u}}1
    {Â}{{\^A}}1 {Ê}{{\^E}}1 {Î}{{\^I}}1 {Ô}{{\^O}}1 {Û}{{\^U}}1
    {œ}{{\oe}}1 {Œ}{{\OE}}1 {æ}{{\ae}}1 {Æ}{{\AE}}1 {ß}{{\ss}}1
    {ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1 {å}{{\r a}}1 {Å}{{\r A}}1
    {€}{{\EUR}}1 {£}{{\pounds}}1 {«}{{\guillemotleft}}1
    {»}{{\guillemotright}}1 {ñ}{{\~n}}1 {Ñ}{{\~N}}1 {¿}{{?`}}1
    {…}{{\ldots}}1 {≥}{{>=}}1 {≤}{{<=}}1 {„}{{\glqq}}1 {“}{{\grqq}}1
    {”}{{''}}1
}
\lstset{style=listingstyle}

% required by pandoc, defined manually to not have to import
% any (bloated) pandoc partials
\newcommand{\passthrough}[1]{#1}

% -----------------
% paragraph spacing
% -----------------
\widowpenalty=10000
\clubpenalty=10000
\brokenpenalty=10000
\interlinepenalty=10000

\makeatletter
\ifx\paragraph\undefined\else
  \let\oldparagraph\paragraph
  \renewcommand{\paragraph}{
    \@ifstar
      \zzParagraphStar
      \zzParagraphNoStar
  }
  \newcommand{\zzParagraphStar}[1]{\oldparagraph*{#1}\mbox{}}
  \newcommand{\zzParagraphNoStar}[1]{\oldparagraph{#1}\mbox{}}
\fi
\ifx\subparagraph\undefined\else
  \let\oldsubparagraph\subparagraph
  \renewcommand{\subparagraph}{
    \@ifstar
      \zzSubParagraphStar
      \zzSubParagraphNoStar
  }
  \newcommand{\zzSubParagraphStar}[1]{\oldsubparagraph*{#1}\mbox{}}
  \newcommand{\zzSubParagraphNoStar}[1]{\oldsubparagraph{#1}\mbox{}}
\fi
\makeatother

% ------
% tables
% ------
$if(tables)$
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{array}
\usepackage{calc}
% \newcounter{none}
$if(multirow)$
\usepackage{multirow}
$endif$

\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother

\setlength\heavyrulewidth{0.3ex}      % thickness of \toprule, \bottomrule
\renewcommand{\arraystretch}{1.3}     % spacing (padding)

$endif$

% -----------------
% page layout/style
% -----------------
$if(pagestyle)$
\pagestyle{$pagestyle$}
$endif$

\usepackage[margin=3.5cm]{geometry}

% page numbering
\usepackage{scrlayer-scrpage}
\usepackage{lastpage}
\ohead{}
\cfoot{\thepage\ of \pageref{LastPage}}

% ----------------------
% prevent overfull lines
% ----------------------
\setlength{\emergencystretch}{3em}

% -----------
% tight lists
% -----------
\providecommand{\tightlist}{
    \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}
}

% -----------
% blockquotes
% -----------
\definecolor{blockquote-border}{RGB}{140,140,140}
\definecolor{blockquote-text}{RGB}{0,0,0}
\usepackage{mdframed}
\mdfsetup{
    rightline=false,
    bottomline=false,
    topline=false,
    linewidth=3pt,
    linecolor=blockquote-border,
    skipabove=3ex,
    skipbelow=1ex,
    innertopmargin=0pt,
    innerbottommargin=0pt,
}
\newmdenv{customblockquote}
\renewenvironment{quote}{\begin{customblockquote}\list{}{\rightmargin=0em\leftmargin=0em}
\item\relax\color{blockquote-text}\ignorespaces}{\unskip\unskip\endlist\end{customblockquote}}

% --------
% graphics
% --------
\usepackage{graphicx}

\makeatletter
\newsavebox\pandoc@box
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
  \sbox\pandoc@box{#1}
  \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}
  \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}
  \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
  \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}
  \else\usebox{\pandoc@box}
  \fi
}
\makeatother

% set sane defaults for placement of floating matter
% (e.g. images and tables)
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{4}
\renewcommand{\topfraction}{0.9}
\renewcommand{\bottomfraction}{0.8}
\renewcommand{\textfraction}{0.07}
\renewcommand{\floatpagefraction}{0.8}
\usepackage{float}
% \floatplacement{figure}{htp}
\floatplacement{figure}{H}

$if(svg)$
\usepackage{svg}
$endif$

% -----------------------
% hyperreferences (links)
% -----------------------
\PassOptionsToPackage{hyphens}{url}
\usepackage{url}
\usepackage{hyperref}
\hypersetup{
    unicode=true,
    pdfborder={0 0 0 [0 0]},
    colorlinks=true,
    allcolors=black,
    linkcolor=blue,
    urlcolor=blue,
}

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

% ------------
% bullet lists
% ------------
\def\itempoint{$$\star$$}
\renewcommand{\labelitemi}{\itempoint}
\renewcommand{\labelitemii}{\itempoint}
\renewcommand{\labelitemiii}{\itempoint}
\renewcommand{\labelitemiv}{\itempoint}

% --------
% stuff ..
% --------
$if(title)$
\title{$title$$if(thanks)$\thanks{$thanks$}$endif$}
$endif$
$if(subtitle)$
\usepackage{etoolbox}
\makeatletter
\providecommand{\subtitle}[1]{% add subtitle to \maketitle
  \apptocmd{\@title}{\par {\large #1 \par}}{}{}
}
\makeatother
\subtitle{$subtitle$}
$endif$
\author{$for(author)$$author$$sep$ \and $endfor$}
\date{$date$}

% --------------
% begin document
% --------------
\begin{document}
$if(has-frontmatter)$
\frontmatter
$endif$
$if(title)$
\maketitle
$if(abstract)$
\begin{abstract}
$abstract$
\end{abstract}
$endif$
$endif$

$for(include-before)$
$include-before$

$endfor$
$if(toc)$
$if(toc-title)$
\renewcommand*\contentsname{$toc-title$}
$endif$
{
$if(colorlinks)$
\hypersetup{linkcolor=$if(toccolor)$$toccolor$$else$$endif$}
$endif$
\setcounter{tocdepth}{$toc-depth$}
\tableofcontents
}
$endif$
$if(lof)$
\listoffigures
$endif$
$if(lot)$
\listoftables
$endif$
$if(linestretch)$
\setstretch{$linestretch$}
$endif$
$if(has-frontmatter)$
\mainmatter
$endif$
$body$

$if(has-frontmatter)$
\backmatter
$endif$
$if(natbib)$
$if(bibliography)$
$if(biblio-title)$
$if(has-chapters)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}

$endif$
$endif$
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$

$endif$
$for(include-after)$
$include-after$

$endfor$
\end{document}
