\NeedsTeXFormat{LaTeX2e}

\ProvidesClass{eis}

% Declare key=value options
\RequirePackage{kvoptions}[2010/12/23] % Important: Require version 3.10
% Earlier versions of this package had a bug concerning the handling of \DeclareDefaultOption{…}

% Conditional commands
\RequirePackage{ifthen}

% Namespacing
\SetupKeyvalOptions{
    family=eis,
    prefix=eis@
}
%% Set English as default language
\DeclareStringOption[]{language}[english]

% Set Master Thesis as default document type
\DeclareStringOption[]{type}[master]

% Process options
\ProcessKeyvalOptions*

% Inherit from report class
\LoadClass[12pt]{report}

% Use UTF-8 for input encoding
\RequirePackage[utf8]{inputenc}

% Use T1 font encoding
\RequirePackage[T1]{fontenc}

% Key value processing
\RequirePackage{pgfkeys}

% Graphics
%\RequirePackage[a-3b]{pdfx}  this line is helpful if we are doing an online submission, instead of using an adobe premiere version to convert pdf to pdf/A format. once can uncomment this line and use verapdf to check the downloaded pdf is pdf/3b compilant or not. There are some rules for the pdf to be pdf/a compilant such as all the images should be jpeg or jpg but not png. One cannot attach external pdf's. Just in case, if the downloaded version is not pdf/a compilant after uncommenting this line. It's better to use adobe premier instead of checking the reasons why the file is not pdf/a compilant in the latex file.
\RequirePackage{rotating}
\RequirePackage{graphicx}
\RequirePackage{adjustbox}
\RequirePackage{xurl}

% Colors
\RequirePackage{xcolor}

% Mathematics
\RequirePackage{amsmath}
\RequirePackage{amssymb}

% Algorithms
\RequirePackage{algorithm}
\RequirePackage[noend]{algpseudocode}
\RequirePackage{algorithmicx}

% Use Times New Roman as default font
\RequirePackage{txfonts}

% Floats
\RequirePackage{float}
\RequirePackage{placeins} 

% Heading formatting
\RequirePackage{fancyhdr}
\RequirePackage{titlesec}

% Managing table of contents appearances
\RequirePackage{tocvsec2}

% Change the resetting of counters
\RequirePackage{chngcntr}

% Advanced tables
\RequirePackage{array}
\RequirePackage{tabularx}
\RequirePackage{multirow}
\RequirePackage{tablefootnote}
\RequirePackage{booktabs}

% External tables
\RequirePackage{pgfplotstable}
\pgfplotsset{compat=1.12}

% Advanced captions
\RequirePackage{caption}
\RequirePackage{subcaption}

% Code listings
\RequirePackage{listings}

% Minipages with variable lists
\RequirePackage{varwidth}

% Advanced table of contents formatting
\RequirePackage[titles]{tocloft}

% Formatting of ordered (enumeration) and unordered (itemize) lists
\RequirePackage[inline]{enumitem}

% Customizing of citations in the text
\RequirePackage{natbib}

% Advanced page layout
\RequirePackage{geometry}

% Hyperlinks and PDF information
\RequirePackage{hyperref}

% Glossaries (must be loaded after hyperref)
\RequirePackage[printonlyused, smaller]{acronym}

% Length calculations
\RequirePackage{calc}

% Allow for "Textmarker" highlighting \texthl{highlighted text}
\RequirePackage{soul}

% \todo Notes
\setlength {\marginparwidth}{2cm}
\RequirePackage{todonotes}

% Abbreviations
\RequirePackage{eis-abbreviations}

% Blind texts
\RequirePackage{lipsum}

% For correct spacing after abbrevations
\RequirePackage{xspace}
\DeclareRobustCommand\xdot{.\@\xspace}
 
% Processing of advanced options
% (keys are can be defined later)
\newcommand
    {\isthesis}
    [1]
    {\setkeys{isthesis}{#1}}
 
% Macro for creating options
\newcommand
    {\eis@new@option}
    {\@ifstar{\eis@new@option@star}{\eis@new@option@nostar}}
 
% Non-starred version (name, internal name, default value)
\newcommand
    {\eis@new@option@nostar}
    [3]
    {\eis@new@option@star{#1}{#2}{#3}{\expandafter\renewcommand\csname eis@#2\endcsname{##1}}}
 
 % Starred version (name, internal name, default value, macro to execute)
 \newcommand
    {\eis@new@option@star}
    [4]
    {\expandafter\newcommand\csname eis@#2\endcsname{#3}\define@key{isthesis}{#1}{#4}}

 % ERCIS colors
 \definecolor{ercis-black}{RGB}{0,0,0}
 \definecolor{ercis-grey}{RGB}{94,94,93}
 \definecolor{ercis-red}{RGB}{133,35,57}
 \definecolor{ercisred}{RGB}{133,35,57}
 \definecolor{ercis-lightred}{RGB}{200,156,166}
 \definecolor{ercis-blue}{RGB}{135,151,163}
 
 % Additional ERCIS colors
 \definecolor{ercis-darkblue}{RGB}{67,92,139}
 \definecolor{ercis-cyan}{RGB}{0,156,179}
 \definecolor{ercis-orange}{RGB}{231,124,18}
 \definecolor{ercis-green}{RGB}{135,191,42}
 
 % WWU colors
 % See https://www.uni-muenster.de/imperia/md/content/wwu/cd/10.05.03_wwu_cd_manual_2.0_web_final.pdf
 \definecolor{wwu-black}{RGB}{62,62,59}
 \definecolor{wwu-green}{RGB}{0,142,150}
 \definecolor{wwu-lightgreen}{RGB}{122,181,22}
 \definecolor{wwu-blue}{RGB}{0,110,137}
 \definecolor{wwu-lightblue}{RGB}{0,157,209}
 
 % %
 % % Localization
 % %
\ifthenelse{\equal{\eis@language}{english}}{
	 % ENGLISH
	 
	 % English hyphenation rules
	 \RequirePackage[ngerman, english]{babel}
	 
	  % Use nice quotation marks with \enquote
	 \RequirePackage[style=american]{csquotes}
	 
	% Date formatting
	\RequirePackage[en-GB,showdow]{datetime2}
	\DTMlangsetup[en-GB]{ord=raise}
	\DTMnewdatestyle{isthesisdate}{%
		\renewcommand*{\DTMdisplaydate}[4]{\DTMenglishordinal{##3} \DTMenglishmonthname{##2}  ##1}%
		\renewcommand*{\DTMDisplaydate}{\DTMdisplaydate}%
	}
	
	\eis@new@option{label-associate}{label@associate}{Associate Supervisor}
	\eis@new@option{label-tutor}{label@tutor}{Research Assistant}
	\eis@new@option{label-studies}{label@studies}{Course of studies}
	\eis@new@option{label-author}{label@author}{Presented by}
	\eis@new@option{label-submission}{label@submission}{Submission}
	\eis@new@option{label-atthe}{label@atthe}{at the}
	\eis@new@option{label-context}{label@context}{in the context of the seminar}
	\eis@new@option{secondary-logo}{secondary@logo}{assets/Lehrstuhllogo}
	\newcommand{\listabbreviationname}{Abbreviations}
	\newcommand{\listsymbolname}{Symbols}
	\newcommand{\authorshipstatementname}{Declaration of Authorship}%
	\AtBeginDocument{%
		\renewcommand{\contentsname}{Contents}%
		\renewcommand{\listfigurename}{Figures}%
		\renewcommand{\lstlistlistingname}{Listings}%
		\renewcommand{\listtablename}{Tables}%
		\renewcommand{\abstractname}{Abstract} %
		\renewcommand{\appendixname}{Appendix} %
		\renewcommand{\bibname}{References}%
		\setlength{\cftfignumwidth}{2cm}
	}
    
}{\ifthenelse{\equal{\eis@language}{german}}{
    % GERMAN
	
    % English hyphenation rules
    \RequirePackage[english, ngerman]{babel}
	 
	% Use nice quotation marks with \enquote
	\RequirePackage[style=ngerman]{csquotes}
	 
  	% Date formatting
  	\RequirePackage[german,showdow]{datetime2}

  	\DTMnewdatestyle{isthesisdate}{%
  		\renewcommand*{\DTMdisplaydate}[4]{\DTMgermanordinal{##3}. \DTMgermanmonthname{##2}  ##1}%
  		\renewcommand*{\DTMDisplaydate}{\DTMdisplaydate}%
  	}
	
    % Allows the use of "," as a decimal point
	\RequirePackage{icomma}
	 
	\eis@new@option{label-associate}{label@associate}{Betreuer}
	\eis@new@option{label-tutor}{label@tutor}{wiss. Mitarbeiter}
	\eis@new@option{label-studies}{label@studies}{Studiengang}
	\eis@new@option{label-author}{label@author}{vorgelegt von}
	\eis@new@option{label-submission}{label@submission}{Abgabetermin}
	\eis@new@option{label-atthe}{label@atthe}{am}
	\eis@new@option{label-context}{label@context}{im Rahmen des Seminars}
	\eis@new@option{secondary-logo}{secondary@logo}{assets/Lehrstuhllogo}
	\newcommand{\listsymbolname}{Symbolverzeichnis}
	\newcommand{\listabbreviationname}{Abk\"urzungsverzeichnis}
	\newcommand{\authorshipstatementname}{Abschlie{\ss}ende Erkl\"arung}
	\AtBeginDocument{%
		\renewcommand{\contentsname}{Inhaltsverzeichnis}%
		\renewcommand{\listfigurename}{Abbildungsverzeichnis}%
		\renewcommand{\lstlistlistingname}{Codeverzeichnis}%
		\renewcommand{\listtablename}{Tabellenverzeichnis}%
		\renewcommand{\abstractname}{Abstract} %
		\renewcommand{\appendixname}{Anhang} %
		\renewcommand{\bibname}{Literaturverzeichnis}%
		\renewcommand{\figurename}{Abbildung}
		\renewcommand{\cftfigpresnum}{Abbildung\ }
		\setlength{\cftfignumwidth}{2.3cm}
		\renewcommand{\tablename}{Tabelle}
		\renewcommand{\cfttabpresnum}{Tabelle\ }
		\renewcommand{\ALG@name}{Algorithmus} %algorithms package
	}
 
}{
  \ClassError{isthesis}{Unknown language ``\eis@language'' specified}{}
}}

% Set specific settings w.r.t. thesis type
\ifthenelse{\equal{\eis@type}{master}}{
    % Specific settings for Master Theses
}{\ifthenelse{\equal{\eis@type}{bachelor}}{
    % \glossaryentrynumbers{} % Specific settings for Bachelor Theses
}{\ifthenelse{\equal{\eis@type}{seminar}}{ %
    % Specific settings for Seminar Theses
}{ %
    \ClassError{isthesis}{Unknown type ``\eis@type'' specified}{}
}}}
 
% Macro for creating a thesis type
% (name, language, title page caption)
\newcommand{\eis@new@type}[3]{%
	\providecommand{\eis@title@type}{}%
	\ifthenelse{\equal{\eis@type}{#1}}{
		\ifthenelse{\equal{\eis@language}{#2}}{
			\renewcommand{\eis@title@type}{#3}%
		}{\relax}
	}{\relax}
}

% Create thesis types
\eis@new@type{seminar}{german}{Seminararbeit}
\eis@new@type{seminar}{english}{Seminar Thesis}

\eis@new@type{bachelor}{german}{Bachelorarbeit}
\eis@new@type{bachelor}{english}{Bachelor Thesis}

\eis@new@type{master}{english}{Master Thesis}
\eis@new@type{master}{german}{Masterarbeit}

% Helper to remove line breaks from a command
\newcommand
    {\removelinebreaks}
    [1]
    {\begingroup\def\\{ }#1\endgroup}

% Regular font style for hyperlinks
\urlstyle{same}

% Set default page layout
\geometry{
    paper=a4paper,
    left=3cm,
    top=2.95cm,
    bottom=2.2cm,
    right=3cm
}

% Disable indention of paragraphs
\setlength{\parindent}{0pt}

% Paragraph spacing
\newlength{\parskip@default}
\setlength{\parskip@default}{\parskip}
\AtBeginDocument{\setlength{\parskip}{12pt}}

% Line spacing
\newlength{\baselineskip@default}
\setlength{\baselineskip@default}{\baselineskip}
\AtBeginDocument{\setlength{\baselineskip}{18pt}}

% Page style (override default plain style)
\fancypagestyle{plain}{
	\fancyhf{}
	% For seminar theses, put name and matriculation number in headline
	\ifthenelse{\equal{\eis@type}{seminar}}{
		\fancyhead[L]{\footnotesize \textcolor{ercis-grey}
			\@author  \ifthenelse{\equal{\eis@author@matriculation}{}}{\relax}{ %
		 \textcolor{ercis-grey}{(\eis@author@matriculation)}}
		}
	}{\relax}
	\fancyhead[L]{\relax}
	\fancyhead[R]{\thepage}
	\fancyfoot{\relax}
	\setlength{\headheight}{15pt} % fixes \headheight warning
	\renewcommand{\headrulewidth}{0pt} %no headrule
}

% Footnote formatting
\RequirePackage[flushmargin,hang,bottom]{footmisc}
\setlength{\footnotemargin}{0.75cm}
\renewcommand\footnoterule{\kern-3pt \hrule width 2in \kern 2.6pt} % Length of separator between text and footnotes
\interfootnotelinepenalty=10000 % Prevent footnotes to be split over multiple pages

% Sectioning formatting
\titleformat{\chapter}{\normalfont\large\bfseries}{\makebox[1.5cm][l]{\thechapter}}{0pt}{}
\titlespacing*{\chapter}{0pt}{-16pt plus 2pt minus 2pt}{8pt plus 2pt minus 2pt}

\titleformat{\section}{\normalfont\bfseries}{\makebox[1.5cm][l]{\thesection}}{0pt}{}
\titlespacing*{\section}{0pt}{12pt plus 2pt minus 2pt}{6pt plus 2pt minus 2pt}

\titleformat{\subsection}{\normalfont\bfseries}{\makebox[1.5cm][l]{\thesubsection}}{0pt}{}
\titlespacing{\subsection}{0pt}{12pt plus 2pt minus 2pt}{6pt plus 2pt minus 2pt}

% Numberless sectioning formatting (sub headings)
\titleformat{name=\section,numberless}{\normalfont\itshape}{}{0pt}{}
\titlespacing{name=\section,numberless}{0pt}{4pt plus 2pt minus 2pt}{4pt plus 2pt minus 2pt}

\titleformat{name=\subsection,numberless}{\normalfont\itshape}{}{0pt}{}
\titlespacing{name=\subsection,numberless}{0pt}{4pt plus 2pt minus 2pt}{4pt plus 2pt minus 2pt}

\titleformat{name=\subsubsection,numberless}{\normalfont\itshape}{}{0pt}{}
\titlespacing{name=\subsubsection,numberless}{0pt}{4pt plus 2pt minus 2pt}{4pt plus 2pt minus 2pt}

% Keep floats within the sections they are defined in
\newcommand{\eis@section@barrier}[1]{%
    \expandafter\let\csname #1@default\expandafter\endcsname\csname #1\endcsname%
    % \expandafter\renewcommand\csname #1\endcsname{\FloatBarrier\expandafter\FloatBarrier\csname #1@default\endcsname}%
    \expandafter\renewcommand\csname #1\endcsname{\FloatBarrier\csname #1@default\endcsname}%
    % using l@addto@macro
    % or \noexpand primitive?
}

\eis@section@barrier{chapter}
\eis@section@barrier{section}
\eis@section@barrier{subsection}

% Caption formatting
\captionsetup{figurewithin=none,tablewithin=none} % Continuous numbering
\captionsetup{labelsep=quad} % No separator between label and caption
\AtBeginDocument{
	    \counterwithout{lstlisting}{chapter} % Continous numbering for listings
}

% Figure formatting
\let\figure@default\figure
\let\endfigure@default\endfigure

\pgfkeys{
    /isthesis/figure/.cd,
    caption/.initial={},
    toc/.initial={},
}

\define@key{figure}{caption}{\newcommand{\figure@caption}{#1}}
\define@key{figure}{toc}{\newcommand{\figure@toc}{#1}}
\define@key{figure}{label}{\newcommand{\figure@label}{#1}}
\define@key{figure}{placement}{\newcommand{\figure@placement}{#1}}
\define@key{figure}{width}{\newcommand{\figure@width}{#1}}
\define@key{figure}{fit}[]{\newcommand{\figure@fit}{}}
\define@key{figure}{cache}{\newcommand{\figure@cache}{#1}}
\define@key{figure}{cachename}{\newcommand{\figure@cachename}{#1}}

\newcommand{\figure@private@resize@width}{}
\newcommand{\figure@private@resize@proxy}[1]{\resizebox{\figure@private@resize@width}{!}{#1}}

\renewenvironment{figure}[1][]{%
    \setkeys{figure}{#1}%
    \ifthenelse{\isundefined{\figure@placement}}{%
        \newcommand{\figure@internal@placement}{ht}%
    }{%
        \ifthenelse{\equal{\figure@placement}{exact}}{% 
            \newcommand{\figure@internal@placement}{!ht}%{H}%
        }{%
            \ifthenelse{\equal{\figure@placement}{top}}{% 
                \newcommand{\figure@internal@placement}{t}%
            }{%
                \ifthenelse{\equal{\figure@placement}{bottom}}{% 
                    \newcommand{\figure@internal@placement}{b}%
                }{}%
            }%
        }%
    }%
    \expandafter\figure@default\expandafter[\figure@internal@placement]%
    \ifthenelse{\isundefined{\figure@cache}}{}{%
        % Control caching
        \tikzset{external/export next=\figure@cache}%
    }%
    \ifthenelse{\isundefined{\figure@cachename}}{}{%
        % Set cache name
        \tikzsetnextfilename{\figure@cachename}%
    }%
    \center%
    \ifthenelse{\isundefined{\figure@width}}{}{%
        \renewcommand{\figure@private@resize@width}{\figure@width}%
        \collect@body\figure@private@resize@proxy%
    }%
}{%
    \ifthenelse{\isundefined{\figure@toc}}{%
        % Without dedicated TOC caption
        \caption{\figure@caption\label{\figure@label}}%
    }{%
        % With dedicated TOC caption
        \caption[\figure@toc]{\figure@caption\label{\figure@label}}%
    }%
    \endcenter%
    \endfigure@default%
}
\renewcommand{\captionlabelfont}{\bfseries}

% Table formatting
\let\table@default\table
\let\endtable@default\endtable

\define@key{table}{caption}{\newcommand{\table@caption}{#1}}
\define@key{table}{toc}{\newcommand{\table@toc}{#1}}
\define@key{table}{label}{\newcommand{\table@label}{#1}}
\define@key{table}{columns}{\newcommand{\table@columns}{#1}}
\define@key{table}{placement}{\newcommand{\table@placement}{#1}}

\renewenvironment{table}[1][]{%
    \begingroup%
    \newcommand{\table@internal@placement}{ht}%
    \setkeys{table}{#1}%
    \expandafter\table@default\expandafter[\table@internal@placement]%
    % \table@default[ht]
    % \footnotesize%
    \center%
    \renewcommand{\arraystretch}{1.15}%
    % \tabular{\table@columns}
}{%
    % \endtabular%
    \ifthenelse{\isundefined{\table@toc}}{%
        % Without dedicated TOC caption
        \caption{\table@caption\label{\table@label}}%
    }{%
        % With dedicated TOC caption
        \caption[\table@toc]{\table@caption\label{\table@label}}%
    }%
    \endcenter%
    \endtable@default%
    \endgroup%
}

% Itemization formatting
\setlist[itemize]{
%    label={$-$}, %activate for dashes instead of bullets
	labelindent=24pt,
	labelsep=18pt,
	leftmargin=*,
	topsep=0pt,
}

% Enumeration formatting
\setlist[enumerate, 1]{
    label={(\arabic*)},
    align=left,
	labelindent=24pt,
	labelsep=18pt,
	leftmargin=*,
	topsep=0pt,
}

% Display verbatim environments
\let\verbatim@default\verbatim
\let\endverbatim@default\endverbatim

\pgfkeysdef{/isthesis/verbatim/font}{#1}

\newcommand{\eis@verbatim@inner}[1][]{%
    {\nfss@catcodes\scantokens{\gdef\eis@verbatim@parameters{#1}}}%
    \eis@verbatim@parameters%
    % \pgfkeys{/isthesis/verbatim/.cd,\eis@verbatim@parameters}%
}

\renewenvironment{verbatim}{%
    \bgroup%
    \small%
    \setlength{\topsep}{0pt}%
    \setlength{\partopsep}{0pt}%
    \verbatim@default%
    \eis@verbatim@inner%
}{%
    \endverbatim@default%
    \egroup%
}

% Hurenkinder und Schusterjungen verhindern
\clubpenalty=10000
\widowpenalty=10000
\displaywidowpenalty=10000

% Continue footnote numbering across chapters
\counterwithout{footnote}{chapter}

% \ Listings Set up
\lstset{ %
	basicstyle=\ttfamily\footnotesize,
	numbers=left,                   % where to put the line-numbers
	numberstyle=\footnotesize,      % the size of the fonts that are used for the line-numbers
	stepnumber=0,                   % Each X line will be numbered
	numbersep=5pt,                  % how far the line-numbers are from the code
	backgroundcolor=\color{white},  % choose the background color. 
	commentstyle=\color{ercis-blue},
	keywordstyle=\color{ercis-red},
	showspaces=false,               % show spaces adding particular underscores
	showstringspaces=false,         % underline spaces within strings
	showtabs=false,                 % show tabs within strings adding particular underscores
	%frame=single,           % adds a frame around the code
	tabsize=2,          % sets default tabsize to 2 spaces
	captionpos=b,           % sets the caption-position to bottom
	breaklines=true,        % sets automatic line breaking
	breakatwhitespace=false,    % sets if automatic breaks should only happen at whitespace
	escapeinside={\%*}{*)},       % if you want to add a comment within your code
	moredelim=**[is][\color{ercis-orange}]{@}{@},
}

% Title page
\let\maketitle@default\maketitle
\renewcommand{\maketitle}{%
    \begin{titlepage}%
		\pagenumbering{gobble}
    	\DTMsetdatestyle{isthesisdate}
        \newgeometry{
            top=1cm,
            outer=2.5cm,
            bottom=2.5cm,
            inner=2.5cm
        }
        \includegraphics[height=\eis@primary@logo@height]{\eis@primary@logo}%
        \hfill%
        \ifthenelse{\equal{\eis@secondary@logo}{}}{}{\includegraphics[height=\eis@secondary@logo@height]{\eis@secondary@logo}}%
        \vfill%
        \begin{center}%
            {\large \@author \par}%
            \vskip 1.5em%
            {\Large \@title \par}%
            \vskip 3em%
            {\bfseries \eis@title@type \par}%
            \ifthenelse{\equal{\eis@type}{seminar}}{ \eis@label@context \- \enquote{\eis@seminar} \par}{}%
            \ifthenelse{\equal{\eis@group@name}{}}{}{%
                \vskip 1.5em%
                {%
                    \eis@label@atthe \- \eis@group@name%
                    \ifthenelse{\equal{\eis@group@institute}{}}{}{\\ (\eis@group@institute)}%
                    \par%
                }%
            }
            \ifthenelse{\equal{\eis@associate@group@name}{}}{}{%
                \vskip 1.5em%
                {%
                    in collaboration with the \eis@associate@group@name%
                    \ifthenelse{\equal{\eis@associate@group@institute}{}}{}{\\ (\eis@associate@group@institute)}%
                    \par%
                }%
            }
        \end{center}\par%
        \vfill%
        \begin{center}%
            \parbox{0cm}{%
                \begin{tabbing}%
				\= \hspace*{4cm} \= \kill
				\> \eis@label@associate: \> \eis@supervisor@associate \\%
				\ifthenelse{\equal{\eis@supervisor@tutor}{}}{\relax}{ %
				\> \eis@label@tutor: \> \eis@supervisor@tutor \\} %
				\> \> \\
				\> \eis@label@author: \> \@author  \ifthenelse{\equal{\eis@author@matriculation}{}}{\relax}{ %
					[\eis@author@matriculation]} \\ %
				\ifthenelse{\equal{\eis@author@address}{}}{\relax}{ %
					\> \> \eis@author@address \\} %
				\ifthenelse{\equal{\eis@author@city }{}}{\relax}{ %
					\> \> \eis@author@zip \, \eis@author@city  \\}%
				\ifthenelse{\equal{\eis@author@phone}{}}{\relax}{ %
					\> \> \eis@author@phone \\} %
				\ifthenelse{\equal{\eis@author@email}{}}{\relax}{ %
					\> \> \eis@author@email \\} %
				\> \> \\
					\> \eis@label@submission: \> {\eis@submission@date \DTMusedate{submissiondate}} \\
				\> \> \\
				\> \eis@label@studies: \> \eis@course@studies 
                \end{tabbing}%
            }%
        \end{center}\par%
        \restoregeometry%
		\pagenumbering{Roman}
    \end{titlepage}%
}

% Customizable logos on title page
\eis@new@option{primary-logo}{primary@logo}{assets/UPB_Logo_DE_vierfarbig_CMYK}
\eis@new@option{primary-logo-height}{primary@logo@height}{16mm}
% Secondary logo is language dependent and defined above
\eis@new@option{secondary-logo-height}{secondary@logo@height}{16mm}

% Override latex default meta information macros
\let\default@title\title
\renewcommand{\title}[1]{%
    \default@title{#1}%
    \hypersetup{pdftitle={#1}}%
}

\let\default@author\author
\renewcommand{\author}[1]{%
    \default@author{#1}%
    \hypersetup{pdfauthor={#1}}%
}

% Additional meta information variables
\eis@new@option*{title}{title}{Thesis Title}{\AtBeginDocument{\title{#1}}}
\eis@new@option*{author}{author@name}{Firstname Middlename Lastname}{\AtBeginDocument{\author{#1}}}
\eis@new@option{author-email}{author@email}{imt@uni-paderborn.de}
\eis@new@option{author-address}{author@address}{Warburger Str. 100}
\eis@new@option{author-phone}{author@phone}{+49 5251 600}
\eis@new@option{author-matriculation}{author@matriculation}{1234567}
\eis@new@option{author-zip}{author@zip}{33098}
\eis@new@option{author-city}{author@city}{Paderborn}
\eis@new@option{group}{group@name}{Department of Information Systems}
\eis@new@option{group-institute}{group@institute}{}
\eis@new@option{associate-group}{associate@group@name}{}
\eis@new@option{associate-group-institute}{associate@group@institute}{}

\eis@new@option{associate-supervisor}{supervisor@associate}{}
\eis@new@option{tutor-supervisor}{supervisor@tutor}{} %Betreuer
\eis@new@option{course-studies}{course@studies}{}
\eis@new@option{seminar}{seminar}{}
\eis@new@option*{submission-date}{submission@date}{}{\DTMsavedate{submissiondate}{#1}}
% Roman page numbering from the beginning
\AtBeginDocument{\pagenumbering{Roman}}

% Start with II after title page
\let\maketitle@default\maketitle
\renewcommand
    {\maketitle}
    {\maketitle@default\setcounter{page}{2}}

% Abstract style
\renewenvironment
    {abstract}
    {
    	\clearpage
    	\pagenumbering{gobble}
    	\pagestyle{empty}
    	\small
    	\begin{center}
    		\bfseries\normalsize \abstractname\vspace{-1em}\vspace{-1em}
    	\end{center}
    	\rule{\textwidth}{1pt}
    	\vspace{-1.5em}
    	\list{}{%
    		\setlength{\leftmargin}{8mm}
    		\setlength{\rightmargin}{\leftmargin}%
    	}%
    	\item\relax
    }
    {\endlist \vspace{-1em}	\rule{\textwidth}{1pt}}


% Content wrapper
\newenvironment{content}{%
	% specific spacing in content
	\titlespacing*{\chapter}{0pt}{-30pt plus 2pt minus 2pt}{8pt plus 2pt minus 2pt}
    %% Pre content
    \pagestyle{plain}%
    \clearpage
    % Enable arabic page numbering
    \pagenumbering{arabic}%
    % Reset page numbering
    \setcounter{page}{1}%
}{%
    %% Post content
}

% Quote page
\pgfkeys{
    /isthesis/quotepage/.cd,
    author/.initial={},
    citation/.initial={}
}

\newcommand{\quotepage}[2][]{
    \clearpage%
    \begingroup%
    \pgfkeys{/isthesis/quotepage/.cd,#1}%
    \thispagestyle{empty}%
    \null\vfill%
    \centering%
    \begin{varwidth}{\textwidth}
        {\raggedright\large\itshape%
        #2\par\bigskip%
        }%
        {\pgfkeys{/isthesis/quotepage/author/.get=\author}%
        \raggedleft\large\scshape\author\par%
        }
    \end{varwidth}%
    \pgfkeys{/isthesis/quotepage/citation/.get=\citationkey}%
    \nocite{\citationkey}%
    \vfill\vfill%
    \endgroup%
    \clearpage%
}

% Table of contents
\let\default@tableofcontents\tableofcontents
\renewcommand{\tableofcontents}{%
    % \addcontentsline{toc}{chapter}{\contentsname}%
    {%
        \clearpage%
        \phantomsection%
        \pdfbookmark[0]{\contentsname}{contents}%
        \setlength{\parskip}{0pt}%
        % Set depth of table of contents to subsection
        \setcounter{tocdepth}{2}%
        \default@tableofcontents%
    }%
    \pagebreak%
}

\renewcommand{\cftdotsep}{2}
\setlength{\cftparskip}{0pt}

\renewcommand{\cftchapfont}{}
\renewcommand{\cftchappagefont}{}
\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}}
\setlength{\cftbeforechapskip}{0pt}

% List of figures
\let\default@listoffigures\listoffigures
\renewcommand{\listoffigures}{%
    \phantomsection%
    \addcontentsline{toc}{chapter}{\listfigurename}%
    {%
        \setlength{\parskip}{0pt}%
        \default@listoffigures%
    }%
    \pagebreak%
}

\renewcommand{\cftfigindent}{0pt}

% List of tables
\let\default@listoftables\listoftables
\renewcommand{\listoftables}{%
    \phantomsection%
    \addcontentsline{toc}{chapter}{\listtablename}%
    {%
        \setlength{\parskip}{0pt}%
        \default@listoftables%
    }%
    \pagebreak%
}

\renewcommand{\cfttabindent}{0pt}
\setlength{\cfttabnumwidth}{2cm}

% List of listings
\let\default@lstlistoflistings\lstlistoflistings
\renewcommand
    {\lstlistoflistings}
    {%
        \phantomsection%
        \addcontentsline
            {toc}
            {chapter}
            {\lstlistlistingname{}}%
            {%
                \setlength{\parskip}{0pt}%
                \default@lstlistoflistings%
            }%
        \pagebreak%
    }
\renewcommand\l@lstlisting[2]{\@dottedtocline{1}{0pt}{2em}{\lstlistingname~#1}{#2}}

% List of abbreviations
\newcommand
    {\listofabbreviations}
    {%
        \phantomsection%
        \addcontentsline{toc}{chapter}{\listabbreviationname{}}
        \setlength{\parskip}{0pt}%
        \chapter*{\listabbreviationname{}}
        \input{config/acronyms}
        \pagebreak%
    }
    
% List of symbols
\newcommand
    {\listofsymbols}
    {%
        \phantomsection%
        \addcontentsline{toc}{chapter}{\listsymbolname{}}
        \setlength{\parskip}{0pt}%
        \chapter*{\listsymbolname{}}
        \input{config/symbols}
        \pagebreak%
    }

% Appendix
\let\appendix@default\appendix
\let\appendix\undefined
\newenvironment{appendix}{%
    \appendix@default%
    \chapter*{\appendixname}%
    \addcontentsline{toc}{chapter}{\appendixname}%
    \renewcommand{\thesection}{\Alph{section}}%
    \settocdepth{chapter}%
}{%
    \resettocdepth%
}

% Format of equation numbering
\renewcommand{\theequation}{\thechapter.\arabic{equation}}

% MISQ citation style
% see http://www.misq.org/manuscript-guidelines
\setcitestyle{%
    round,      % Parantheses around default citation
    authoryear, % Author-year citations
    sort,       % Sorting of authors in a single citation
}

% The following specification needs a separate setcitestyle
% No separator between author and year
\setcitestyle{aysep={}}

% References
\AtBeginDocument{%
	\ifthenelse{\equal{\eis@language}{german}}{
		\bibliographystyle{assets/misq-de}%
	}{
		\bibliographystyle{assets/misq}%
	}
}

\newcommand{\references}[1]{%
    \addcontentsline{toc}{chapter}{\bibname}%
    \bibliography{#1}%
    \pagebreak%
}

% Declaration of authorship
\define@key{authorshipstatement}{pagenumbering}[true]{\renewcommand{\authorshipstatement@pagenumbering}{#1}}

\newcommand{\authorshipstatement}[1][]{%
    \begingroup%
    \newcommand{\authorshipstatement@pagenumbering}{true}%

    \setkeys{authorshipstatement}{#1}%
    \clearpage%
    \phantomsection%
    \pdfbookmark[0]{\authorshipstatementname}{authorshipstatement}%
    \ifthenelse{\equal{\authorshipstatement@pagenumbering}{false}}{%
        % Disable page numbering
        \pagenumbering{gobble}%
    }{}%
    \ifthenelse{\equal{\authorshipstatement@pagenumbering}{only}}{%
        % Render a page without content except for the page numbering
        \mbox{}%
    }{%
        \chapter*{\authorshipstatementname}%
        \DTMsetdatestyle{isthesisdate}
        \ifthenelse{\equal{\eis@language}{german}}{
            \textit{Kursiv gedruckte Abschnitte sollen mit dem Betreuer der Arbeit abgestimmt werden.}
            
            Mit der Abgabe der vorliegenden Arbeit versichere ich, \@author, dass ich meine \eis@title@type \ \enquote{\removelinebreaks{\@title}} selbständig und ohne unerlaubte Hilfsmittel oder unerlaubte Hilfe Dritter angefertigt habe. 
           \textit{(Zusatz bei Gruppenarbeiten: Die von mir verfassten Teile dieser Gruppenarbeit habe ich eindeutig gekennzeichnet. Alle Verfasser*innen bestätigen die Kennzeichnung meines Eigenanteils durch ihre Unterschrift.)}
            
            Alle Stellen, die inhaltlich oder wörtlich aus Veröffentlichungen stammen, sind kenntlich gemacht. Ich erkläre ferner, dass ich sämtliche Stellen der Arbeit, die originär durch texterstellende Software erstellt wurden oder substantiell in ihrer Aussage durch solche Software beeinflusst wurden, als solche gekennzeichnet habe (beispielsweise als direkte Zitate). Diese Versicherung inkludiert auch alle in der Arbeit enthaltenen Tabellen, Skizzen, Zeichnungen, bildliche Darstellungen und andere Elemente.
            
            Diese Arbeit liegt oder lag in gleicher oder ähnlicher Weise noch keiner Prüfungsbehörde vor und wurde bisher noch nicht veröffentlicht. Mir ist bewusst, dass die Arbeit elektronisch gespeichert wird und unter Zuhilfenahme von Software auf Verstöße gegen diese Erklärung geprüft werden kann. Ich bin mir auch darüber bewusst, dass bei Abgabe einer falschen Erklärung die Prüfung als nicht bestanden bewertet wird. 
            \newline \newline
            \textit{Optionale Erklärungen, die nach eigenem Ermessen zusätzlich gegeben oder gestrichen werden können:}
            
            \textit{•	Ich erkläre mich damit einverstanden, dass Teile dieser Arbeit unter Beachtung meiner Urheberschaft für die Anfertigung wissenschaftlicher Ausarbeitungen verwendet werden dürfen. In diesem Fall bitte ich um eine vorherige Information per Email. (Anmerkung: Hierzu mus}s eine auch über das Ende des Studiums hinaus gültige Email-Adresse am Lehrstuhl hinterlegt werden).
            
            \textit{•	Die Arbeit darf auch ohne meine explizite Freigabe einzelnen, interessierten Dritten verfügbar gemacht werden. (Anmerkung: Hier geht es z.B. darum, die Arbeit anderen Studierenden verfügbar zu machen, die evtl. eine ähnliche Themenstellung bearbeiten; jedoch wird die Arbeit nicht öffentlich zum Download bereitgestellt werden).}
            
            \textit{•	Oder aber: Die Arbeit soll Dritten nicht ohne meine ausdrückliche Genehmigung zugänglich gemacht werden. (Anmerkung: In diesem Fall soll bitte eine auch über das Ende des Studiums hinaus gültige Email-Adresse hinterlegt werden, da die Erlaubnis sonst gar nicht eingeholt werden kann).}
            \newline
			
			\eis@author@city, den \DTMusedate{submissiondate} \\[2\baselineskip]%
			\@author%
        }{
            \textit{Italicized sections are to be coordinated with the thesis supervisor.}
            
            By submitting this thesis, I, \@author, hereby affirm that I have prepared my \eis@title@type \ \enquote{\removelinebreaks{\@title}} independently and without the use of unauthorized aids or assistance from third parties.
           \textit{(Additional clause for group work: The parts of this group work that I have written myself are clearly marked. All co-authors confirm the designation of my individual contribution with their signature.)}
            
            All passages taken from publications, either verbatim or in substance, have been clearly indicated. I further declare that I have marked all parts of the thesis that were originally generated by text-generating software, or that were substantially influenced in their content by such software, accordingly (for example, as direct quotations). This declaration also includes all tables, sketches, drawings, visual representations, and other elements contained in the thesis.
            
            This thesis has not previously been submitted to any examination authority, in whole or in part, nor has it been published. I am aware that the thesis will be stored electronically and may be checked for violations of this declaration using software. I am also aware that submitting a false declaration will result in the thesis being deemed as failed.
            \newline \newline
            \textit{Optional declarations, which may be included or omitted at your own discretion:}
            
            \textit{•	I consent to parts of this thesis being used, with proper attribution of authorship, for the preparation of academic work. In such cases, I request to be informed in advance via email. (Note: An email address that remains valid beyond the completion of studies must be provided to the department for this purpose.)}
            
            \textit{•	The thesis may be made available to individual, interested third parties even without my explicit approval. (Note: This refers, for example, to making the thesis accessible to other students working on similar topics; however, it will not be made publicly available for download.)}
            
            \textit{•	Alternatively: The thesis should not be made accessible to third parties without my express permission. (Note: In this case, an email address that remains valid beyond the end of studies must be provided, otherwise permission cannot be obtained.)}

			
			\eis@author@city,  \DTMusedate{submissiondate} \\[2\baselineskip]%
			\@author%
        }
    }%
    \ifthenelse{\equal{\authorshipstatement@pagenumbering}{false}}{%
        % Restore default page numbering
        \clearpage%
        \pagenumbering{arabic}%
    }{}%
    \endgroup
}
\pagestyle{plain}