% Dennis Komm  2019-02-07
% Based on LaTex ETH Presentation Templates by Dieter Hennig and Karl Wuest

% Felix Friedrich 2019-09-02 
% made this a pure style file and moved all other definitions into slides.tex

% Adel Gavranovic 2024-08-28
% - adapted the underlines in \(sub)sectionframes{} to be at a consistent distance from the base of the text
% - added section name above subsection name in \subsectionframe

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{ifthen}
\usepackage{pgffor}

\usepackage[light,lining,sfdefault]{FiraSans}
\usefonttheme[onlymath]{serif} 


\usepackage[normalem]{ulem}
\usepackage{microtype}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage{bm}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{relsize}
\usepackage{tikz,datetime,textpos}
\usepackage{calc}
\usepackage{xspace}
\usepackage{booktabs}
\usepackage{array}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usepackage{dsfont}
\usepackage{pifont}

\usepackage{fancyvrb}
\usepackage{fontawesome}      % for nice icons

% COLORS

\definecolor{ETHblue}{RGB}{31,64,122}
\definecolor{ETHred}{rgb}{0.9,0,0}
\definecolor{ETHgreen}{RGB}{64,122,31}
\definecolor{lightorange}{RGB}{255,165,0}


\let\leftold\left
\let\rightold\right
\renewcommand{\left}{\mathopen{}\mathclose\bgroup\leftold}
\renewcommand{\right}{\aftergroup\egroup\rightold}


\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}


\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{itemize item}[square]
\setbeamertemplate{itemize subitem}[square]
\setbeamertemplate{itemize subsubitem}[triangle]

\setbeamercolor*{author}{fg=white}
\setbeamercolor*{placeanddate}{fg=white}
\setbeamercolor*{item}{fg=ETHblue}
\setbeamercolor*{subitem}{fg=ETHblue!70}
\alt<beamer>{\setbeamercolor*{frametitle}{fg=white,bg=ETHblue}}{\setbeamercolor*{frametitle}{fg=black,bg=white}}
\setbeamercolor*{section in toc}{fg=black}
\setbeamercolor*{section page}{fg=black}

% font weights
% \firathin
% \firaultralight
% \firaextralight
% \firalight
% \firabook
% \firamedium
% \firasemibold
% \firaextrabold
% \firaheavy

\renewcommand<>{\textmd}[1]{%
  \only#2{{\firamedium{#1}}}%
}
\renewcommand{\bf}{\firasemibold}


\setbeamerfont*{frametitle}{size=\Large,shape=\firabook}
\setbeamerfont{section page}{size=\Large}
\setbeamercolor{subtitle}{fg=black}
\setbeamerfont{title}{size=\firabook\LARGE}
\setbeamercolor{title}{fg=ETHblue}
\setbeamerfont{subtitle}{size=\mdseries\normalsize}
\setbeamerfont{author}{size=\small}
\setbeamerfont{placeanddate}{size=\footnotesize}
\setbeamerfont{text}{size=\normalsize,shape=\firalight}

\newenvironment{xplainframe}{\bgroup\begin{frame}[plain]}{\end{frame}\egroup}
\newcommand{\headline}[1]{\frametitle{\boldmath #1\unboldmath}}
\renewcommand{\cite}[2]{\hfill {\slshape [#1,\ #2]}\hspace*{-0.7mm}}
\newcommand{\citetwo}[4]{\hfill {\slshape [#1,\ #2;\ #3,\ #4]}\hspace*{-0.7mm}}

\newcommand*{\eth@barbreit}{\paperwidth-4mm}
\newcommand*{\eth@barhoch}{10.75mm}
\newcommand*{\eth@baruhh}{3.5mm}
\newcommand*{\eth@baruhb}{2.5mm}
\newcommand*{\eth@shiftx}{9.5mm-\paperwidth}
\newcommand*{\eth@shifty}{5.5mm-\paperheight}
\newcommand*{\anchorheight}{\the\paperheight-\eth@barhoch-2mm}
\newcommand*{\titleanchorheight}{7.5mm}

\pgfplotsset{
  every axis/.append style={font=\footnotesize},  
}

\newcommand*{\eth@hintergrundbreite}{\paperwidth-9mm}
\newcommand*{\eth@hintergrundhoehe}{0.5\paperheight-12mm}

\newcommand{\bfnum}[1]{{\boldmath\textcolor{ETHblue!70!black}{\bfseries #1}\unboldmath}}
\newcommand{\p}{\ding{239}}
\newcommand{\pg}{\p\ }
\newcommand{\bfblue}[1]{\textcolor{ETHblue}{\boldmath\textbf{#1}\unboldmath}}
\newcommand{\bfred}[1]{\textcolor{ETHred}{\boldmath\textbf{#1}\unboldmath}}
\newcommand{\bfgreen}[1]{\textcolor{ETHgreen}{\boldmath\textbf{#1}\unboldmath}}

\newcommand{\pictureat}[4][\empty]{%
  \begin{tikzpicture}[overlay,remember picture,shift={(current page.north west)},y=-1cm]%
    \node[align=left] at (#2) {\includegraphics[#3]{#4}%
    \ifthenelse{\equal{#1}{\empty}}{}{\\[-0.75em]\tiny #1}};%
  \end{tikzpicture}%
}

\newenvironment{overlaytikzpicture}{%
  \begin{tikzpicture}[overlay,remember picture,shift={(current page.north west)},y=-1cm]%
}{
  \end{tikzpicture}%
}

\defbeamertemplate*{background}{xplainframe}{}

\newcommand{\setdefaultbg}{
  \setbeamertemplate{background}[xplainframe]
}


\newcommand{\settitlebg}{
  \setbeamercolor*{title page header}{fg=white}
  \setbeamercolor*{title}{fg=white}
  \setbeamertemplate{background} {
    \begin{tikzpicture}
      \useasboundingbox (0,0) rectangle(\the\paperwidth,\the\paperheight);
      \node[shift={(-0.5\paperwidth,-\paperheight-20mm + \anchorheight)}]  at (current page.north east)
           {\includegraphics[width=\the\paperwidth-9mm]{bg_eth.jpeg}};  
      \hspace{2mm}\draw[ETHblue,fill=ETHblue] (0,\eth@barhoch + \anchorheight)--   %
          (\eth@barbreit,\eth@barhoch + \anchorheight)--(\eth@barbreit, \anchorheight)-- %
          (\eth@barbreit-\eth@baruhb, \anchorheight)-- (\eth@barbreit-\eth@baruhb,\eth@baruhh + \anchorheight) -- %
          (\eth@baruhb,\eth@baruhh + \anchorheight)--(\eth@baruhb, \anchorheight)-- (0, \anchorheight) -- %
          (0,\eth@barhoch + \anchorheight); %
      \hspace{2.5mm}\draw[ETHblue,fill=ETHblue]%
        (0,\eth@hintergrundhoehe+\titleanchorheight-0.4cm)--(\eth@hintergrundbreite,\eth@hintergrundhoehe+\titleanchorheight-0.4cm)%
        --(\eth@hintergrundbreite,\titleanchorheight)--(0,\titleanchorheight)--(0,\eth@hintergrundhoehe+\titleanchorheight); 
      % \node at (1.0,8.45) {\includegraphics[height=1cm]{eth.png}};
    \end{tikzpicture}
  }
}


% ------ frames ----------

\newcommand{\titleframe}{
  {\setbeamertemplate{footline}{} 
  \settitlebg
  \frame{\maketitle}}
  \addtocounter{framenumber}{-1}
  \setdefaultbg
}

\newcommand{\partframe}[2][\empty]{
  {\setbeamertemplate{footline}{}
  \begin{frame}
    \addtocounter{framenumber}{-1}
    \vfill
    \begin{center}
      \LARGE\bfseries\boldmath\color{ETHblue} #2 \unboldmath
      \ifthenelse{\equal{#1}{\empty}}{}{%
        \\
        \Large\bfseries\boldmath\color{ETHblue!60} #1 \unboldmath
      }
    \end{center}
    \vfill
  \end{frame}}
}

\newcommand{\thanksframe}[1]{
  \ifthenelse{\equal{\multiSlides}{1}}{}{%
    {\setbeamertemplate{footline}{}
    \begin{frame}
      \addtocounter{framenumber}{-1}
      \vfill
      \begin{center}
        \LARGE\bfseries\boldmath\color{ETHblue} #1 \unboldmath
      \end{center}
      \vfill
    \end{frame}}%
  }
}

%a section frame: displays current section name plus some subcaption as separate slide
\newcommand{\sectionframe}[1]
{{
\setbeamercolor*{frametitle}{fg=normal text.fg, bg=normal text.bg} % set bg to green (or so) when adjusting..
\begin{frame}[c]
%    \begin{center}
    \usebeamerfont*{title}
    \usebeamercolor*[fg]{title}
    \begin{minipage}[t][3ex][b]{\textwidth} % section title minipage
    {\small~}\\
    \LARGE \arabic{section}. \insertsection\vspace{-8pt}\\
    \rule{\textwidth}{2pt}
    \end{minipage}
    \usebeamerfont*{subtitle}
    \usebeamercolor*[fg]{subtitle}
    \raggedright \normalsize
    #1
%    \end{center}
\end{frame}
}}

\newcommand{\subsectionframe}[1]
{{
\setbeamercolor*{frametitle}{fg=normal text.fg, bg=normal text.bg} % set bg to green (or so) when adjusting..
\begin{frame}[c]
    %\begin{center}
    \usebeamerfont*{title}
    \usebeamercolor*[fg]{title}
    \begin{minipage}[t][3ex][b]{\textwidth} % section title minipage
    {\small\color{ETHblue!70}\arabic{section}. \insertsection}\vspace{2pt}\\
    \Large \arabic{section}.\arabic{subsection}. \insertsubsection\vspace{-8pt}\\
    \rule{\textwidth}{1pt}
    \end{minipage}
    \usebeamerfont*{subtitle}
    \usebeamercolor*[fg]{subtitle}
    \raggedright \normalsize
    \small #1
    %\end{center}
\end{frame}
}}


% ---------------- BOXES ------------------
\alt<beamer>{\colorlet{lboxTitleBg}{ETHblue}}{\colorlet{lboxTitleBg}{ETHblue!20}}
\alt<beamer>{\colorlet{lboxTitleFg}{white}}{\colorlet{lboxTitleFg}{black}}
\alt<beamer>{\colorlet{lboxBg}{ETHblue!30}}{\colorlet{lboxBg}{ETHblue!10}}
\colorlet{lboxFg}{black}

\newcommand*{\lboxOuterSkip}{0.2cm}
\newcommand*{\lboxInnerSkip}{0.2cm}

\newenvironment{lbox}[1][]{
  \setbeamercolor*{item}{fg=lboxTitleBg}
  \setbeamercolor*{subitem}{fg=lboxTitleBg}
  \renewcommand{\bfnum}[1]{\textcolor{lboxFg}{\bfseries ##1}}
  \ifthenelse{\equal{#1}{\empty}}{
	  \begin{mdframed}[
      linewidth=0px,
      backgroundcolor=lboxBg,
      skipabove=\lboxOuterSkip,
      skipbelow=\lboxOuterSkip,
      innertopmargin=\lboxInnerSkip,
      innerbottommargin=\lboxInnerSkip
    ]%
  }{%
    \begin{mdframed}[
      linewidth=0px,
      backgroundcolor=lboxTitleBg,
      skipabove=\lboxOuterSkip,
      skipbelow=\lboxOuterSkip
    ]%
     \color{lboxTitleFg}%
     #1%
    \end{mdframed}%\vspace{-0.35cm}
	  \begin{mdframed}[
      linewidth=0px,
      backgroundcolor=lboxBg,
      skipabove=0pt,
      skipbelow=\lboxOuterSkip,
      innertopmargin=\lboxInnerSkip,
      innerbottommargin=\lboxInnerSkip
    ]%
  }%
}{%
  \end{mdframed}%
}

\newenvironment{lbox*}[1][]{
  \renewcommand*{\lboxInnerSkip}{0.0cm}
  \begin{lbox}[#1]%
}{%
  \end{lbox}%
}

\alt<beamer>{\colorlet{thmboxTitleBg}{black!60}}{\colorlet{thmboxTitleBg}{black!20}}
\alt<beamer>{\colorlet{thmboxTitleFg}{white}}{\colorlet{thmboxTitleFg}{black}}
\alt<beamer>{\colorlet{thmboxBg}{black!10}}{\colorlet{thmboxBg}{black!10}}

\newcommand*{\thmboxOuterSkip}{0.2cm}
\newcommand*{\thmboxInnerSkip}{0.2cm}

\newenvironment{thmbox}[1][]{
  \setbeamercolor*{item}{fg=thmboxTitleBg}
  \setbeamercolor*{subitem}{fg=thmboxTitleBg}
  \renewcommand{\bfnum}[1]{\textcolor{thmboxTitleBg}{\bfseries ##1}}
  \ifthenelse{\equal{#1}{\empty}}{
	  \begin{mdframed}[
      linewidth=0px,
      backgroundcolor=thmboxBg,
      skipabove=\thmboxOuterSkip,
      skipbelow=\thmboxOuterSkip,
      innertopmargin=\thmboxInnerSkip,
      innerbottommargin=\thmboxInnerSkip
    ]%
  }{%
    \begin{mdframed}[
      linewidth=0px,
      backgroundcolor=thmboxTitleBg,
      skipabove=\thmboxOuterSkip,
      skipbelow=\thmboxOuterSkip
    ]%
     \color{thmboxTitleFg}%
     #1%
    \end{mdframed}%\vspace{-0.35cm}
	  \begin{mdframed}[
      linewidth=0px,
      backgroundcolor=thmboxBg,
      skipabove=0pt,
      skipbelow=\thmboxOuterSkip,
      innertopmargin=\thmboxInnerSkip,
      innerbottommargin=\thmboxInnerSkip
    ]%
  }%
}{%
  \end{mdframed}%
  
}

\newenvironment{thmbox*}[1][]{
  \renewcommand*{\thmboxInnerSkip}{0.0cm}
  \begin{thmbox}[#1]%
}{%
  \end{thmbox}%
}



\makeatletter
\setbeamertemplate{theorem begin}
{%
	\begin{thmbox}[\inserttheoremname \inserttheoremnumber]
     \usebeamerfont{text}
}%
\setbeamertemplate{theorem end}{\end{thmbox}}
\makeatother

\alt<beamer>{\colorlet{alertboxTitleBg}{ETHred!70!black}}{\colorlet{alertboxTitleBg}{ETHred!20}}
\alt<beamer>{\colorlet{alertboxTitleFg}{white}}{\colorlet{alertboxTitleFg}{black}}
\alt<beamer>{\colorlet{alertboxBg}{ETHred!20}}{\colorlet{alertboxBg}{ETHred!10}}
%% TODO: Use alertboxOuterSkip/alertboxInnerSkip also for our other boxes (lbox, alertbox)
\newcommand*{\alertboxOuterSkip}{0.2cm}
\newcommand*{\alertboxInnerSkip}{0.2cm}
\newenvironment{alertbox}[1][]{
  \setbeamercolor*{item}{fg=alertboxTitleBg}
  \setbeamercolor*{subitem}{fg=alertboxTitleBg}
  \renewcommand{\bfnum}[1]{\textcolor{alertboxTitleBg}{\bfseries ##1}}
  \ifthenelse{\equal{#1}{\empty}}{
	  \begin{mdframed}[
      linewidth=0px,
      backgroundcolor=alertboxBg,
      skipabove=\alertboxOuterSkip,
      skipbelow=\alertboxOuterSkip,
      innertopmargin=\alertboxInnerSkip,
      innerbottommargin=\alertboxInnerSkip
    ]%
  }{%
    \begin{mdframed}[
      linewidth=0px,
      backgroundcolor=alertboxTitleBg,
      skipabove=\alertboxOuterSkip,
      skipbelow=\alertboxOuterSkip
    ]%
     \color{alertboxTitleFg}%
     #1%
    \end{mdframed}%\vspace{-0.35cm}
	  \begin{mdframed}[
      linewidth=0px,
      backgroundcolor=alertboxBg,
      skipabove=0pt,
      skipbelow=\alertboxOuterSkip,
      innertopmargin=\alertboxInnerSkip,
      innerbottommargin=\alertboxInnerSkip
    ]%
  }%
}{%
  \end{mdframed}%
}

\newenvironment{alertbox*}[1][]{
  \renewcommand*{\alertboxInnerSkip}{0.0cm}
  \begin{alertbox}[#1]%
}{%
  \end{alertbox}%
}


\alt<beamer>{\colorlet{exampleboxTitleBg}{ETHgreen!80!black}}{\colorlet{exampleboxTitleBg}{ETHgreen!20}}
\alt<beamer>{\colorlet{exampleboxTitleFg}{white}}{\colorlet{exampleboxTitleFg}{black}}
\alt<beamer>{\colorlet{exampleboxBg}{ETHgreen!20}}{\colorlet{exampleboxBg}{ETHgreen!10}}
%% TODO: Use exampleboxOuterSkip/exampleboxInnerSkip also for our other boxes (lbox, alertbox)
\newcommand*{\exampleboxOuterSkip}{0.2cm}
\newcommand*{\exampleboxInnerSkip}{0.2cm}
\newenvironment{examplebox}[1][]{
  \setbeamercolor*{item}{fg=exampleboxTitleBg}
  \setbeamercolor*{subitem}{fg=exampleboxTitleBg}
  \renewcommand{\bfnum}[1]{\textcolor{ETHgreen!70!black}{\bfseries ##1}}
  \ifthenelse{\equal{#1}{\empty}}{
	  \begin{mdframed}[
      linewidth=0px,
      backgroundcolor=exampleboxBg,
      skipabove=\exampleboxOuterSkip,
      skipbelow=\exampleboxOuterSkip,
      innertopmargin=\exampleboxInnerSkip,
      innerbottommargin=\exampleboxInnerSkip
    ]%
  }{%
    \begin{mdframed}[
      linewidth=0px,
      backgroundcolor=exampleboxTitleBg,
      skipabove=\exampleboxOuterSkip,
      skipbelow=\exampleboxOuterSkip
    ]%
     \color{exampleboxTitleFg}%
     #1%
    \end{mdframed}%\vspace{-0.35cm}
	  \begin{mdframed}[
      linewidth=0px,
      backgroundcolor=exampleboxBg,
      skipabove=0pt,
      skipbelow=\exampleboxOuterSkip,
      innertopmargin=\exampleboxInnerSkip,
      innerbottommargin=\exampleboxInnerSkip
    ]%
  }%
}{%
  \end{mdframed}%
}

\newenvironment{examplebox*}[1][]{
  \renewcommand*{\exampleboxInnerSkip}{0.0cm}
  \begin{examplebox}[#1]%
}{%
  \end{examplebox}%
}

\newcommand{\frameheight}{\textheight}

\newcommand{\cright}[1]{\\[-8pt]\textcolor{black!70}{\scalebox{0.4}{#1}}}

\setbeamertemplate{title page}{
  \setbeamertemplate{background}[title page]
  \begin{textblock*}{\textwidth}(-0.3cm,2.0cm)
    \begin{beamercolorbox}{title page header}
      \begin{beamercolorbox}{author}
        \usebeamerfont{author}\insertauthor\\[-1.4mm]%
      \end{beamercolorbox}
      \usebeamerfont{title}\usebeamercolor{title}\inserttitle\\[1mm]%
      \usebeamerfont{subtitle}\insertsubtitle\\[1mm]%
    \end{beamercolorbox}%
    
    \begin{beamercolorbox}{placeanddate}
      \usebeamerfont{placeanddate}\insertdate%
    \end{beamercolorbox}
  \end{textblock*}
}

\setbeamertemplate{frametitle}{
  \vspace*{-0.5mm}
  \begin{beamercolorbox}[wd=\paperwidth, ht=0.85cm, dp=0.4cm]{frametitle}
	%\vspace{-1.6em}
	\centerline{
	\begin{minipage}{\textwidth}
	\strut\insertframetitle\strut
    %% Using \strut prevents jumpy frame titles when (not) having ascender/descender letters.
    %% See also https://bloerg.net/2012/06/21/customizing-the-frametitle-of-beamer-presentation.html.
	\end{minipage}
	}
    %\centerline{\insertframetitle}
  \end{beamercolorbox}
}

\setbeamertemplate{footline}{
  \leavevmode%
  \hbox{%
  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.5ex,dp=3ex,left]{fg=black,bg=white}%
    \hspace{4.5mm}\insertshorttitle\  \insertshortsubtitle%
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.25\paperwidth,ht=2.5ex,dp=3ex,left]{fg=black,bg=white}%
    \centering \usebeamerfont{author in head/foot}%\insertshortdate
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.15\paperwidth,ht=2.5ex,dp=3ex,left]{fg=black,bg=white}%
    \centering \insertshortauthor
  \end{beamercolorbox}%
  \begin{beamercolorbox}[wd=.1\paperwidth,ht=2.5ex,dp=2ex,right]{fg=black,bg=white}%
    \raggedleft \insertframenumber%\,/\,\inserttotalframenumber
    \hspace*{4.5mm}
  \end{beamercolorbox}}%
  \vskip0pt%
}


\endinput