\NeedsTeXFormat{LaTeX2e} % specify required latex format
\ProvidesPackage{masterthesis}[2019/01/04 Masterthesis Package]

% define licence option to include a licence statement
\newif\if@uselicence\@uselicencefalse
\DeclareOption{licence}{%
    \@uselicencetrue
}

% define acknowledge option to include an acknowledgement
\newif\if@acknowledge\@acknowledgefalse
\DeclareOption{acknowledge}{%
    \@acknowledgetrue
}

% define abstract option to include an abstract
\newif\if@abstract\@abstractfalse
\DeclareOption{abstract}{%
    \@abstracttrue
}

\newif\if@library\@libraryfalse
\DeclareOption{library}{%
    \@librarytrue
}

\newif\if@writeprof\@writeproffalse
\DeclareOption{writeprof}{%
    \@writeproftrue
}

\newif\if@expose\@exposefalse
\DeclareOption{expose}{%
    \@exposetrue
}

\ProcessOptions\relax

% load packages
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} % euro quality fonts [T1] (togeth. w/ textcomp)
\usepackage{textcomp, amssymb}  % additional symbols (there are more packages)
\usepackage[all]{xy} % creating figures within latex
\usepackage[tight]{subfigure} % figures within figures
\usepackage{geometry}
\usepackage{soul}
\usepackage{ifpdf}
\usepackage{multirow}

% load biblatex
\usepackage[
    backend=biber,
    bibstyle=ieee,
    citestyle=ieee,
    backref=true,
    minnames=1,
    maxnames=2,
]{biblatex}

% check if pdflatex is used
\ifpdf
    \usepackage[pdftex]{graphicx}
    \usepackage[pdftex]{color}
    \usepackage[pdftex]{thumbpdf}
    \usepackage[pdftex,
		hidelinks = true,
		colorlinks = false,%
              %pagebackref=true, % bibliography -> text
              linktocpage=true, % toc etc: make page number active (not name)
              plainpages=false, % distinguish roman and arabic pagenumbers
              bookmarksopen=true,%
              bookmarksnumbered=true,%
              pdfauthor={\@author},%
              pdftitle={\@title},%
              pdfsubject={\@subject},%
              pdfkeywords={\keywords},%
             ]{hyperref}       % clickabe references
\else
    \usepackage[hypertex,
          plainpages=false, % distinguish roman and arabic pagenumbers
          linktocpage=true, % toc etc: make page number active (not name)
         ]{hyperref}        % clickabe references in .dvi
                            % purposely included before color package
    \usepackage[dvips]{color}     % color package, required by xy
    \usepackage[dvips]{graphicx}  % graphics package
\fi

\usepackage{xcolor}

%%% load further packages
\usepackage{listings}

% simplify quoting
\usepackage{csquotes}

% support both german and british english
\usepackage[ngerman,english,british]{babel}
\usepackage{iflang}

\KOMAoption{toc}{bibliography, index, listof}

\usepackage{makeidx}
\makeindex

\usepackage[xindy]{glossaries} % for \printglossary
\makeglossaries

%%% conditional includes
\newif\if@privatedefs\@privatedefsfalse
\IfFileExists{./private/definitions.tex}{%
    \@privatedefstrue
    \input{./private/definitions.tex}
}{}

\usepackage[titletoc]{appendix}

\MakeOuterQuote{"}

%%% define commands
\newcommand{\start}{%
    \newgeometry{centering,left=2cm,right=2cm,top=2cm,bottom=2cm}
    \begin{titlepage}
        \IfFileExists{./private/images/uhh-logo.pdf}{%
            \includegraphics[scale=0.3]{uhh-logo}}{}
        \vspace*{2cm}
        \Large
        \begin{center}
            \if@privatedefs
                \if@expose
                    \textcolor{uhhRed}{\textbf{\so{EXPOSE}}}
                \else
                    \textcolor{uhhRed}{\textbf{\so{MASTERTHESIS}}}
                \fi
            \else
                \if@expose
                    \textcolor{red}{\textbf{\so{EXPOSE}}}
                \else
                    \textcolor{red}{\textbf{\so{MASTERTHESIS}}}
                \fi
            \fi
            \vspace*{2cm}\\
            {\LARGE \textbf{\@title}}
            \vspace*{2cm}\\
            \IfLanguageName{british}{submitted by}{vorgelegt von}
            \vspace*{0.4cm}\\
            \@author
        \end{center}
        \vspace*{3.9cm}

        \noindent
        \faculty \vspace*{0.4cm} \\
        \department \vspace*{0.4cm} \\
        \if@writeprof
            \professor \vspace*{0.4cm} \\
        \else\fi
        \IfLanguageName{british}{Course of studies}{Studiengang}: \studiengang \vspace*{0.4cm} \\
        \IfLanguageName{british}{Matriculation Number}{Matrikelnummer}: \matrikelnummer \vspace*{0.8cm} \\
        \if@expose\else
        \IfLanguageName{british}{Supervisor}{Erstgutachter}: \firstReviewer \vspace*{0.4cm} \\
        \IfLanguageName{british}{Co-Supervisor}{Zweitgutachter}: \secondReviewer
        \fi
    \end{titlepage}
    \restoregeometry

    \if@uselicence
        \input{licence.tex}
    \else\fi

    \if@acknowledge
        \input{acknowledge.tex}
    \else\fi

    \if@abstract
        \input{abstract.tex}
    \else\fi

    \tableofcontents
}

\newcommand{\references}{%
    \printbibliography[heading=bibintoc]
}

\newcommand{\finish}{%
    %\clearpage
    \printglossary

    %\clearpage
    \printindex

    \if@expose
    \else
        \clearpage
        \selectlanguage{ngerman}
        \chapter{Eidesstattliche Versicherung}
        \input{declaration.tex}
    \fi
    \if@library
        \clearpage
        \chapter{Erklärung zu Bibliothek}
        \input{library.tex}
    \else\fi
}
