
%% Links
\definecolor{ccolor}{HTML}{bc2323} % Cite
\definecolor{dcolor}{HTML}{2370bc} % DOI
\definecolor{rcolor}{HTML}{bc2323} % Internal links

%% -------------------------------------------------------
%% TikZ Plots
%% -------------------------------------------------------

\definecolor{dodgerblue}{rgb}{0.12, 0.56, 1.0}
\definecolor{awesome}{rgb}{1.0, 0.13, 0.32}

\tikzstyle{sketch}=[black, >=stealth, line width=0.3mm, font={\small}]

\tikzset{
  % style to apply some styles to each segment of a path
  on each segment/.style={
    decorate,
    decoration={
      show path construction,
      moveto code={},
      lineto code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
      curveto code={
        \path [#1] (\tikzinputsegmentfirst)
        .. controls
        (\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
        ..
        (\tikzinputsegmentlast);
      },
      closepath code={
        \path [#1]
        (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
      },
    },
  },
  % style to add an arrow in the middle of a path
  mid arrow/.style={postaction={decorate,decoration={
        markings,
        mark=at position .5 with {\arrow[#1]{stealth}}
      }}},
}

\newcommand{\prop}[4]{(#1,#2)[fill] circle(0.05)node[#3]{#4}}
\newcommand{\vloop}[3][0.25]{\draw(#2,#3) circle(#1)}

%% -------------------------------------------------------

%% Serif fonts
\addtokomafont{disposition}{\rmfamily}

%% Relative path
\makeatletter
\providecommand*{\input@path}{}
\g@addto@macro\input@path{{lectures/}}
\makeatother

%% Geometry
\geometry{
    a4paper,
    left=20mm,
    right=45mm, 
    top=3.0cm, 
    bottom=3.5cm,
    headheight=10mm,
    headsep=12mm,
}

%% Hyperref
\urlstyle{tt}

\hypersetup{
    %bookmarks=true,        % show bookmarks bar?
    unicode=false,          % 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={}, % title
    pdfauthor={Nicolai Lang},       % author
    pdfsubject={Dissertation 2019},   % subject of the document
    pdfcreator={Nicolai Lang},      % creator of the document
    pdfproducer={Nicolai Lang},     % producer of the document
    pdfkeywords={}, % list of keywords
    pdfnewwindow=true,      % links in new window
    colorlinks=true,        % false: boxed links; true: colored links
    linkcolor=rcolor,      % color of internal links
    citecolor=ccolor,         % color of links to bibliography
    filecolor=magenta,      % color of file links
    urlcolor=dcolor           % color of external links
}

%% Layer
\definecolor{bgcolor}{HTML}{e8e8e8} %fff4d6
\definecolor{fgcolor}{HTML}{808080}
\definecolor{numbercolor}{HTML}{808080}
\definecolor{warning}{HTML}{e00f0f}
\DeclareNewLayer[% define a new layer
background,
contents={%
    \begin{tikzpicture}[remember picture, overlay]
        \node (ne) [anchor=center,xshift=0cm] at (current page.north east) {};
        \node (se) [anchor=center,xshift=-40mm] at (current page.south east) {};
        \fill[bgcolor!50] (se) rectangle (ne);
        \node [anchor=center,fgcolor,align=center,xshift=-20mm,yshift=18mm] at (current page.south east) {\sffamily\normalsize{↑ Notes}};
        \draw [dotted,fgcolor!50,line width=0.5pt] ([yshift=-23mm,xshift=-40mm]current page.north east) -- ([yshift=-23mm]current page.north east);
        \draw [bgcolor,line width=0.5pt] ([yshift=-23mm,xshift=-40mm]current page.north east) -- ([yshift=-23mm,xshift=0mm]current page.north west);
        \draw [dotted,fgcolor!50,line width=0.5pt] ([yshift=28mm,xshift=-40mm]current page.south east) -- ([yshift=28mm]current page.south east);
        \draw [bgcolor,line width=0.5pt] ([yshift=28mm,xshift=-40mm]current page.south east) -- ([yshift=28mm,xshift=0mm]current page.south west);
        %\node [circle, draw=fgcolor,line width=1pt,inner sep=2mm,anchor=center,fgcolor,align=center,xshift=-20mm,yshift=-12mm] at (current page.north east) {\sffamily\small{DRAFT}};
        \node [anchor=center,xshift=-20mm,yshift=-12mm] at (current page.north east) {\includegraphics[width=2.2cm]{itp3_logo_institut_simple_hellgrau}};
    \end{tikzpicture}
}
]{defaultbackground}

\renewcommand{\sectionmark}[1]{}

\clearpairofpagestyles
\setkomafont{pageheadfoot}{\footnotesize}
\lohead{\color{fgcolor}\footnotesize{LECTURE}~{\color{numbercolor}\huge\bfseries\thelecture}} 
\cohead{}
\rohead{\color{fgcolor}\footnotesize{\rightmark}}
\rofoot{\color{fgcolor}\footnotesize{PAGE}~\huge\bfseries\thepage}
\lofoot{\color{fgcolor}\footnotesize\MakeUppercase{\lecturer~•~ITP~III~•~University of Stuttgart}}
\AddLayersToPageStyle{scrheadings}{defaultbackground}

\newcommand{\chapternpb}[1]{\let\clearpage\relax\chapter{#1}}
\renewcommand*{\chapterpagestyle}{scrheadings}

%% Script commands
\definecolor{notecolor}{HTML}{2d69e2}
\newcommand{\note}[1]{{\color{notecolor}#1}}
\definecolor{importantcolor}{HTML}{ff007f}
\newcommand{\imp}[1]{{\color{importantcolor}\noindent #1}}
\newcommand{\mimp}[1]{\text{\imp{#1}}\nonumber}
\definecolor{asidecolor}{HTML}{2fa318}
\newcommand{\aside}[1]{{\color{asidecolor}#1}}

%% Lectures
\newcommand{\newlecture}{%
    \clearpage
    \stepcounter{lecture}
}

\markright{}
\newcommand{\reference}[1]{%
    \markright{→~#1}
}

%% Reformat equation labels at equations and in text
\makeatletter
\def\tagform@#1{\maketag@@@{\footnotesize\ignorespaces(#1)\unskip\@@italiccorr}}
\makeatother

%% Math
\makeatletter
\newenvironment{subalign}[1][\@nil]{%
\subequations%
\align%
\def\tmp{#1}%
\ifx\tmp\@nnil%
\else%
\label{#1}%
\fi%
}{%
\endalign%
\endsubequations%
}
\makeatother

\makeatletter
\newenvironment{eqaligned}[1][\@nil]{%
%\subequations%
\equation%
\def\tmp{#1}%
\ifx\tmp\@nnil%
\else%
\label{#1}%
\fi%
\aligned%
}{%
\endaligned%
\endequation%
%\endsubequations%
}
\makeatother

\newenvironment{emphalign}{\empheq[box=\highlight]{align}}{\endempheq}
\newenvironment{emphalignat}{\empheq[box=\highlight]{alignat}}{\endempheq}

%% Environments
\newtheoremstyle{theoremsans}% name of the style to be used
{20pt}% measure of space to leave above the theorem. E.g.: 3pt
{20pt}% measure of space to leave below the theorem. E.g.: 3pt
{\rmfamily}% name of font to use in the body of the theorem
{0pt}% measure of space to indent
{}% name of head font
{}% punctuation between head and body
{ }% space after theorem head; " " = normal interword space
{\rmfamily\textbf{#1~#2:\enspace#3}\\*[5pt]}
% \theoremstyle{theoremsans}
% \newtheorem{myexample}{Example}[chapter]
% \newenvironment{example}%
% {\begin{mdframed}[backgroundcolor=examplecolor]\begin{myexample}}%
% {\end{myexample}\end{mdframed}}

\mdfdefinestyle{colorbox}{%
    backgroundcolor=white!10,
    linecolor=white,
    linewidth=2pt,
    topline=false,
    bottomline=false,
    rightline=false,
    leftline=true,
    frametitlefont=\normalsize\sffamily\bfseries\color{black},
    splittopskip=.5cm,
    innertopmargin=.4cm,
    innerbottommargin=.4cm,
    frametitleaboveskip=.4cm,
    frametitlebelowskip=.0cm,
}

%% Examples
\definecolor{examplecolor}{HTML}{737373}
\mdtheorem[style=colorbox,backgroundcolor=examplecolor!10,linecolor=examplecolor]{example}{(->)~~Example}[chapter]

%% Notes
\definecolor{blocknotecolor}{HTML}{104fad}
\mdtheorem[style=colorbox,backgroundcolor=blocknotecolor!10,linecolor=blocknotecolor]{blocknote}{(->)~~Note}[chapter]
\mdtheorem[style=colorbox,backgroundcolor=blocknotecolor!10,linecolor=blocknotecolor,fontcolor=notecolor]{optionalblocknote}{(->)~~Note}[chapter]

%% Lecture topics
\definecolor{lecturecolor}{HTML}{ffbb47}
\mdtheorem[style=colorbox,backgroundcolor=lecturecolor!10,linecolor=lecturecolor]{lecturebox}{%
(->)~~Topics of Lecture~\thelecture}
\newenvironment{lecture}{%
\newpage%
\stepcounter{lecture}%
\small\begin{lecturebox*}%
\begin{enumerate}\setlength\itemsep{0.0cm}%
}{\end{enumerate}\end{lecturebox*}}

%% Problemset topics
\definecolor{problemcolor}{HTML}{ad1084}
\mdtheorem[style=colorbox,backgroundcolor=problemcolor!10,linecolor=problemcolor]{problembox}{%
(->)~~Topics of Problemset~\theproblemset}
\newenvironment{problemset}{%
\stepcounter{problemset}%
\small\begin{problembox*}%
\begin{enumerate}\setlength\itemsep{0.0cm}%
}{\end{enumerate}\end{problembox*}}

\definecolor{interludecolor}{HTML}{6d6d6d}
\mdtheorem[style=colorbox,backgroundcolor=interludecolor!10,linecolor=interludecolor]{interludebox}{↓~~Interlude}
\newenvironment{interlude}{\small\begin{interludebox*}}{\end{interludebox*}}

\definecolor{importantcolor}{HTML}{db0606}
\mdtheorem[style=colorbox,backgroundcolor=importantcolor!10,linecolor=importantcolor]{importantbox}{⁂~~Important}
\newenvironment{important}{\small\begin{importantbox*}}{\end{importantbox*}}

\definecolor{defcolor}{HTML}{10ad72}
\mdtheorem[style=colorbox,backgroundcolor=defcolor!10,linecolor=defcolor]{defbox}{★~~Definition}
\newenvironment{definition}{\small\begin{defbox*}}{\end{defbox*}}

% \definecolor{notecolor}{HTML}{34a02e}
\mdtheorem[style=colorbox,backgroundcolor=notecolor!10,linecolor=notecolor]{notebox}{†~~Note}
\newenvironment{notice}{\small\begin{notebox*}}{\end{notebox*}}

\definecolor{topiccolor}{HTML}{ffbb47}
\mdtheorem[style=colorbox,backgroundcolor=topiccolor!10,linecolor=topiccolor]{topicbox}{◊~~Goals and summary of this lecture}
\newenvironment{topic}{\small\begin{topicbox*}}{\end{topicbox*}}

% \newenvironment{redbox}{}{}
% \tcolorboxenvironment{redbox}{before skip=6pt, after skip=6pt, colframe=red, colback=white, arc=0pt, boxrule=2pt}

% \mdfdefinestyle{filledbox2}{%
%     backgroundcolor=bgcolor!50,
%     linecolor=bgcolor,
%     linewidth=3pt,
%     topline=false,
%     bottomline=false,
%     rightline=false,
%     leftline=true,
%     innertopmargin=2ex,
%     innerbottommargin=2ex,
%     innerrightmargin=3ex,
%     innerleftmargin=0ex
% }
% \newenvironment{topic}{\begin{mdframed}[style=filledbox2]\sffamily\small\begin{itemize}}{\end{itemize}\end{mdframed}}

\newtcolorbox{highlightbox}[1][]{%
nobeforeafter,tcbox raise base, enhanced, colframe=red, colback=white, arc=0pt, boxrule=2pt, top=0pt, bottom=12pt, boxsep=0pt, #1
}

\newtcbox{\highlight}[1][]{%
nobeforeafter,math upper,tcbox raise base, enhanced, colframe=red, colback=white, arc=0pt, boxrule=2pt, #1
}

\definecolor{marked}{HTML}{ff8300}
\newcommand{\marked}[1]{{\color{marked}#1}}
\definecolor{markedindex}{HTML}{bb1fef}
\newcommand{\mi}[1]{{\color{markedindex}#1}}

%% Shortcuts
\newcommand{\seepset}[1]{(->) Problemset~#1}
\renewcommand{\leadsto}{$\rightarrow$~}
\renewcommand{\therefore}{\leadsto}
\newcommand{\consider}{$\sphericalangle$~}
\newcommand{\Note}{\textit{\textbf{Note:}}~}
\newcommand{\fref}{→~}
\newcommand{\bref}{←~}
\newcommand{\see}{\fref}
\newcommand{\uref}{↑~}
\newcommand{\dref}{↓~}
\newcommand{\nte}{\circeq}
\newcommand{\hnte}{\stackrel{*}{=}}
\newcommand{\easytoshow}{$\xrightarrow{\circ}$~}
\newcommand{\noteasytoshow}{$\xrightarrow{*}$~}
\renewcommand{\land}{$\wedge$~}
\renewcommand{\lor}{$\vee$~}
\newcommand{\limplies}{$\Rightarrow$}
\newcommand{\rep}{\square}
\newcommand{\aref}{\blacksquare}
\newcommand{\termdef}[1]{$\ast$~\textit{#1}}
\newcommand{\optional}{$\ast$~}

%% Topic reference
\newcommand{\tref}[1]{[→~\cref{#1}]}
% \crefname{section}{Section}{Sections}

%% DOI style
\let\origdoi\doi
\renewcommand{\doi}[1]{{\footnotesize\bfseries\texttt{\origdoi{#1}}}}

%% Font for URLs
\renewcommand\UrlFont{\ttfamily}

%% Backref
\renewcommand*{\backref}[1]{}
\renewcommand*{\backrefalt}[4]{%
    \ttfamily\footnotesize
    \ifcase #1 (Not cited.)%
    \or        (Cited on page~#2.)%
    \else      (Cited on pages~#2.)%
\fi}

\newtheoremstyle{theoremitalic}% name of the style to be used
{20pt}% measure of space to leave above the theorem. E.g.: 3pt
{20pt}% measure of space to leave below the theorem. E.g.: 3pt
{\itshape}% name of font to use in the body of the theorem
{0pt}% measure of space to indent
{}% name of head font
{}% punctuation between head and body
{ }% space after theorem head; " " = normal interword space
{\sffamily\textbf{\textsc{#1~#2}:\enspace#3}\\*[5pt]}

\newtheoremstyle{theoremsans}% name of the style to be used
{20pt}% measure of space to leave above the theorem. E.g.: 3pt
{20pt}% measure of space to leave below the theorem. E.g.: 3pt
{\sffamily}% name of font to use in the body of the theorem
{0pt}% measure of space to indent
{}% name of head font
{}% punctuation between head and body
{ }% space after theorem head; " " = normal interword space
{\sffamily\textbf{\textsc{#1~#2}:\enspace#3}\\*[5pt]}

%% =============================================================================
%% Theorems
%% =============================================================================
\theoremstyle{theoremitalic}
\newtheorem{myresult}{Result}[chapter]
\newtheorem{myprop}{Proposition}[chapter]
\newtheorem{mylemma}{Lemma}[chapter]
\newtheorem{mytheorem}{Theorem}[chapter]
\newtheorem{myconjecture}{Conjecture}[chapter]
\newtheorem{mycorollary}{Corollary}[chapter]
\newtheorem{mydef}{Definition}[chapter]
\newtheorem{myremark}{Remark}[chapter]
\newtheorem{myexample}{Example}[chapter]

%% =============================================================================
%% TikZ styles
%% =============================================================================

%% Styles
% \tikzstyle{roundlabel}=[circle,inner sep=1.5pt,fill=tikzgrey,color=black,text=white,draw,font=\sffamily\footnotesize]
% \tikzstyle{TlabelB}=[rectangle callout,rounded corners=0.03cm,inner sep=3.0pt,fill=tikzlight,color=tikzlight,text=tikzgrey,draw,font=\sffamily\footnotesize,callout absolute pointer={#1},at={#1},above=0.2cm,align=center]
% \tikzstyle{smallbullet}=[circle,inner sep=0.5pt,fill=tikzorange,color=tikzorange,text=white,draw,font=\sffamily\small\bfseries]
% \tikzstyle{labelline}=[rounded corners=0.5mm,black,line width=2pt,solid]
% \tikzstyle{labeltext}=[color=white,fill=white,inner sep=0.5pt,text=tikzgrey,draw,font=\sffamily\footnotesize]
% \tikzstyle{math}=[font=\Large,align=center]
%\tikzstyle{figure}=[anchor=south west]
%\tikzstyle{label}=[circle,inner sep=0.07cm,fill=white,text=black,draw=white]
% \tikzstyle{tlabel}=[inner sep=0.07cm,text=black]
% \tikzstyle{wlabel}=[inner sep=0.07cm,text=black,anchor=west,font=\footnotesize]
% \tikzstyle{figtext}=[anchor=west, rounded corners=0.0cm,inner sep=0.07cm,fill=white,color=white,text=black,draw,font=\sffamily\footnotesize]

%% Grid
\newcommand{\grid}{%
    \draw[step=0.2cm,sublatticecolor,very thin] (0,0) grid (11,17);
    \draw[step=1.0cm,black,thin] (0,0) grid (11,17);
    \foreach \x in {0,1,...,11}
    \draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north,font=\sffamily\tiny] {\x};
    \foreach \y in {0,1,...,17}
    \draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east,font=\sffamily\tiny] {\y};
}

%% Scale (for labels)
% \tikzset{every picture/.append style={scale=1.22807}}

%\tikzset{label/.style={anchor=north west, inner sep=0pt, font=\small\sffamily\bfseries}}
%\tikzset{info/.style={anchor=north west, inner sep=0pt, font=\small\sffamily}}
%\tikzset{image/.style={anchor=north west, inner sep=0pt}}

% \newcommand{\inputtikz}[1]{%
%   \tikzsetnextfilename{#1}%
%   \input{#1.tikz}%
% }

%% =============================================================================
%% Labels
%% =============================================================================

%% Figures
\newcommand{\lbl}[1]{\bfseries\sffamily\small(#1)}
\newcommand{\CaptionMark}[1]{{\boldmath\textbf{#1}}}
\newcommand{\CaptionLabel}[1]{\textbf{(#1)}}
\newcommand{\CaptionLabelR}[1]{(#1)}

%% =============================================================================
%% Captions
%% =============================================================================

%% Styling
\DeclareCaptionLabelSeparator{vline}{~•~}
\DeclareCaptionFormat{myformat}{\small\sffamily{\scfont\textbf{#1#2}}#3}

\DeclareCaptionStyle{mystyle}[
    margin=5mm,
    justification=centering
]{margin={0mm,0mm},labelsep=vline}

\captionsetup{style=mystyle,format=myformat}

\setlength{\parskip}{5pt plus 1pt minus 1pt}
\setlength{\parindent}{0pt}

%% =============================================================================
%% Tables
%% =============================================================================

%% Tabular columns with fixed width
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}

%% =============================================================================
%% Lists
%% =============================================================================

%\definecolor{sepcolor}{HTML}{cecece}
%~\color{sepcolor}|
%\setenumerate[0]{label={\color{itemcolor}\footnotesize\sffamily\textbf{\arabic*.}}}

\definecolor{itemcolor}{HTML}{000000}
\definecolor{sepcolor}{HTML}{cecece}
\newenvironment{lot}{%
\setenumerate[1]{label={\color{itemcolor}\footnotesize\sffamily\textbf{\arabic*~\color{sepcolor}|}}}
\setenumerate[2]{label={\color{itemcolor}\footnotesize\sffamily\textbf{\roman*~\color{sepcolor}|}}}
\setenumerate[3]{label={\color{itemcolor}\footnotesize\sffamily\textbf{\alph*~\color{sepcolor}|}}}
\begin{enumerate}
}{\end{enumerate}}

%% =============================================================================
%% Formatting
%% =============================================================================

\newcommand{\Emph}[1]{\underline{#1}}

