\def\inPreamble{}% Flag setzen: wird sind in der Präambel

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Encoding %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% UTF8 Codierte .tex-Dateien
%\RequirePackage[utf8]{inputenc}

% Benutzung der europäischen Schriftkodierung
% z.B. zur richtigen Darstellung von Umlauten
\RequirePackage[T1]{fontenc}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Werkzeuge %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\RequirePackage{etoolbox}		% Einfacheres Programmieren in LaTeX
\RequirePackage{calculator}		% Rechnen (auch mit Längen)
\RequirePackage{xfp}			% Genaueres Rechnen (aber nicht mit Längen)
\RequirePackage{pbox}			% \pbox (Parbox flexibler Breite)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Variablen zur Anpassung durch den Benutzer %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% >>> werden gesetzt in der Datei "PersoenlicheAngaben.tex" %%%%%%%%%%%%%%%%%%

\newbool{abbildungsverzeichnis}
\newbool{quellcodeverzeichnis}
\newbool{tabellenverzeichnis}
\newbool{abkuerzungsverzeichnis}
\newbool{glossar}

\newbool{verzeichnisseZusammenfassen}
\newbool{verzeichnisseImInhaltsverzeichnis}

\newbool{nichtZitiertInweiterfuehrendeLiteratur}
\newbool{weiterfuehrendeLiteratur}

\newbool{verlaengerung}
\newbool{danksagung}
\newbool{color}
\newbool{colorListings}
\newbool{linksMarkieren}

\newbool{doppelseitig}

\newlength{\bindekorrektur}
\setlength{\bindekorrektur}{1cm}

\newlength{\randAussen}
\setlength{\randAussen}{1.88cm} % 1.88 - 2.5cm (einseitig), 2.5 - 3.4 cm (doppelseitig)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Benutzer-Einstellungen anwenden %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\input{Einstellungen}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Verzeichnis- & PDF-Verzeichnis-Einträge generieren %%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\verzeichnisEintrag}[2]{
	% #1 Name
	% #2 Label (für PDF)
	\ifbool{verzeichnisseImInhaltsverzeichnis}{%
		\phantomsection% damit die Seitenzahl auf jeden Fall stimmt
		\nopagebreak%
		\addcontentsline{toc}{chapter}{#1}% 
		\nopagebreak%
	}{%
		\pdfbookmark[0]{#1}{#2}% hier passte die Seitenzahl bisher immer, daher keine \phantomsection nötig
	}%
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Document-Class %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\ifbool{doppelseitig}{
	\def\onetwoside{twoside}
}{
	\def\onetwoside{oneside}
}

\documentclass[
	\onetwoside,% twoside: zweiseitig, oneside: einseitig
	titlepage, 	% Titelseite steht für sich allein
	english,    % Englische Sprache
% 	12pt,		% Schriftgröße
	10pt,		% Schriftgröße
	a4paper, 	% A4-Papier
	openright,
	headlines = 2
]{report}

\setlength{\parindent}{0pt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Sprachen %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\RequirePackage[%
	main=english, %Umsetzung der deutschen Sprache nach neuer Rechtschreibung
	ngerman % muss hier nochmal erwähnt werden, damit \autoref das auch mitbekommt
	]{babel}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Schriftarten, Schriftsatz %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% \RequirePackage{lmodern} % Schriftart lmodern nutzen
\RequirePackage{microtype} % Besserer Schriftsatz

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Zitate, Anführungszeichen %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\RequirePackage[
	autostyle, % Zitierstil an die aktuelle Sprache anpassen
	german=quotes, % wenn Deutsch -> „Anführungszeichen“ benutzen 
]{csquotes} %wird auch von biblatex verwendet


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Literaturverwaltung %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% \RequirePackage[backend=bibtex8,  %Daten von Bibtex holen
% 			style=alphabetic, %In der Form [Xil13] statt [1] referenzieren
% 			sorting=nyt	      %Name,Year,Title 
% 			]{biblatex}

\RequirePackage[backend=biber,  %Daten von Bibtex holen
			style=numeric-comp, %In der Form [Xil13] statt [1] referenzieren
			sorting=none 
			]{biblatex}

\addbibresource{Literatur/data.bib} % Literatur-Datei laden
\addbibresource{Literatur/fermions.bib} % Literatur-Datei laden
\addbibresource{Literatur/gmk.bib} % Literatur-Datei laden
\addbibresource{Literatur/lgt.bib} % Literatur-Datei laden
\addbibresource{Literatur/maths.bib} % Literatur-Datei laden
\addbibresource{Literatur/qft.bib} % Literatur-Datei laden
\addbibresource{Literatur/fkfpi.bib} % Literatur-Datei laden
\addbibresource{Literatur/intro.bib} % Literatur-Datei laden

\DeclareBibliographyCategory{cited} % registrieren, welche Quellen zitiert wurden
\AtEveryCitekey{%
	\addtocategory{cited}{\thefield{entrykey}}%
}

\NewBibliographyString{erratum}

\DefineBibliographyStrings{english}{
  erratum = {erratum:},
}

\DeclareFieldFormat{relatedstring:erratum}{\mkbibbold{#1}\printunit{\relatedpunct}}

% \ifbool{nichtZitiertInweiterfuehrendeLiteratur}{
% 	\nocite{*} % alle nicht zitierten Quellen mit aufnehmen
% }{
% 	\explizitesNocite
% }


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Seitengröße festlegen %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Berechnung der seitlichen Seitenränder:
\def\randAussenCm{}
\def\bindekorrekturCm{}
\LENGTHDIVIDE{\randAussen}{1cm}{\randAussenCm} 			% auf cm normieren
\LENGTHDIVIDE{\bindekorrektur}{1cm}{\bindekorrekturCm} 	% auf cm normieren

\newlength{\randRechtsAussen}	% Als Länge anlegen (bessere Wiederverwendbarkeit)
\newlength{\randLinksInnen}

\setlength{\randRechtsAussen}{\fpeval{1*\randAussenCm} cm}
\setlength{\randLinksInnen}{\fpeval{\randAussenCm/2+\bindekorrekturCm} cm}

% Anwenden
\usepackage[
%	showframe, 				% Seitenränder anzeigen - zum Debuggen
	layout=a4paper,			% Papierformat
 	headheight=1.2cm,		% durch Kopfzeile festgelegt
%	top=3.55cm,				% Abstand Text <-> oberer Seitenrand
% 	left=\randLinksInnen,	% Abstand Text <-> linker Seitenrand
% 	right=\randRechtsAussen,% Abstand Text <-> rechter Seitenrand
% 	bottom=3.7cm 			% Abstand Text <-> unterer Seitenrand
	top=2.5cm,				% Abstand Text <-> oberer Seitenrand
	inner=2cm,	            % Abstand Text <-> innerer Seitenrand
	outer=2cm,              % Abstand Text <-> äußerer Seitenrand
	bottom=2.5cm, 			% Abstand Text <-> unterer Seitenrand
	bindingoffset=5mm
]{geometry}

% \usepackage[inner=2cm,outer=2cm,top=2cm,bottom=2.5cm,bindingoffset=5mm]{geometry}
\usepackage[onehalfspacing]{setspace} % 1.5 fachen Zeilenabstand
\frenchspacing
\usepackage{emptypage} % Keine Seitenzahlen/Kopfzeilen auf Leerseiten

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% (R), (C), TM (vor allem für Zitate und das Literaturverzeichnis) %%%%%%%%%%%

\newcommand{\markRegistered}[1]{#1$^\text{\tiny{\textregistered\xspace}}$}
\newcommand{\markCopyrighted}[1]{#1$^\text{\tiny{\copyright\xspace}}$}
\newcommand{\markTrademark}[1]{#1$^\text{\tiny{\texttrademark\xspace}}$}
\usepackage[official]{eurosym}
\usepackage{bbm}
\usepackage{MnSymbol}
\usepackage{bbding} %Häkchen für abgehakte Dinge
\newcommand{\ok}{\Checkmark}
\newcommand{\x}{\XSolidBrush}
\newcommand{\xg}{\textcolor{gray}{\x}}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Farben %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[
	cmyk, 		% Konvertiere alle Farben in das cmyk-Farbmodell (besser zum Drucken)
	table, 		% Lade das colortbl package (Farben in Tabellen)
	showerrors,	% Nicht definierte Farbe verwendet -> Fehler erzeugen
]{xcolor}		% Farben
\usepackage{float}

% Universell nutzbar
\definecolor{Buw}			{cmyk}{0.55, 0.00, 1.00, 0.00} % Pantone 376
\definecolor{BuwEtikett}	{cmyk}{0.55, 0.00, 1.00, 0.10} % Pantone 376 + 10K

\definecolor{BuwFak01}		{cmyk}{0.08, 1.00, 0.65, 0.34} % Pantone 201
\definecolor{BuwFak02}		{cmyk}{1.00, 0.03, 0.34, 0.12} % Pantone 321
\definecolor{BuwFak03}		{cmyk}{1.00, 0.57, 0.12, 0.70} % Pantone 540
\definecolor{BuwFak04_oben}	{cmyk}{0.70, 0.30, 0.00, 0.12} % Pantone 646
\definecolor{BuwFak04_unten}{cmyk}{1.00, 0.61, 0.04, 0.26} % Pantone 301
\definecolor{BuwFak04}		{cmyk}{0.89, 0.34, 0.02, 0.09} % Pantone 7690
\definecolor{BuwFak05}		{cmyk}{0.23, 0.17, 0.13, 0.46} % Pantone Cool Gray 8
\definecolor{BuwFak06_oben}	{cmyk}{0.37, 1.00, 0.00, 0.26} % Pantone 2425
\definecolor{BuwFak06_unten}{cmyk}{0.37, 1.00, 0.00, 0.47} % Pantone 2425 + 30K
\definecolor{BuwFak07}		{cmyk}{1.00, 0.00, 0.55, 0.40} % Pantone 562
\definecolor{BuwFak08}		{cmyk}{0.00, 0.00, 0.00, 0.00} %
\definecolor{BuwFak09}		{cmyk}{0.00, 0.30, 0.85, 0.00} % Pantone 1235

\definecolor{pureK}			{cmyk}{0.00, 0.00, 0.00, 1.00} % K

\definecolor{AccentStrong}	{cmyk}{0.000,0.420,0.800,0.100} % Orange
\definecolor{AccentWeak}	{cmyk}{0.295,0.142,0.000,0.310} % Bläuliches Grau

\definecolor{customOrange}  {cmyk}{0.00, 0.55, 0.68, 0.07}

% Farbschema
\ifbool{color}{
	% wenn Farbe
	\colorlet{primaryTop}		{Buw}
	\colorlet{primaryMiddle}	{Buw}
	\colorlet{primaryBottom}	{Buw}
	% \colorlet{secondaryTop}		{BuwFak06_oben}
	% \colorlet{secondaryMiddle}	{BuwFak06_oben!50!BuwFak06_unten}
	% \colorlet{secondaryBottom}	{BuwFak06_unten}
 	\colorlet{secondaryTop}		{BuwFak04}
	\colorlet{secondaryMiddle}	{BuwFak04}
	\colorlet{secondaryBottom}	{BuwFak04}
	\colorlet{tertiaryTop}		{black!50}
	\colorlet{tertiaryMiddle}	{black!50}
	\colorlet{tertiaryBottom}	{black!50}
	\colorlet{textBlack}		{black}
}{
	% wenn Graustufen
	\colorlet{primaryTop}		{pureK}
	\colorlet{primaryMiddle}	{pureK}
	\colorlet{primaryBottom}	{pureK}
	\colorlet{secondaryTop}		{pureK!70}
	\colorlet{secondaryMiddle}	{pureK!70}
	\colorlet{secondaryBottom}	{pureK!70}
	\colorlet{tertiaryTop}		{pureK!50}
	\colorlet{tertiaryMiddle}	{pureK!50}
	\colorlet{tertiaryBottom}	{pureK!50}
	\colorlet{textBlack}		{pureK}
}

% Kurzform für mittlere Farbe
\colorlet{primary}			{primaryMiddle}
\colorlet{secondary}		{secondaryMiddle}
\colorlet{tertiary}			{tertiaryMiddle}


% Spezialisierter Anwendungszweck
\colorlet{pagenumber}		{tertiaryBottom!50!textBlack}
% \colorlet{headrule}			{primaryTop}
\colorlet{headrule}			{gray}
\colorlet{footnoteRule}		{secondary}
% \colorlet{footrule}			{primaryBottom}
\colorlet{footrule}			{gray}

% TODO Formelnummern Style
\colorlet{captionLabel}		{pureK!80}
\colorlet{subcaptionLabel}	{pureK!70}

\colorlet{captionText}		{pureK!70}
\colorlet{subcaptionText}	{pureK!60}

\colorlet{listingBackground}{pureK!5}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Fußnotengestaltung %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\renewcommand{\footnoterule}{%
	\textcolor{footnoteRule}{%
		\vspace*{-3pt}%
		\hrule height 0.1em width 0.4\columnwidth%
		\vspace*{2.6pt}%
	}%
}%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Kopfzeilen und Fußzeilen, Seitenzahl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\customFootrule{
	\renewcommand{\footrulewidth}{0.5mm}
	\renewcommand{\footrule}{%
		\begingroup
			\color{footrule}
			\hrule height \footrulewidth
% 			\vspace{0.5em}
			\vspace{0.3em}
		\endgroup
	}
}

\def\customHeadrule{
	\renewcommand{\headrulewidth}{0.5mm}
	\renewcommand{\headrule}{%
		\begingroup
			\color{headrule}
			\hrule height \headrulewidth 
		\endgroup
	}
}


\def\renewMarks{
	\renewcommand{\sectionmark}[1]{%
		\markright{%
			##1%~(\thesection)%
		}%
	}
	\renewcommand{\chaptermark}[1]{%
		\markboth{%
			##1% \chaptername~\thechapter%
		}{%
		}%
	}
}

\def\seitenNummer{%
	\color{pagenumber}\bfseries\thepage{}%
% 	\color{pagenumber}\sffamily\bfseries\thepage{}%
}

\usepackage{fancyhdr} % Schönere Kopfzeilen
\def\vertikalZentrieren{%
	\vspace{-\footrulewidth}%
	\vspace{-1.275em}%
}

\fancypagestyle{thesis-page-regular}{%
	\renewMarks

	\fancyhf{}%clear
% 	\fancyhead[RO,LE]{%
% 		\includegraphics[height=2em]{Medien/Uni_Wuppertal_Logo}%
% 	}
	
	\fancyhead[LO,RE]{%
		\nouppercase{%
			%\sffamily%
			\textbf{\leftmark}%
			\\%
			\rightmark%
		}%
	}

	\fancyfoot[RO]{\vertikalZentrieren\colorbox{white}{\seitenNummer}\hspace{1em}}
	\fancyfoot[LE]{\vertikalZentrieren\hspace{1em}\colorbox{white}{\seitenNummer}}
	
	\customHeadrule
	\customFootrule
}

\fancypagestyle{plain}{%
	\renewMarks
	\fancyhf{} % clear
	\fancyfoot[RO]{\vertikalZentrieren\colorbox{white}{\seitenNummer}\hspace{1em}}
	\fancyfoot[LE]{\vertikalZentrieren\hspace{1em}\colorbox{white}{\seitenNummer}}
	
	\customHeadrule
	\customFootrule
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Format der Überschriften %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[%
	nobottomtitles*,	% Überschriften am unteren Seitenrand vermeiden
]{titlesec}
 
% \def\titleformatBase{\sffamily\bfseries}
% \def\titleformatBase{\bfseries}
% \def\titleformatChapter{\Huge}
% \def\titleformatSection{\LARGE}
% \def\titleformatSubsection{\Large}
% \def\titleformatSubsubsection{\large}
% \def\titleformatParagraph{\normalsize}
% ----
\def\titleformatBase{\bfseries}
\def\titleformatChapter{\huge}
\def\titleformatSection{\Large}
\def\titleformatSubsection{\large}
%\def\titleformatSubsubsection{\large}
\def\titleformatSubsubsection{\normalsize}
\def\titleformatParagraph{\normalsize}

%\def\titlepartChapter	{\titleformatChapter\ifbool{weAreInTheAppendix}{\Alph{chapter}}{\arabic{chapter}}}
%\def\titlepartSection	{\titleformatSection\arabic{section}}
%\def\titlepartSubsection{\titleformatSubsection\arabic{subsection}}
\def\titlepartChapter	{\ifbool{weAreInTheAppendix}{\Alph{chapter}}{\arabic{chapter}}}
\def\titlepartSection	{\arabic{section}}
\def\titlepartSubsection{\arabic{subsection}}
\newbool{weAreInTheAppendix}
\setbool{weAreInTheAppendix}{false}
\appto{\appendix}{\setbool{weAreInTheAppendix}{true}}
\def\titleNumberExtraDistance{.5cm}

\titleformat{\chapter}[hang]
	{\titleformatBase}
	{\titleformatChapter\titlepartChapter\hphantom{.\titlepartSection.\titlepartSubsection}}
	{\titleNumberExtraDistance}
	{\titleformatChapter}
	%[after-code]
	
\titleformat{\section}[block]
	{\titleformatBase}
%	{\color{textBlack!50}\titlepartChapter.\color{textBlack}\titlepartSection\hphantom{.\titlepartSubsection}}
	{\titleformatSection\color{textBlack}\titlepartChapter.\color{textBlack}\titlepartSection\hphantom{.\titlepartSubsection}}
	{\titleNumberExtraDistance}
	{\titleformatSection}
	%[after-code]

\titleformat{\subsection}[block]
	{\titleformatBase}
%	{\color{textBlack!33}\titlepartChapter.\color{textBlack!50}\titlepartSection.\color{textBlack}\titlepartSubsection}
	{\titleformatSubsection\color{textBlack}\titlepartChapter.\color{textBlack}\titlepartSection.\color{textBlack}\titlepartSubsection}
	{\titleNumberExtraDistance}
	{\titleformatSubsection}
	%[after-code]
	
\titleformat{\subsubsection}[block]
	{\titleformatBase}
	{\titleformatSubsubsection\thesubsubsection}
	{}
	{%
%	\hphantom{\titlepartChapter\titlepartSection\titlepartSubsection}\hspace{\titleNumberExtraDistance}%
	\titleformatSubsubsection}
	%[after-code]
	
\titleformat{\paragraph}[runin]
	{\titleformatBase}
	{\titleformatParagraph\theparagraph}
	{0em}
	{%
%	\hphantom{\titlepartChapter\titlepartSection\titlepartSubsection}\hspace{\titleNumberExtraDistance}%
	\titleformatParagraph}%
	[]
	%[after-code]
	
%				command			left	before	after
\titlespacing*{\chapter}		{0pt}	{-2.1em}{1em}
\titlespacing*{\section}		{0pt}	{1em}	{1em}
\titlespacing*{\subsection}		{0em}	{1em}	{1em}
\titlespacing*{\subsubsection}	{0em}	{1em}	{1em}
\titlespacing*{\paragraph}		{0em}	{1em}	{1em}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Grafiken %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{graphicx}				% um Bilder einbinden zu können 
\usepackage{pdfpages}				% Ganzseitig externe PDFs einbinden (z.B. für Aufgabenstellung)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% TikZ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{tikz}					% Zeichnen per Code
\usetikzlibrary{shadows, patterns, shapes, shapes.geometric, arrows, decorations.pathreplacing, bending}	%Schatten mit Tikz
\usepackage[compat=1.1.0]{tikz-feynman}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
%
\pgfdeclarelayer{back}
\pgfsetlayers{back,main}
\makeatletter
\pgfkeys{%
	/tikz/on layer/.code={
		\pgfonlayer{#1}\begingroup
		\aftergroup\endpgfonlayer
		\aftergroup\endgroup
	},
	/tikz/node on layer/.code={
		\pgfonlayer{#1}\begingroup
		\expandafter\def\expandafter\tikz@node@finish\expandafter{\expandafter\endgroup\expandafter\endpgfonlayer\tikz@node@finish}%
	},
}
\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% SI-Einheiten und Zahlendarstellung %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[
	% Die Einstellungen für dieses Paket befinden sich in der Datei siunitx.cfg
]{siunitx}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Mathematik-/Physikpackages %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{amsmath}
\usepackage{mathtools}
% Add your packages here
\let\centerdot\relax % Avoid conflict with amssymb
\let\veebar\relax % Avoid conflict with amssymb
\let\barwedge\relax % Avoid conflict with amssymb
\let\doublebarwedge\relax % Avoid conflict with amssymb
\let\circledS\relax % Avoid conflict with amssymb
\let\dotplus\relax % Avoid conflict with amssymb
\let\complement\relax % Avoid conflict with amssymb
\let\divideontimes\relax % Avoid conflict with amssymb
\let\thicksim\relax % Avoid conflict with amssymb
\let\thickapprox\relax % Avoid conflict with amssymb
\let\hslash\relax % Avoid conflict with amssymb
\usepackage{amssymb}
\usepackage{bm}
\usepackage{nicefrac}
\usepackage{physics}
\usepackage{slashed}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Listen und Tabellen %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{enumitem} %enumitem or paralist
\setlist[enumerate]{font=\bfseries} %bold indices in enumerate
\usepackage{multirow}             % Zusammenfassen von Tabellenzellen 
                                  % \multicolumn und \multirow
\usepackage{booktabs}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Quellcode %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{listings} %Für Quelltexte

% manuell Übersetzen
\renewcommand{\lstlistingname}{Quellcode}
\renewcommand{\lstlistlistingname}{Quellcodeverzeichnis}

\ifbool{color}{
	\def\listingBasicstyle		{\color{black}\ttfamily\small}
	\def\listingKeywordstyle	{\color{primary}\bfseries}
	\def\listingStringstyle		{\color{secondary}\slshape}
	\def\listingCommentstyle	{\color{AccentWeak}\fontseries{l}\selectfont}
	\def\listingEmphstyle		{\color{AccentStrong}\bfseries}
	\def\listingRulecolor		{\color{AccentWeak}}
	\def\listingNumbercolor		{\color{AccentWeak!60}}
}{
	\def\listingBasicstyle		{\color{pureK}\ttfamily\small}
	\def\listingKeywordstyle	{\color{pureK}\bfseries}
	\def\listingStringstyle		{\color{pureK}\slshape}
	\def\listingCommentstyle	{\color{pureK}\fontseries{l}\selectfont}
	\def\listingEmphstyle		{\color{pureK}\bfseries\underbar}
	\def\listingRulecolor		{\color{pureK!50}}
	\def\listingNumbercolor		{\color{pureK!26}}
}

\lstset{
	basicstyle	= \listingBasicstyle,		% Basisformat
	keywordstyle= \listingKeywordstyle,		% Schlüsselwörter
	stringstyle	= \listingStringstyle,		% Strings
	commentstyle= \listingCommentstyle,		% Kommentare
	emphstyle	= \listingEmphstyle,		% Hervorhebungen
%	
% TODO ???
%		extendedchars=true,         
	breaklines=true,            % Zeilen werden Umgebrochen
	breakatwhitespace=true,		% erlaube Zeilenumbrüche nur an Whitespace
	breakindent=0em,
	breakautoindent=true, % bei Zeilenumbruch automatisch einrücken
%
	prebreak=,
	postbreak=\mbox{$\hookrightarrow$\hspace{-0.34em}\hphantom{m}},
%	
	showstringspaces=true, 		% Leerzeichen in Strings zeigen
	showspaces=false,           % Leerzeichen anzeigen?
	showtabs=false,             % Tabs anzeigen?
	tabsize=3,					% Zeichenbreite eines Tabs
%	
	keepspaces=false,			% Erlaubt die Unterdrückung von Leerzeichen zugunsten eines besseren Spalten-Layouts
	columns=fixed,				% Zeichenbreite
%	
	captionpos=b, 				% Position der Beschriftung
	xleftmargin=2.2em, 			% Abstand zum Rand
	xrightmargin=0.35em,		%
	framexleftmargin=0em,		% Abstand im Rahmen
	framexrightmargin=0pt,		%
	framexbottommargin=2pt,		%
	framextopmargin=0pt,		%
	frame=tblr,					% Rahmen anzeigen
	frameround=tftf,			% t: abgerundete Ecke, f: eckige Ecke
	backgroundcolor=\color{listingBackground}, % Hintergrundfarbe
	rulecolor=\listingRulecolor,% Farbe der Umrandung
%
	numbers=left,
	numberstyle=\scriptsize\ttfamily\listingNumbercolor, %Stil der Zeilennummern
	stepnumber=1,
}

\lstset{literate= 				% Umlaute in Listings erlauben
	{Ö}{{\"O}}1
	{Ä}{{\"A}}1
	{Ü}{{\"U}}1
	{ß}{{\ss}}2
	{ü}{{\"u}}1
	{ä}{{\"a}}1
	{ö}{{\"o}}1
}

\lstdefinelanguage{thesis-latexbeispiel}
	{morekeywords=
		{\\begin, \\end, \\frac, \\pi, \\\\, \\sum, \\varphi, \\pm, \\int, \\limits, \\infty, \\cdot, \\sqrt, \\left, \\right, \\mathrm,
		\\linewidth, \\centering, \\includegraphics, \\caption, \\label, \\lstinline, \\lstinputlisting, \\todo, \\listoftodos, \\url, \\href, \\cite, \\textqoute,
		\\gls, \\glssymbol, \\LaTeX},
		emph={figure, table, tabular, align, lstlisting},
		sensitive=true,
		morecomment=[l]{\%},
%		morecomment=[s]{/*}{*/},
%		morestring=[b]",
		alsoletter={\\},
	}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Format der Float-Beschriftungen %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{caption}
\usepackage[labelformat=brace,list=true]{subcaption}
%Farbiger Text geht mit labelfont={bf,it,color=red}
% Mehr Infos zu CaptionStyle http://ctan.math.washington.edu/tex-archive/macros/latex/contrib/caption/caption-eng.pdf
\DeclareCaptionStyle{myCaptionStyle}{%
	format=plain,			% Basis-Format
	labelsep=quad,			% Abstand Typ/Nummer <-> Beschriftung
%	indention=-7em,			%
	margin=0.5em,				% Zusatzabstand Links
	singlelinecheck=false,	%
    labelfont={small,bf,color=captionLabel},% Font Typ/Nummer
	textfont={small, color=captionText},	% Font Beschriftung
% 	labelfont={sf,small,bf,color=captionLabel},% Font Typ/Nummer
% 	textfont={sf,small, color=captionText},	% Font Beschriftung
}

\DeclareCaptionStyle{mySubCaptionStyle}{%
	format=plain,			% Basis-Format
	labelsep=space,			% Abstand Typ/Nummer <-> Beschriftung
%	indention=-7em,			%
	margin=0.5em,			% Zusatzabstand links
	singlelinecheck=false,	%
    labelfont={small,bf, color=subcaptionLabel},% Font Typ/Nummer
	textfont={small, color=subcaptionText},	% Font Beschriftung
% 	labelfont={sf,small,bf, color=subcaptionLabel},% Font Typ/Nummer
% 	textfont={sf,small, color=subcaptionText},	% Font Beschriftung
}

% labelformat: empty  :
%              simple : a 
%              brace  : a)
%              parens : (a)


\captionsetup[table]{style=myCaptionStyle}
\captionsetup[figure]{style=myCaptionStyle}
\captionsetup[lstlisting]{style=myCaptionStyle}

\captionsetup[subfigure]{style=mySubCaptionStyle}
\captionsetup[subtable]{style=mySubCaptionStyle}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% PDF-Meta-Informationen und Links im Dokument %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[]{hyperref}

\ifbool{linksMarkieren}{
	% nichts
}{
	\hypersetup{hidelinks} % Link-Markierung verstecken
}

\hypersetup{
	linktoc=all, 						% Welcher Teil im Inhaltsverzeichnis ist klickbar? (none/section/page/all)
    colorlinks=false,					% false: boxed links (wird nicht mitgedruckt); true: colored links (wird auch so gedruckt!)
    hidelinks,
	linkcolor=primary!0!white,			% color of internal links
    linkbordercolor=primary!0!white,
%
    citecolor=primary!100!black,			% color of links to bibliography
    citebordercolor=primary!100!gray,
%
    filecolor=AccentStrong,				% color of file links
    filebordercolor=AccentStrong!20,
%
    urlcolor=AccentWeak,				% color of external links
    urlbordercolor=AccentWeak!20,
%
	menucolor=blue,
	menubordercolor=blue,
%
	runcolor=red,
	runbordercolor=red,
%
    %bookmarks=true,			% show bookmarks bar?
    bookmarksnumbered=true,
    bookmarksopen=true,
    bookmarksopenlevel=0,
    unicode=true,				% non-Latin characters in Acrobat’s bookmarks
    pdftoolbar=true,			% show Acrobat’s toolbar?
    pdfmenubar=true,			% show Acrobat’s menu?
    pdffitwindow=false,			% window fit to page when opened
    pdfstartview={FitH},		% fits the width of the page to the window
    pdftitle=\thema,			% Titel
    pdfauthor=\autor,			% Autor
    pdfsubject=\artderarbeit,	% subject of the document
    pdfcreator=LaTeX,			% creator of the document
    pdfproducer=,				% producer of the document
    pdfkeywords=\schlagwoerter,	% Schlagworte
    pdfnewwindow=true,			% Links in neuem Fenster öffnen
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Besseres Zitieren (Groß-/Kleinschreibung) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[noabbrev, nameinlink]{cleveref}
\creflabelformat{equation}{#2\textup{#1}#3}
%\usepackage{cite}                 % Besser zitieren: -> [1-3, 6-8] unnötig mit biblatex

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Glossar, Abkürzungen, Akronyme, Symbole, ... %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage[
	toc=false,		% Nicht im Inhaltsverzeichnis anzeigen. Wenn die Verzeichnisse dort erscheinen sollen, machen wir das selber
	translate=babel,% Babel zum Übersetzen verwenden
	acronym,		% Eigenes Verzeichnis für Akronyme	(CRC, BAföG, LASER, ...)
	abbreviations,	% Eigenes Verzeichnis für Abkürzungen (Dr., z.B., bspw., bzw., etc.)
	symbols,		% Eigenes Verzeichnis für Symbole (µ, ...)
]{glossaries-extra}

\usepackage{glossary-longragged}% Extra Style
\usepackage{glossary-mcols}% Extra Style

%TODO was macht das/wozu war das gut?
%\forglsentries[symbols]{\thislabel}{\gls{\thislabel}. } 
%\forglsentries[symbols]{\thislabel}{\glssymbol{\thislabel}. }

\renewcommand{\abbreviationsname}{Abkürzungen} % wird mit translate=babel irgendwie nicht übersetzt => dann machen wir das eben selber
\renewcommand{\seename}{siehe} % wird mit translate=babel irgendwie nicht übersetzt => dann machen wir das eben selber

% \makenoidxglossaries %langsames sortieren, geht aber immer und braucht keine externen Programme
% \loadglsentries{Glossar.tex}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Anpassung von Nummerierungstiefe etc. (default passt aber schon)
%\setcounter{secnumdepth}{3} %Nummerierungstiefe
%\setcounter{tocdepth}{2} %Kapiteltiefe im Inhaltverzeichnis

\usepackage{blindtext}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Todos %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% \usepackage[
% 	ngerman,
% %	textwidth=\randRechtsAussen-0em,%TODO sollte sich berechnen lassen, oder?
% 	textsize=scriptsize
% ]{todonotes}

\setlength{\marginparwidth}{\randAussen-2.5mm}% hieraus ergibt sich die Breite der Todo-Boxen