% pandoc WBH Prüfungsvorlage
%
% Diese Vorlage ist für Prüfungen an der Wilhelm-Büchner-Hochschule erstellt worden
% sie entspricht den Vorgaben für Hausarbeiten und Thesis zum aktuellen Zeitpunkt.
% 
% Autoren:
%
% Created:
% Changed: 26.06.2020

\documentclass[
    12pt,
    a4paper,
    $if(lang)$
        $babel-lang$,
    $endif$
    bibliography=totocnumbered,
    listof=totocnumbered
]{scrartcl}

$if(lang)$
% Support different languages
% default: en
% -----------------------------------------------------------------------
\usepackage[shorthands=off,$for(babel-otherlangs)$$babel-otherlangs$,$endfor$main=$babel-lang$]{babel}

$if(babel-newcommands)$
$babel-newcommands$
$endif$

%\usepackage[utf8]{inputenc}
$endif$
\usepackage[usenames,dvipsnames]{color}
\usepackage{amsmath}												% For pandoc extensive `amsmath` collection of symbols for typesetting ordinary math
\usepackage{amsfonts}												% More symboles for exotic currency notation and engeneering diagrams
\usepackage{amssymb}												% More symboles for exotic currency notation and engeneering diagrams
\usepackage{siunitx}                        % For using SI Units https://www.ctan.org/pkg/siunitx
\usepackage{fancyhdr}
\usepackage{tabularx}
\usepackage[a4paper, top=27mm, left=20mm, right=40mm, bottom=35mm, headsep=10mm, footskip=12mm]{geometry} % Vorgabe 4cm Rand auf der rechten Seite.
\usepackage{setspace}
\usepackage[right]{eurosym}
\usepackage[printonlyused]{acronym}
\usepackage{subfig}
\usepackage{floatflt}
\usepackage{colortbl}
\usepackage{paralist}
\usepackage{array}
\usepackage{parskip}
\usepackage[right]{eurosym}
\usepackage[subfigure,titles]{tocloft}
\usepackage{helvet}
\usepackage{graphicx}
\usepackage[export]{adjustbox} % also loads graphicx, to have max width for graphics
\usepackage{pdfpages}
\usepackage{tikz}


% ----------------------------------------------------------------------------------------------------------
% Firstname + Lastname
% ----------------------------------------------------------------------------------------------------------

$if(student.firstname)$
% Firstname is set, assume name is Firstnaem + Lastname
\def \studentname{$student.firstname$ $student.lastname$}
$else$
% Firstname is not set, studentname = name
\def \studentname{$student.name$}
$endif$

% ----------------------------------------------------------------------------------------------------------
% Aufgabenstellung
% ----------------------------------------------------------------------------------------------------------
% Debug: 
% include: $assignment.include$ file: $assignment.file$ pages: $assignment.pages$

\def \assignment{
    
% Regular include for historic reasons
%------------------
% include assignment is on
% \includepdf[pages=$assignment.pages$]{$assignment.file$}
% New include for historic reasons
%------------------

% check if assignment.file is set at all 
$if(assignment.file)$
% check if form shall be filled out
$if(assignment.fillform)$
\includepdf[pagecommand={  % 23mm, 6mm
\begin{tikzpicture}[remember picture, overlay, x=1mm,y=1mm,%
mybox/.style={rectangle,minimum width=56mm, draw opacity=0.0, line width=0,  minimum height=8mm, align=left,text width=56mm},%
info/.style={mybox,draw=black,align=left}]
\node at (34,-34) [info] {$student.firstname$};
\node at (95,-34) [info] {$student.lastname$};
\node at (34,-47) [info] {$student.strasse$};
\node at (95,-47) [info] {$student.ort$}; 
\node at (34,-59) [info] {$student.matrikelnr$};
\node at (95,-59) [info] {$studium.studiengangnr$};
\end{tikzpicture}}, pages=1]{$assignment.file$}
$if(assignment.multipage)$ % check if we need to include the rest of the document
\includepdf[pages=$assignment.pages$]{$assignment.file$} % Include rest of document
$endif$
$else$
\includepdf[pages=$assignment.pages$]{$assignment.file$}
$endif$
$else$
%include assignment was off
$endif$
}


$if(tables)$
\usepackage{longtable,booktabs} 			% This two Packages are needet for Pandoc Table support. Issue is opened: https://github.com/jgm/pandoc/issues/1023
$endif$

\usepackage{multirow}

$if(graphics)$
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
$endif$

% Support hyperref with colorisation
% -------------------------------------------------------------------------
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage[pdfpagelabels=true]{hyperref}}
\urlstyle{same} % disable monospaced font for URLs

$if(verbatim-in-note)$
	\VerbatimFootnotes % allow verbatim text in footnotes
$endif$

$if(links-as-notes)$
	% Make links footnotes instead of hotlinks:
	\DeclareRobustCommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$

$if(strikeout)$
	\usepackage[normalem]{ulem}
	% Avoid problems with \sout in headers with hyperref
	\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
$endif$

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

% PDF Metadata
% ------------------------------------------------------------------
\hypersetup{
	unicode=false, 
	pdftoolbar=true, 
	pdfmenubar=true, 
	pdffitwindow=false, 
	pdfstartview={FitH},
	pdftitle={$if(title)$$title$$endif$$if(aufgabe.code)$: $aufgabe.code$$endif$- \studentname},
	pdfauthor={$if(author)$$author$$else$\studentname$endif$$if(student.matrikelnr)$, Matrikelnummer: $student.matrikelnr$$endif$},
	$if(studium.studiengang)$
	pdfsubject={Studiengang: $studium.studiengang$}, 
	$endif$
	pdfcreator={\LaTeX\ with package \flqq hyperref\frqq via pandoc},
	pdfproducer={pdfTeX \the\pdftexversion.\pdftexrevision},
	pdfkeywords={$if(aufgabe.typ)$$aufgabe.typ$,$endif$ $if(student.matrikelnr)$$student.matrikelnr$,$endif$ $if(aufgabe.code)$$aufgabe.code$,$endif$ $if(keywords)$ $for(keywords)$ $keywords$ $sep$, $endfor$$endif$},
	pdfnewwindow=true,
	$if(lang)$
	pdflang=$lang$,
	$endif$
	pdfdisplaydoctitle=true, 
	$if(colorlinks)$
	colorlinks=true,
	linkcolor=$if(linkcolor)$$linkcolor$$else$gray$endif$,
	filecolor=$if(filecolor)$$filecolor$$else$magenta$endif$,
	citecolor=$if(citecolor)$$citecolor$$else$gray$endif$,
	urlcolor=$if(urlcolor)$$urlcolor$$else$black$endif$,
	$else$
	hidelinks,
	$endif$
}

% Designing blockquote
% ------------------------------------------------------------------
\definecolor{blockquote-border}{RGB}{221,221,221}
\definecolor{blockquote-text}{RGB}{119,119,119}
\usepackage{mdframed}
\newmdenv[rightline=false,bottomline=false,topline=false,linewidth=3pt,linecolor=blockquote-border,skipabove=\parskip]{customblockquote}
\renewenvironment{quote}{\begin{customblockquote}\list{}{\rightmargin=0em\leftmargin=0em}%
\item\relax\color{blockquote-text}\ignorespaces}{\unskip\unskip\endlist\end{customblockquote}}

% Syntax Highlighting with colors
% -----------------------------------------------------------------
$if(highlighting-macros)$
$highlighting-macros$
$endif$
$if(verbatim-in-note)$
\usepackage{fancyvrb}
$endif$

$if(listings)$
  \usepackage{listings}
  \newcommand{\passthrough}[1]{#1}
  \lstset{basicstyle=\footnotesize, captionpos=b, breaklines=true, showstringspaces=false, tabsize=2, frame=lines, numbers=left, numberstyle=\tiny, xleftmargin=2em, framexleftmargin=2em}
	\makeatletter
	\def\l@lstlisting#1#2{\@dottedtocline{1}{0em}{1em}{\hspace{1,5em} Lst. #1}{#2}}
	\makeatother
$endif$

\renewcommand{\familydefault}{\sfdefault}

% Pandoc tightlisting
% ------------------------------------------------------------------
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}


% Support for citation
% -------------------------------------------------------------------
$if(natbib)$
\usepackage[$natbiboptions$]{natbib}
\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$}
$endif$
$if(biblatex)$
\usepackage[backend=bibtex]{biblatex}
	$for(bibliography)$
	\addbibresource{$bibliography$}
	$endfor$
$endif$

\usepackage[T1]{fontenc}

$if(csl-refs)$
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newlength{\cslentryspacingunit} % times entry-spacing
\setlength{\cslentryspacingunit}{\parskip}
\newenvironment{CSLReferences}[2] % #1 hanging-ident, #2 entry spacing
 {% don't indent paragraphs
  \setlength{\parindent}{0pt}
  % turn on hanging indent if param 1 is 1
  \ifodd #1
  \let\oldpar\par
  \def\par{\hangindent=\cslhangindent\oldpar}
  \fi
  % set entry spacing
  %\setlength{\parskip}{#2\cslentryspacingunit}
 }%
 {\par}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{#1\hfill\break}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
$endif$

%$if(csl-refs)$
%\newlength{\cslhangindent}
%\setlength{\cslhangindent}{1.5em}
%\newenvironment{CSLReferences}%
%  {$if(csl-hanging-indent)$\setlength{\parindent}{0pt}%
%  \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces$endif$}%
%  {\par}
%$endif$

$if(numbersections)$
	\setcounter{secnumdepth}{$if(secnumdepth)$$secnumdepth$$else$5$endif$}
	$else$
	\setcounter{secnumdepth}{$if(secnumdepth)$$secnumdepth$$else$5$endif$}
	%\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
$endif$

% ----------------------------------------------------------------------------
% begin document
% ----------------------------------------------------------------------------

\begin{document}


%
% Assignment
% -------------------
$if(assignment.file)$
$if(assignment.beforetitle)$
\assignment
$endif$
$endif$

% ----------------------------------------------------------------------------------------------------------
% Kopf und Fußzeile
% ----------------------------------------------------------------------------------------------------------
\renewcommand{\sectionmark}[1]{\markright{#1}}
\renewcommand{\leftmark}{\rightmark}
\pagestyle{fancy}
\lhead{}
\chead{}
\rhead{\thesection\space\contentsname}
\lfoot{\tiny $if(aufgabe.typ)$$aufgabe.typ$ des Studenten: $endif$$if(author)$$author$$else$\studentname$endif$$if(student.matrikelnr)$ (Matrikelnr.: $student.matrikelnr$)$endif$ $if(studium.studiengang)$Studiengang: $studium.studiengang$$endif$ $if(aufgabe.code)$- Prüfung: $aufgabe.code$ $endif$}
\cfoot{}
\rfoot{\ \linebreak Seite \thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}

% Vorspann
\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\theHsection}{\Roman{section}}
\pagenumbering{Roman}

% Pagebreak after each Section
\let\oldsection\section
\renewcommand\section{\clearpage\oldsection}

% ----------------------------------------------------------------------------------------------------------
% Titelseite
% ----------------------------------------------------------------------------------------------------------
\thispagestyle{empty}
\begin{center}
$if(logo)$ $if(hochschule)$ $else$   \includegraphics[max width=\textwidth]{$logo$}\\ $endif$  $endif$ $if(hochschule)$ $if(logo)$  $else$   \Huge \textbf{$hochschule$} \\ $endif$   $endif$
    \vspace*{2cm}
	\Large
	$if(studium.studiengang)$
		\textbf{Studiengang:}\\
		\textbf{$studium.studiengang$}\\
		\vspace*{1cm}
	$endif$
	\Huge
	$if(aufgabe.typ)$
		\textbf{$aufageb.typ$}\\
		\vspace*{0.5cm}
	$endif$
	$if(title)$
		\textbf{$title$} \\
	$endif$
	\vspace*{0.3cm}
	\large
  $if(aufgabe.code)$
		$aufgabe.code$ \\
	$endif$
	\vspace*{0.5cm}
	$if(studium.fach)$
		\textbf{$studium.fach$}\\
	$endif$
	\vspace*{0.5cm}
	
	\vfill
	\normalsize
	\newcolumntype{x}[1]{>{\raggedleft\arraybackslash\hspace{0pt}}p{#1}}
	\begin{tabular}{x{6cm}p{7.5cm}}
		$if(student)$
			\rule{0mm}{5ex}\textbf{Student:} & \studentname
			$if(student.strasse)$
				\newline $student.strasse$
			$endif$
			$if(student.ort)$
				\newline $student.ort$
			$endif$
			$if(student.email)$
				\newline $student.email$
			$endif$ \\
		$endif$
		$if(betreuung)$
			\rule{0mm}{5ex}\textbf{Betreuung:} & $betreuung$ \\
		$endif$
		$if(student.matrikelnr)$
			\rule{0mm}{5ex}\textbf{Matrikelnummer:} & $student.matrikelnr$ \\
		$endif$
		$if(date)$
			\rule{0mm}{5ex}\textbf{Abgabedatum:} & $date$ \\
		$else$
			\rule{0mm}{5ex}\textbf{Abgabedatum:} & \today \\
		$endif$
	\end{tabular}
\end{center}
\pagebreak

% ----------------------------------------------------------------------------------------------------------
% Assignment
% ----------------------------------------------------------------------------------------------------------

$if(assignment.file)$
$if(assignment.beforetitle)$
$else$
\assignment
$endif$
$endif$


$if(skipfirstpage)$ % Skip first page count, if skipfirstpage = 1
\clearpage
\setcounter{page}{1}
$endif$

$if(abstract)$
% ----------------------------------------------------------------------------------------------------------
% Abstract
% ----------------------------------------------------------------------------------------------------------
\begin{abstract}
	$abstract$
\end{abstract}
$endif$


$for(include-before)$
% ----------------------------------------------------------------------------------------------------------
% include-before Section
% ----------------------------------------------------------------------------------------------------------
$include-before$
$endfor$

$if(toc)$
$if(toc-title)$
\renewcommand*\contentsname{$toc-title$}
$endif$
{
$if(colorlinks)$
\hypersetup{linkcolor=$if(toccolor)$$toccolor$$else$black$endif$}		% Setup the link color of the toc
$endif$

\setcounter{tocdepth}{$toc-depth$}

% ----------------------------------------------------------------------------------------------------------
% Inhaltsverzeichnis
% ----------------------------------------------------------------------------------------------------------
% TODO Typ vor Nummer
\renewcommand{\cfttabpresnum}{Tab. }
\renewcommand{\cftfigpresnum}{Abb. }
\settowidth{\cfttabnumwidth}{Abb. 10\quad}
\settowidth{\cftfignumwidth}{Abb. 10\quad}

\singlespacing
\rhead{$if(lang)$INHALTSVERZEICHNIS$else$TABLE OF CONTENTS$endif$}
\renewcommand{\contentsname}{I $if(lang)$Inhaltsverzeichnis$else$Table of contents$endif$}
\phantomsection
\addcontentsline{toc}{section}{\texorpdfstring{I \hspace{0.35em}$if(lang)$Inhaltsverzeichnis$else$Table of contents$endif$}{$if(lang)$Inhaltsverzeichnis$else$Table of contents$endif$}}
\addtocounter{section}{1}
\tableofcontents
\pagebreak
}
$endif$

$if(lot)$
% ----------------------------------------------------------------------------------------------------------
% Tabellenverzeichnis
% ----------------------------------------------------------------------------------------------------------
\rhead{$if(lang)$TABELLENVERZEICHNIS$else$LIST OF TABLES$endif$}
\listoftables
\pagebreak
$endif$

$if(lof)$
% ----------------------------------------------------------------------------------------------------------
% Abbildungsverzeichnis
% ----------------------------------------------------------------------------------------------------------
\rhead{$if(lang)$ABBILDUNGSVERZEICHNIS$else$LIST OF FIGURES$endif$}
\listoffigures
\pagebreak
$endif$

$if(abk)$
% ----------------------------------------------------------------------------------------------------------
% Abkürzungsverzeichnis
% ----------------------------------------------------------------------------------------------------------
\rhead{$if(lang)$ABKÜRZUNGSVERZEICHNIS$else$LIST OF ABBREVIATIONS$endif$}
\section{Abkürzungsverzeichnis}
\begin{acronym}[OSGi] 						% längste Abkürzung steht in eckigen Klammern
	\setlength{\itemsep}{-\parsep} 			% geringerer Zeilenabstand
	\acro{OSGi}{Open Service Gateway initiative}
\end{acronym}
\newpage
$endif$

% ----------------------------------------------------------------------------------------------------------
% Einrichtung der Kopfzeile
% ----------------------------------------------------------------------------------------------------------
\renewcommand{\sectionmark}[1]{\markright{#1}}
\renewcommand{\subsectionmark}[1]{}
\renewcommand{\subsubsectionmark}[1]{}
\lhead{$if(lang)$Abschnitt$else$Chapter$endif$ \thesection}
\rhead{} %hier kann die rechte Seite der Kopfzeile editiert werden!

\onehalfspacing
\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\theHsection}{\arabic{section}}
\setcounter{section}{0}
\pagenumbering{arabic}
\setcounter{page}{1}
%\renewcommand{\includegraphics}[1][]{\includegraphics[width=0.9\columnwidth,keepaspectratio]{#1}}


% ----------------------------------------------------------------------------------------------------------
% Inhalt
% ----------------------------------------------------------------------------------------------------------

$body$

% ----------------------------------------------------------------------------------------------------------
% Literaturverzeichnis
% ----------------------------------------------------------------------------------------------------------

$if(natbib)$
    $if(bibliography)$
        $if(biblio-title)$
            $if(has-chapters)$
\renewcommand\bibname{$biblio-title$}
            $else$
\renewcommand\refname{$biblio-title$}
            $endif$
        $endif$
        $if(beamer)$
\begin{frame}[allowframebreaks]{$biblio-title$}
  \bibliographytrue
        $endif$
  \bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
        $if(beamer)$
\end{frame}
        $endif$
    $endif$
$endif$

$if(biblatex)$
    $if(beamer)$
\begin{frame}[allowframebreaks]{$biblio-title$}
  \bibliographytrue
  \printbibliography[heading=none]
\end{frame}
    $else$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
    $endif$
$endif$

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

$endfor$

%$if(biblatex)$
%	\pagebreak
%	\lhead{}
%	\rhead{QUELLENVERZEICHNIS} %hier kann die rechte Seite der Kopfzeile editiert werden!
%	\renewcommand{\refname}{Quellenverzeichnis}
%	\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
%	\pagebreak
%$endif$
%$if(natbib)$
%  $if(bibliography)$
%		\pagebreak
%		\lhead{}
%		\rhead{QUELLENVERZEICHNIS} %hier kann die rechte Seite der Kopfzeile editiert werden!
%		\renewcommand{\refname}{Quellenverzeichnis}
 %   \bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
 %	$endif$
%$endif$
%$if(csl-refs)$
%	\pagebreak
%\lhead{}
%\rhead{QUELLENVERZEICHNIS} %hier kann die rechte Seite der Kopfzeile editiert werden!
%\renewcommand{\refname}{Quellenverzeichnis}
%$endif$


%$if(biblatex)$
	% ----------------------------------------------------------------------------------------------------------
	% Literatur
	% ----------------------------------------------------------------------------------------------------------
%	\pagebreak
%	\lhead{}
%	\rhead{QUELLENVERZEICHNIS} %hier kann die rechte Seite der Kopfzeile editiert werden!
%	\renewcommand{\refname}{Quellenverzeichnis}	

%	\ bibliographystyle{myalpha}
%	\bibliography{bibo}
%	\pagebreak

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

$if(insurance)$
% ----------------------------------------------------------------------------------------------------------
% Erklärung zur Selbstständigkeit
% ----------------------------------------------------------------------------------------------------------
\newpage
\thispagestyle{empty}
\begin{center}
	\vspace*{5em}
	\huge\textbf{Erklärung}\\
\end{center}
\vspace{2em}
Ich, \studentname,  versichere  durch  meine  Unterschrift,  dass  ich  die  vorliegende Arbeit selbstständig erstellt habe. Andere als die angegebenen Hilfsmittel habe ich nicht ver-wendet. 

Soweit  ich  fremde  Gedankengänge  oder  Texte  verwendet  habe,  sind  diese  von  mir  als solche kenntlich gemacht und dem Urheber eindeutig zuordenbar. Dazu zählen sowohl wört-liche als auch nicht wörtliche Übernahmen.

\vspace{4em}
\begin{minipage}{\linewidth}
	\begin{tabular}{p{15em}p{15em}}
		Datum: &  .......................................................\\
		& \centering (\studentname)\\
	\end{tabular}
\end{minipage}
$endif$

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

$endfor$
\end{document}
