% Author: Johannes Demel
% This file requires quite a few texlive packages.
% texlive-lang-german / texlive-lang-european
% texlive-science

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{cel-thesis/cel-thesis}
\LoadClass[11pt,	% 11pt
	    titlepage,
      BCOR=18mm,  % Bindekorrektur für Druck
      DIV=13,     % Layout
	    twoside,		% Doppelseitige Ausgabe
	    a4paper,		% DIN A4
	    openright,	% Neue Kapitel auf rechter Seite
%	    draft,		  % Overfull H-Boxen markieren
	    final,		  % Engueltige Version mit Bildern
      listof = totoc,
      bibliography=totoc,
]{scrreprt}
\RedeclareSectionCommand[
beforeskip=0pt,
]{chapter}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% variables
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% new commands
\newcommand{\thesisTitle}[1]{\def \theThesisTitle{#1}}
\newcommand{\thesisType}[1]{\def \theThesisType{#1}}
\newcommand{\thesisAuthor}[1]{\def \theThesisAuthor{#1}}
\newcommand{\thesisAdvisor}[1]{\def \theThesisAdvisor{#1}}
\newcommand{\thesisSupervisor}[1]{\def \theThesisSupervisor{#1}}
\newcommand{\thesisHeadOfInstitute}[1]{\def \theThesisHeadOfInstitute{#1}}
\newcommand{\thesisStartDate}[1]{\def \theThesisStartDate{#1}}
\newcommand{\thesisEndDate}[1]{\def \theThesisEndDate{#1}}
\newcommand{\thesisSignatureDate}[1]{\def \theThesisSignatureDate{#1}}
\newcommand{\thesisLanguage}[1]{\def \theThesisLanguage{#1}}
\newcommand{\thesisCC}[1]{\def \theThesisCC{#1}}
\newcommand{\thesisPythonWatermark}[1]{\def \theThesisPythonWatermark{#1}}
% Defaults
\thesisTitle{Random Thesis Title}
\thesisType{Master Thesis Type}
\thesisAuthor{John Doe}
\thesisAdvisor{Dr.-Ing. Holger J\"akel}
\thesisHeadOfInstitute{Prof. Dr.-Ing. Laurent Schmalen}
\thesisSupervisor{Super-Assi Deluxe M.Sc.}
\thesisStartDate{dd.mm.yyyy}
\thesisEndDate{dd.mm.yyyy}
\thesisSignatureDate{dd.mm.yyyy}
\thesisLanguage{english}
\thesisCC{FALSE}
\thesisPythonWatermark{FALSE}

\def\dictThesisLanguageGerman{ngerman}
\def\dictThesisLanguageEnglish{english}
\def\dictThesisFALSE{FALSE}
\def\dictThesisTRUE{TRUE}


% General %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[T1]{fontenc}  % encoding for target files.
\usepackage[utf8]{inputenc} % UTF-8 encoding for source files
\usepackage{lmodern}

\usepackage{microtype}
\usepackage[printonlyused]{acronym} % use this package for abbreviations!
\def\setlanguage{
    \usepackage[\theThesisLanguage]{babel}
    \ifx\theThesisLanguage\dictThesisLanguageEnglish
        %\bibliographystyle{alpha} % American Style
        \bibliographystyle{cel-thesis/IEEEtranSA_own} % modified IEEE alpha style that allows underlining of own publications
        \def\theUniversity{Karlsruhe Institute of Technology}
        \def\theInstitute{Communications Engineering Lab}
        \sisetup{%
            binary-units = true,
            output-decimal-marker={.}
        }
    \else
        %\bibliographystyle{alphadin} % DIN norm
        \bibliographystyle{cel-thesis/IEEEtranSA_own} % modified IEEE alpha style that allows underlining of own publications
        \def\theUniversity{Karlsruher Institut für Technologie}
        \def\theInstitute{Institut für Nachrichtentechnik}
        \sisetup{%
            binary-units = true,
        output-decimal-marker={,}
        }
        \mathcode`,="013B % avoid space in comma decimal numbers
    \fi
}

% Math and Symbols %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amssymb, amsfonts, latexsym}
\usepackage{amsmath}
\usepackage[right]{eurosym}
\usepackage{siunitx}

%% Define always missing math symbols. 
\DeclareMathOperator*{\argmin}{\arg\!\min}
\DeclareMathOperator*{\argmax}{\arg\!\max}
\DeclareMathOperator\sign{sign}

%% Math adaptations
%% \j is æ in LaTeX2e, need to clear that
\let\j\relax
\newcommand{\j}{\mathrm{j}}
%% Re, Im are Fraktur for no-good reasons, so let's solve that:
\let\Re\relax
\let\Im\relax
\DeclareMathOperator{\Re}{Re}
\DeclareMathOperator{\Im}{Im}

\newcommand*{\scal}[1]{#1}
\newcommand*{\vect}[1]{\boldsymbol{#1}}
\newcommand*{\mat}[1]{\MakeUppercase{\boldsymbol{#1}}}



% Graphics %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ueberschriften fett
%\setkomafont{sectioning}{\normalcolor\bfseries}
% Bild- und Tabellen-Unterschriften formatieren
\renewcommand{\caplabelfont}{\bfseries}
\renewcommand{\capfont}{\small}
\newcommand{\figref}[1]{\figurename~\ref{#1}}

\usepackage{graphicx}
\usepackage{color}
\usepackage{pgf, tikz, pgfplots}
\usetikzlibrary{shapes,arrows, calc, spy}
\pgfplotsset{compat=1.9}

% Colors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\definecolor{kit-green100}{rgb}{0,.59,.51}
\definecolor{kit-green70}{rgb}{.3,.71,.65}
\definecolor{kit-green50}{rgb}{.50,.79,.75}
\definecolor{kit-green30}{rgb}{.69,.87,.85}
\definecolor{kit-green15}{rgb}{.85,.93,.93}
\definecolor{KITgreen}{rgb}{0,.59,.51}

\definecolor{KITpalegreen}{RGB}{130,190,60}
\colorlet{kit-maigreen100}{KITpalegreen}
\colorlet{kit-maigreen70}{KITpalegreen!70}
\colorlet{kit-maigreen50}{KITpalegreen!50}
\colorlet{kit-maigreen30}{KITpalegreen!30}
\colorlet{kit-maigreen15}{KITpalegreen!15}

\definecolor{KITblue}{rgb}{.27,.39,.66}
\definecolor{kit-blue100}{rgb}{.27,.39,.67}
\definecolor{kit-blue70}{rgb}{.49,.57,.76}
\definecolor{kit-blue50}{rgb}{.64,.69,.83}
\definecolor{kit-blue30}{rgb}{.78,.82,.9}
\definecolor{kit-blue15}{rgb}{.89,.91,.95}

\definecolor{KITyellow}{rgb}{.98,.89,0}
\definecolor{kit-yellow100}{cmyk}{0,.05,1,0}
\definecolor{kit-yellow70}{cmyk}{0,.035,.7,0}
\definecolor{kit-yellow50}{cmyk}{0,.025,.5,0}
\definecolor{kit-yellow30}{cmyk}{0,.015,.3,0}
\definecolor{kit-yellow15}{cmyk}{0,.0075,.15,0}

\definecolor{KITorange}{rgb}{.87,.60,.10}
\definecolor{kit-orange100}{cmyk}{0,.45,1,0}
\definecolor{kit-orange70}{cmyk}{0,.315,.7,0}
\definecolor{kit-orange50}{cmyk}{0,.225,.5,0}
\definecolor{kit-orange30}{cmyk}{0,.135,.3,0}
\definecolor{kit-orange15}{cmyk}{0,.0675,.15,0}

\definecolor{KITred}{rgb}{.63,.13,.13}
\definecolor{kit-red100}{cmyk}{.25,1,1,0}
\definecolor{kit-red70}{cmyk}{.175,.7,.7,0}
\definecolor{kit-red50}{cmyk}{.125,.5,.5,0}
\definecolor{kit-red30}{cmyk}{.075,.3,.3,0}
\definecolor{kit-red15}{cmyk}{.0375,.15,.15,0}

\definecolor{KITpurple}{RGB}{160,0,120}
\colorlet{kit-purple100}{KITpurple}
\colorlet{kit-purple70}{KITpurple!70}
\colorlet{kit-purple50}{KITpurple!50}
\colorlet{kit-purple30}{KITpurple!30}
\colorlet{kit-purple15}{KITpurple!15}

\definecolor{KITcyanblue}{RGB}{80,170,230}
\colorlet{kit-cyanblue100}{KITcyanblue}
\colorlet{kit-cyanblue70}{KITcyanblue!70}
\colorlet{kit-cyanblue50}{KITcyanblue!50}
\colorlet{kit-cyanblue30}{KITcyanblue!30}
\colorlet{kit-cyanblue15}{KITcyanblue!15}

% Layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{marginnote}
\RequirePackage{ifthen}
\RequirePackage[hidelinks, final=true]{hyperref}
\RequirePackage[ddmmyyyy]{datetime}
\renewcommand{\dateseparator}{.}
\RequirePackage[export]{adjustbox}


\setlength{\parskip}{5pt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create titlepage and optional parts like a CC statement.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\header}{%
  \begin{tabular*}{1.0\linewidth}[c]{lcr}
    \ifx\theThesisLanguage\dictThesisLanguageEnglish  % default is german. But one may use english.
    \includegraphics[height=18mm,valign=c]{cel-thesis/logos/kitlogo_en_rgb}%
    \else
    \includegraphics[height=18mm,valign=c]{cel-thesis/logos/kitlogo_de_rgb}%
    \fi
    &%
      \begin{minipage}{8cm}{\centering%
        \textbf{\theUniversity}\\
        \theInstitute%
        \par}\vspace*{0.5em}%
      \hspace*{1.5cm}\parbox{6.5cm}{%
        \small%
        \theThesisHeadOfInstitute%
        }%
      \end{minipage}%
    &% 
      \includegraphics[height=18mm,valign=c]{cel-thesis/logos/cel_logo}%
  \end{tabular*}
}
\newcommand{\ssection}[1]{\vspace*{0.8em}{\textbf{#1}}\\}

\def\makestatutorydeclaration{
  \include{cel-thesis/eidesstattliche_erklaerung}
}

\def\maketitle{
    \hypersetup{
        pdfauthor = \theThesisAuthor,
        pdftitle = {\theThesisType{ }\theThesisTitle{ } \theThesisAuthor},
        pdfsubject = {\theInstitute},
    }
    \thispagestyle{empty}
    \header  % institute banner, etc.
    \vspace*{5.0cm}%
    % Title
    \begin{center}
        {\Large \textbf{\theThesisTitle}} \\[1cm]
        {\large \theThesisType} \\[2.5cm]
        {\textbf{\theThesisAuthor}}\\[5cm]
        \begin{tabular}{lll}
        \ifx\theThesisLanguage\dictThesisLanguageEnglish  % default is german. But one may use english.
	  Advisor 	& : & \theThesisAdvisor \\
	  Supervisor 	& : & \theThesisSupervisor\\[2cm]
	  Start date 	& : & \theThesisStartDate \\
	  End date  	& : & \theThesisEndDate \\
	\else
	  Hauptreferent & : & \theThesisAdvisor \\
	  Betreuer      & : & \theThesisSupervisor\\[2cm]
	  Beginn        & : & \theThesisStartDate \\
	  Abgabe        & : & \theThesisEndDate \\
	\fi
	\end{tabular}
        
    \end{center}
    \hspace*{\fill}
    \newpage
    \makestatutorydeclaration
}

