% -*- coding: utf-8; -*-
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+
%                                                                                                  |
% (C)opyright A. Hilbig, mail@andrehilbig.de                                                       |
%             http://www.andrehilbig.de/Publications                                               |
%                                                                                                  | 
% diese Datei: ahilbig-script.sty                                                                  |
%                                                                                                  |
% Das Dokument steht unter der Lizenz: Creative Commons by-nc-sa Version 4.0                       |
% http://creativecommons.org/licenses/by-nc-sa/4.0/deed.de                                         |
%                                                                                                  |
% Nach dieser Lizenz darf das Dokument beliebig kopiert und bearbeitet werden,                     |
% sofern das Folgeprodukt wiederum unter gleichen Lizenzbedingungen vertrieben                     |
% und auf die ursprünglichen Urheber verwiesen wird.                                               |
% Eine kommerzielle Nutzung ist ausdrücklich ausgeschlossen.                                       |
%                                                                                                  |
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+
%                                                                                                  |
% HINWEISE/ERWEITERUNG                                                                             |
% Diese Pakete basieren auf den entsprechenden Paketen von Prof. Dr. Ludger Humbert                |
% (http://ddi.uni-wuppertal.de/ -- humbert@uni-wuppertal.de) und wurden zum Teil angepasst. Seine  |
% Pakete basieren wiederum auf Entwicklungen von Prof. Dr. Till Tantau                             |
% (http://www.tcs.uni-luebeck.de/de/mitarbeiter/tantau/). Beiden gilt mein Dank hierfür.           |
%                                                                                                  |
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+
%                                                                                                  |

\ProvidesPackage{ahilbig-script}

\newif\ifcmmath
\DeclareOption{cmmath}{\cmmathtrue}
\newif\ifonelecture
\DeclareOption{onelecture}{\onelecturetrue}
\newif\ifgitinfo
\DeclareOption{gitinfo}{\gitinfotrue}
\ProcessOptions

%\RequirePackage{caption}
%\RequirePackage{minitoc}
%\RequirePackage[draft]{ddi-common}
%\RequirePackage[blackandwhite]{ddi-common}
%\RequirePackage[cd]{ddi-common}
	\RequirePackage{ahilbig-common}

\RequirePackage{ahilbig-semester}

%\RequirePackage[height=5cm,keepaspectratio,digitcolor=white,
%	backgroundcolor=none]{ddiLogo} % benutzt in Zeile 388

%\RequirePackage{chapterbib}

\RequirePackage{graphicx}
\RequirePackage{pifont}
\RequirePackage{ahilbig-comics}
\RequirePackage{wrapfig}
\RequirePackage{smartdiagram}
\RequirePackage{pdflscape}
\RequirePackage{placeins}


\RequirePackage{varsfromjobname} % Element[e] aus \jobname extrahieren
%\RequirePackage{qrcode}          % Wird in maintitle genutzt - auskommentiert

%\RequirePackage{pdfpages}

% Default lecture
\providecommand\insertshortlecture{0}
\providecommand\insertlecture{Vortrag}
\providecommand\lecturename{Vortragtitel}

\ifgitinfo
	\RequirePackage{gitinfo2}
	\providecommand\versionsinfo{%
		%Gitinfo -- \gitAbbrevHash in \gitBranch von (\gitAuthorEmail) am \gitAuthorDate
			Versionsinformationen:

   		\begin{tabular}{ll}
				\textcolor{blue!70}{Hash:}										& \textcolor{blue!45}{\gitAbbrevHash}										\\
				\textcolor{blue!70}{Branch:}									& \textcolor{blue!45}{\gitBranch}												\\
				\textcolor{blue!70}{Stand:}										& \textcolor{blue!45}{\gitAuthorIsoDate}								\\
				\textcolor{blue!70}{Zuletzt bearbeitet von:}	& \textcolor{blue!45}{\gitAuthorName\ (\gitAuthorEmail)}\\
   		\end{tabular}
	}
\else
	\providecomman\versionsinfo{}
\fi


\ifonelecture
	\RequirePackage{chngcntr}
	\counterwithout{figure}{chapter}
	\counterwithout{table}{chapter}
\fi

% Common packages
%
\usepackage{babel}
\mode<article>
{
  \usepackage[left=1.75cm,right=6.5cm,top=2.5cm,bottom=2cm,twoside,
  	a4paper]{geometry}
  \usepackage{fancyhdr}
  \setlength\columnsep{1.5cm}
}
%%\usepackage{hyperref}
\usepackage{calc}
\usepackage{tikz}
%\usepackage{yfonts}
\usepackage{translator}
\usepackage{amssymb}
\usetikzlibrary{scopes,backgrounds,positioning}

\usepackage[absolute]{textpos}
\usepackage{multimedia} 



\def\UrlFont{}

    
% Common settings for all lectures in this course

\title{\insertlecture}

% The body environment

\mode<article>{
  \parskip.5em plus 1pt minus 1pt
  \newenvironment{body}{\parskip=2pt plus 1pt minus 1pt}{}
}
\mode<presentation>{
  \newenvironment{body}{\document\ifcd\setbeamertemplate{sidebar
      right}{}\fi}{\enddocument}
%  \newcommand{\newblock}{}  
}


% Common theorem-like environments

\theoremstyle{definition}
\newtheorem{lectureexercise@}[theorem]{\translate{Zur Uebung}}
\newtheorem{discussion@}[theorem]{\translate{Zur Diskussion}}

\pgfkeys{/ddi/lines/.initial=0}
\pgfkeys{/ddi/border lines/.initial=4}
\pgfkeys{/ddi/name/.initial=}
\pgfkeys{/ddi/title/.style={/ddi/name=#1}}

\newenvironment{lecture exercise}[1][]{\pgfkeys{/ddi/.cd,#1}%
  \edef\marshal{\noexpand\lectureexercise@[\pgfkeysvalueof{/ddi/name}]}
  \marshal\ignorespaces}
{\endlectureexercise@
}

% \def\lineblock
% {%
%   %
%   \ifnum\pgfkeysvalueof{/ddi/border lines}>0\relax%
%   \only<article>{%
%     \setlength{\marginparsep}{.5cm}%
%     \setlength{\marginparwidth}{4cm}%
%     \marginpar{%
%       \color{black!35}
%       \edef\temp{1,...,\pgfkeysvalueof{/ddi/border lines}}
%       \foreach \i in \temp
%       {\ifnum\i>1\vskip1.5em\else\ding{46}\vskip2pt\fi\hrule width4cm height0.4pt}      
%       \vskip1.5em
%     }%
%   }%
%   \fi%
% }

\def\lineblock{\llap{\ding{46}\ \ }}

\newenvironment{discussion}[1][]{\pgfkeys{/ddi/.cd,#1}%
  \edef\marshal{\noexpand\discussion@[\pgfkeysvalueof{/ddi/name}]}
  \marshal\ignorespaces}
{\enddiscussion@
}


%
% New environments
%

\newdimen\gapskip
\gapskip=5cm

\newenvironment{presentation itemize}
{\alt<presentation>{\itemize}{\ddi@save@item\let\item=\relax\ignorespaces}}
{\alt<presentation>{\enditemize}{}}

\newenvironment{presentation enumerate}
{\alt<presentation>{\itemize}{\ddi@save@item\c@enumi=0\def\item{\advance\c@enumi
    by 1\relax\the\c@enumi.\ }\ignorespaces}}
{\alt<presentation>{\enditemize}{}}

\def\ddi@save@item{\ifx\ddi@reinstall@item\relax\let\orig@item=\item\def\ddi@reinstall@item{\let\item=\orig@item}\fi}

\let\ddi@reinstall@item\relax
\let\orig@list=\list
\def\list{\ddi@reinstall@item\orig@list}


%
% Special wide pages
 
\def\ddistartwidepages{
  \setlength\textwidth{\paperwidth-17.5mm-17.5mm}
  \setlength\oddsidemargin{17.5mm-1in}
  \setlength\evensidemargin{17.5mm-1in}
  \setlength\gapskip{0.25cm}
}
\newenvironment{wide pages}
{
  \begingroup
  \ddistartwidepages
  \onecolumn
}
{
  \clearpage
  \endgroup
  \onecolumn
}


% Learning targets and TOC

\mode<beamer>
{
\newenvironment{learning targets}
{
  \translatelet\temp{Kompetenzen}
%  \section*{\temp}
  \begin{frame}[fragile=singleslide]{\translate{Kompetenzen -- 
  	Seminar}~\insertshortlecture}
    \begin{enumerate}%\rightskip-1.5cm plus1fil
    }
  {
    \end{enumerate}
  \end{frame}
\begin{frame}{\translate{Gliederung -- Vortrag}~\insertshortlecture}
  \tableofcontents
\end{frame}
\aftergroup\setupsidebar
}
}

\mode<article>
{
  \newcommand\maintableofcontents{{%
      \parskip0pt%
%  \addvspace{3em \@plus\p@}%
%  \avoidwiddow{2.5cm}{500}
      \tableofcontents
    }}
\renewcommand*\l@part[2]{%
  \addpenalty{-\@highpenalty}%
  \addvspace{5em \@plus\p@}%
  \avoidwiddow{3cm}{750}
  \setlength\@tempdima{4em}%
  \begingroup
    \parindent \z@
    \leavevmode
    \raggedright
    \leftskip0em%
    \Large\sffamily
    \long\def\numberline##1{{\fontsize{20pt}{24pt}\selectfont%
    	\textcolor{structure.fg}{##1}\par}\leavevmode}%
    #1
    \par
  \endgroup
}
\renewcommand*\l@chapter[2]{%
  \addvspace{3em \@plus\p@}%
  \avoidwiddow{2.5cm}{500}
  \@tempdima=4em%
    \begingroup
      \parindent \z@
      \leavevmode
      \raggedright
      \advance\leftskip4em
      \hskip -4em
      {\Large\color{black} \textsf{#1}\par}
    \endgroup
  }
\renewcommand*\l@section[2]{%
  \addvspace{1.0em \@plus\p@}%
  \avoidwiddow{2cm}{200}
  \@tempdima=4em%
    \begingroup
      \parindent \z@
      \leavevmode
      \rightskip\@pnumwidth plus1fil
      \advance\leftskip4em
      \hskip -4em
      {\small\color{structure.fg} \textsf{#1}}
%      \ifmicrotoc
%      \else
      \nobreak\normalsize\normalfont
     \hfill
     \nobreak
     \rlap{\hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #2}}%
%     \fi
      \par
    \endgroup
  }
\def\subsectionnumberline#1{\hb@xt@\@tempdima{\small\sffamily#1\hfil}}

\renewcommand*\l@subsection[2]{\@tempdima=4em%
    \begingroup
      \parindent \z@
      \leavevmode
      \advance\leftskip4em
      \rightskip\@pnumwidth plus1fil
      \hskip -4em
      \let\numberline\subsectionnumberline
      #1
%     \ifmicrotoc
%      \else
      \nobreak\normalsize\normalfont
     \leaders\hbox{$\m@th
       \mkern \@dotsep mu\hbox{.}\mkern \@dotsep
       mu$}\hfill
     \nobreak
     \rlap{\hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor #2}}%
%     \fi
      \par
    \endgroup}
\let\l@chapterstar\l@subsection  
\def\toclevel@chapterstar{1}
\renewcommand*\l@subsubsection[2]{}
\NewDocumentEnvironment{learning targets}{o}
{
  \begin{frame}
    \ifodd\c@page%
    \else%
    \hskip-4.75cm
    \fi
  \noindent
	\IfNoValueTF{#1}{
		\begin{minipage}[t]{8cm}
	}{
		\begin{minipage}[t]{16cm}
		\begin{multicols}{2}
	}
    \section*{\textcolor{structure.fg}{\translate{Vortrag -- Kompetenzen}}}
    \medskip
    \begin{enumerate}
      \raggedright
}
{
  \end{enumerate}
	\IfNoValueTF{#1}{
	 \end{minipage}
	}{}
	\qquad\textcolor{gray}{\vrule width.4pt}\qquad
	%\rlap{
	\IfNoValueTF{#1}{
   \begin{minipage}[t]{8cm}
	}{}
    \section*{\textcolor{structure.fg}{\translate{Inhalte dieses Vortrags}}}
    \raggedright
		%\minitoc
		\the\microtoc%
	\IfNoValueTF{#1}{
   \end{minipage}
	}{
	 \end{multicols}
 	 \end{minipage}
	}
\vskip2em
    \refstepcounter{framenumber}%
  \end{frame}
}
}


% Microtocs

\mode<article>
{
\def\chaptertext{chapter}
\def\chapterstartext{chapterstar}
\def\parttext{part}
\newtoks\microtoc
\newif\ifmicrotoc
{
  \def\contentsline#1#2#3#4{%
    \extractchapter{#1}{#2}{#3}{#4}#4..\relax%
  }
  \def\extractchapter#1#2#3#4#5.#6.#7\relax{%
    \def\test{#1}%
    \ifx\test\chaptertext%
    \else%
    \ifx\test\chapterstartext%
      \else%
        \ifx\test\parttext%
        \else%
        \expandafter\global\expandafter\microtoc\expandafter{%
								\the\microtoc\filteredcontentsline{#1}{#2}{#3}{#4}{#5}{#6}
				}
        \fi%
      \fi%
    \fi%
  }
  \@input{\jobname.toc}
}

\newcommand\filteredcontentsline[6]{%
  {
    \microtoctrue
    \ifnum#6=\c@chapter\relax%
			\ifthenelse{\equal{#5}{section}}{
      	\contentsline{#1}{#2}{#3}{#4}%
			}{}
    \fi%
    %\ifnum#5=\c@chapter\relax%
    %  \contentsline{#1}{#2}{#3}{#4}%
    %\fi%

  }
}
}

%NEU HILBIG
\newcommand*\addchap{\secdef\@addchap\@saddchap}
\newcommand*{\@addchap}{}
\def\@addchap[#1]#2{\chapterlikeheadline{#2}{}{}%
  \addcontentsline{toc}{chapter}{#1}%
  \if@twoside\ifx\@mkboth\markboth\markright{#1}\fi\fi
}
\newcommand*{\@saddchap}[1]{\chapterlikeheadline{#1}\@mkboth{}{}}

\newcommand*\addsec{\secdef\@addsec\@saddsec}
\newcommand*{\@addsec}{}
\def\@addsec[#1]#2{\section*{#2}\addcontentsline{toc}{section}{#1}
  \if@twoside\ifx\@mkboth\markboth\markright{#1}\fi\fi
}
\newcommand*{\@saddsec}[1]{\section*{#1}\@mkboth{}{}}

\newcommand*\addsubsec{\secdef\@addsubsec\@saddsubsec}
\newcommand*{\@addsubsec}{}
\def\@addsubsec[#1]#2{\subsection*{#2}\addcontentsline{toc}{subsection}{#1}
  \if@twoside\ifx\@mkboth\markboth\markright{#1}\fi\fi
}
\newcommand*{\@saddsubsec}[1]{\subsection*{#1}\@mkboth{}{}}
%ENDE NEU HILBIG

% Parts

\def\ddiparttext{part}

\def\part#1{%
  \clearpage
  \null\vskip4cm
  \refstepcounter{part}%
  \chapterstarmark{\partname\ \thepart}{#1}
  \addcontentsline{toc}{part}{\protect\numberline{\partname\ \thepart}#1}%
  \interlinepenalty \@M
  \normalfont{\raggedright
  \sffamily
  {\fontsize{36pt}{40pt}\selectfont{ \color{structure.fg} \partname\ 
  	 \thepart}\par
    \fontsize{24pt}{30pt}\selectfont#1\par}}
  \vskip2em
  \ifx\@currenvir\ddiparttext
    \parskip.75em plus 1pt minus 1pt
  \else
  \endpart
  \fi
}
\def\endpart{
  \clearpage%
}


% Table of Contents

\mode<article>
{
	\newcommand\printTables{
  	\ddistartwidepages
    \begin{wide pages}
			\tableofcontents

			\listoffigures

			\listoftables
		\end{wide pages}
	}
  \renewcommand\tableofcontents{%
      \chapterstarmark{\contentsname}{}
			\vskip2cm
      {\fontsize{36pt}{40pt} \sffamily\hilight{\contentsname}}\par
			\vskip2cm
			\begin{multicols}{2}
	      \@starttoc{toc}%
			\end{multicols}
    }
	\renewcommand\listoffigures{
      \chapterstarmark{\listfigurename}{}
			\vskip2cm
			{\fontsize{36pt}{40pt} \sffamily\hilight{\listfigurename}}\par
			\vskip2cm
			\begin{multicols}{2}
	      \@starttoc{lof}%
			\end{multicols}
	}
	\renewcommand\listoftables{
      \chapterstarmark{\listtablename}{}
			\vskip2cm
			{\fontsize{36pt}{40pt} \sffamily\hilight{\listtablename}}\par
			\vskip2cm
			\begin{multicols}{2}
	      \@starttoc{lot}%
			\end{multicols}
	}
}


% List of proof methods

\newcommand\listofproofmethods{%
  \begin{wide pages}
  \parskip0pt%
  \chapterstarmark{Verzeichnis der Rezepte}{}
  \twocolumn[
  \vskip2cm
  {\fontsize{36pt}{40pt} \sffamily\hilight{Verzeichnis der Rezepte\par}}
  \vskip1cm]
  \@starttoc{lop}%
  \end{wide pages}
}

\newcommand\listofproofmethodsinline{%
  {
    \parskip0pt
    \@starttoc{lop}%
  }
}


% Discussion
\mode<article>
{
  \renewenvironment{lectureexercise@}[1][]{\begingroup
    \setlength{\marginparsep}{.5cm}%
    \setlength{\marginparwidth}{4cm}%
    \examplelike[#1]{\lineblock \translate{Zur Uebung}}}{
    \endexamplelike
    \endgroup}
  \renewenvironment{discussion@}[1][]{\begingroup
    \setlength{\marginparsep}{.5cm}%
    \setlength{\marginparwidth}{4cm}%
    \examplelike[#1]{\lineblock \translate{Zur Diskussion}}}{%
    	\endexamplelike\endgroup}
}

% Map

\newcommand\insertmap[1]{
  {
    \null
    \parskip0pt
    \setbox\mybox=\vbox{%
      \hsize=100cm\includegraphics[width=\paperheight-1.41cm,
      	height=\paperwidth-1cm,angle=90]{../map/#1-map.pdf}\hss%
    }
    \ht\mybox=0cm
    \wd\mybox=0cm
    \vskip-1.8cm
    \vskip-2.9\baselineskip
    \hbox{}
    \hskip-6cm
    \box\mybox
    \thispagestyle{empty}
    \clearpage
  }
}


% Summary

\newenvironment{summary}
{
  \only<article>{%
    \section*{\translate{Zusammenfassung dieses Vortrags}}
    \sectionstarmark{\translate{Zusammenfassung dieses Vortrags}}
  }
  \only<presentation>{
    \translatelet\temp{Zusammenfassung}
    \section*{\temp}
  }
  \begin{frame}[fragile,environment=summary]
    \frametitle<presentation>{\translate{Zusammenfassung}}
    \only<article>{\vskip-2.5\baselineskip\hbox{}}
}
{
  \end{frame}
}

\newenvironment<>{further reading}
{
  \mode<presentation>{\vfill}
  \def\refname{\translate{Zum Weiterlesen}}
  \actionenv#1
  \begin{thebibliography}{10}
    \setbeamertemplate{bibliography item}[book]
}
{
\end{thebibliography}
\endactionenv
}

\newenvironment{bibitem comments}
{
  \begin{onlyenv}<article>
    \par\medskip
    \small
}
{
  \par\medskip
  \end{onlyenv}
}


\newenvironment<>{summary item}[1]{\actionenv#2\block{\only<article>{%
	\ddibordericon{{\ddiborderpointer}}}#1}}{\endblock\endactionenv}

% Exercise frame

\newif\ifmulti

\pgfkeys{/ddi/minutes/.initial=5}
\pgfkeys{/ddi/multiple exercises/.is if=multi}

\newenvironment{exercise frame}[1][]
{
  \pgfkeys{/ddi/.cd,#1}
  \begin{frame}[fragile=singleslide]
    \frametitle<presentation>{\pgfkeysvalueof{/ddi/minutes}\ifmulti\translate{%
    	Minuten-Aufgaben}\else\translate{Minuten-Aufgabe}\fi}
    \only<article>{\vskip-2.5\baselineskip\hbox{}}%
    \ifmulti\else%
      \begin{lecture exercise}%
    \fi%
    \ignorespaces%    
}
{
    \ifmulti\else%
      \end{lecture exercise}%
    \fi%
  \end{frame}
}

\newenvironment{discussion frame}[1][]
{
  \pgfkeys{/ddi/.cd,#1}
  \begin{frame}[fragile=singleslide]
    \only<presentation>{\frametitle{\translate{Zur Diskussion}: 
    	\pgfkeysvalueof{/ddi/name}}\pgfkeys{/ddi/title=}}
    \only<article>{\vskip-2.5\baselineskip\hbox{}}%
    \only<article>{\begin{discussion}}%
    \ignorespaces%    
}
{
    \only<article>{\end{discussion}}%
  \end{frame}
}


% New frame numbering

\mode<article>{%
	\renewcommand\insertframenumber{%
		\ifonelecture
			Folie~\@arabic\c@framenumber%\ von \inserttotalframenumber
		\else
			\insertshortlecture-\@arabic\c@framenumber
		\fi
	}
}
\mode<presentation>{%
	\renewcommand\insertframenumber{%
		\ifonelecture
			\@arabic\c@framenumber\ von \inserttotalframenumber
		\else
			\beamer@shortlecturename-\@arabic\c@framenumber
		\fi
	}
}


% Beamer version theme settings

\useoutertheme[height=0pt,width=2cm,right]{sidebar}
\ifcd
\else
\usecolortheme{rose,sidebartab}
\useinnertheme{circles}
\fi

\definecolor{websitebg}{rgb}{0.8509,0.8509,0.8784}
\ifcd\else\setbeamercolor{sidebar right}{bg=websitebg}\fi
\setbeamercolor{structure}{fg=orange!80!red}
\ifcd
%  \setbeamercolor{sidebar right}{bg=oceangreen!3}
  \setbeamercolor{structure}{fg=oceangreen!65}
  \setbeamercolor{alerted text}{fg=oceangreen!50}
  \setbeamerfont{alerted text}{shape=\ifmmode\else\itshape\fi}
\fi
\setbeamercolor{author}{parent=structure}
\setbeamercolor{subtitle}{fg=black}

\ifcd
\setbeamerfont{title in sidebar}{size=\fontsize{6.5}{7}}
\setbeamerfont{chapter in sidebar}{size=\fontsize{6.5}{7}}
\setbeamerfont{slide in sidebar}{size=\fontsize{6.5}{7}}
\setbeamerfont{sidebar}{size=\fontsize{5}{5.25}}
\setbeamerfont{section in sidebar}{size=\fontsize{5}{5.5}}
\setbeamerfont{subsection in sidebar}{size=\fontsize{4.5}{5}}
\setbeamercolor{section in sidebar shaded}{use=section in sidebar,
	fg=section in sidebar.fg}
\setbeamercolor{subsection in sidebar shaded}{use=subsection in sidebar,
	fg=subsection in sidebar.fg}

\setbeamertemplate{subsection in sidebar}
{%
  \beamer@sidebarformat{3pt}{subsection in
    sidebar}{\leavevmode\llap{\fontsize{3.75}{3.75}%
    	\selectfont$\blacktriangleright$ }\insertsubsectionhead}%
}

\setbeamertemplate{subsection in sidebar shaded}
{%
  \beamer@sidebarformat{3pt}{subsection in sidebar shaded}{%
  	\insertsubsectionhead}%
}


\setbeamertemplate{section in sidebar}
{%
  \vbox{%
    \vskip.75em%
    \beamer@sidebarformat{3pt}{section in
      sidebar}{\leavevmode\llap{\fontsize{4.5}{5}\selectfont \insertshortlecture.\insertsectionheadnumber\
        \ }\insertsectionhead~{\color{black}\fontsize{3.75}{3.75}\selectfont$\blacktriangleleft$}}%
  }%
}

\setbeamertemplate{section in sidebar shaded}
{%
  \vbox{%
    \vskip.75em%
    \beamer@sidebarformat{3pt}{section in sidebar
      shaded}{\leavevmode\llap{\fontsize{4.5}{5}\selectfont\insertshortlecture.\insertsectionheadnumber\
        \ }\insertsectionhead~\phantom{{\fontsize{3.75}{3.75}\selectfont$\blacktriangleleft$}}}%
  }%
}


\else
\setbeamerfont{title in sidebar}{series=\bfseries}
\setbeamerfont{slide in sidebar}{size=\scriptsize}
\fi

\setbeamerfont{title}{series=\normalfont,size=\LARGE}
\setbeamerfont*{item}{series=}
\ifcd
\setbeamerfont{frametitle}{size=\large}
\setbeamerfont{info in title}{size=\scriptsize}
\setbeamercolor{info in title}{parent=structure}
\else
\setbeamerfont{frametitle}{size=}
\setbeamerfont{info in title}{size=\scriptsize}
\setbeamercolor{info in title}{parent=structure}
\fi
\ifcd\setbeamerfont{block title}{size=\normalsize}\else\setbeamerfont{block title}{size=\small}\fi
\setbeamerfont{subtitle}{size=\normalsize,series=\normalfont}

\setbeamerfont{subtitle}{size=\normalsize,series=\normalfont}

\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{bibliography item}[book]

\ifcd
\else
\pgfdeclarehorizontalshading{mytransition}{\the\paperheight}{color(0cm)=(white); color(1.5mm)=(websitebg)}

\setbeamertemplate{background canvas}
{\hskip\paperwidth\hskip-2.14cm\pgfuseshading{mytransition}}
\fi

\def\setupsidebar{
\setbeamertemplate{sidebar right}
{
  \ifcd
  {
    \vskip2.6em%
    \usebeamerfont{chapter in sidebar}%
    \hskip3pt%
  \translate{Seminar}~\insertshortlecture\par}
  \fi
  {\usebeamerfont{title in sidebar}%
    \ifcd\vskip1pt\else\vskip1.5em\fi%
    \hskip3pt%
    \usebeamercolor[fg]{title in sidebar}%
    \ifcd
    \insertshorttitle[width=2cm-6pt,left,respectlinebreaks]
    \else
    \insertshorttitle[width=2cm-6pt,center,respectlinebreaks]\fi\par%
\ifcd\vskip.75em\else    \vskip1.25em\fi
  }%
\ifcd\else  {%
    \hskip3pt%
    \usebeamercolor[fg]{author in sidebar}%
    \usebeamerfont{author in sidebar}%
    \ifcd
    \insertshortauthor[width=2cm-6pt,left,respectlinebreaks]
    \else
    \insertshortauthor[width=2cm-2pt,center,respectlinebreaks]\fi\par%
    \vskip1.25em%
  }\fi%
  \ifcd\else\hbox to2cm{\hss\insertlogo\hss}
  \vskip1.25em\fi%
  \insertverticalnavigation{2cm}%
  \ifcd\vskip2em\else\vfill\fi
  \hbox to 2cm{\hfill\normalfont\strut\usebeamerfont{slide in sidebar}\insertframenumber\hskip5pt}%
  \vskip3pt%
}%
}
\setupsidebar

\setbeamertemplate{title page}
{
  \vbox{}
	\ifcd\vskip-5mm\leavevmode\hbox{\hskip-3mm}%\includegraphics[scale=0.25]{hglion.pdf}}%
%  \hfill{}
%  \includegraphics[scale=0.25]{hglion.pdf}
\par
  \leftskip3mm\else
  \vskip1em\fi
  {\huge \translate{Seminar} \insertshortlecture\par}
  {\usebeamercolor[fg]{title}\usebeamerfont{title}\inserttitle\par}%
  \ifx\insertsubtitle\@empty%
  \else%
    \vskip0.25em%
    {\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}%
  \fi%     
  \vskip4pt\par
  {\usebeamerfont{info in title} \translate{Seminar}
    {\usebeamercolor[fg]{info in title}\lecturename} \hbox{\translate{vom}
      \insertdate}%
      \vfill
      \begin{tiny}
       \versionsinfo
      \end{tiny}
      \vfill
      \ifcd\hbox{\translate{ von}
      {\usebeamercolor[fg]{info in title}\insertauthor}}\fi}\par
  \ifcd\else\vskip6em
  {\usebeamercolor[fg]{author}\insertauthor}\par\fi
  \ifcd\vskip1em
  {\scalebox{2}{\hbox{\insertlogo}}}
  \vskip0pt plus1filll\else
  \insertinstitute\vskip1em\fi
}


\pgfdeclareimage[width=2cm]{logo}{../../planning/logo}
\logo{\pgfuseimage{logo}}
\ifcd

\setbeamertemplate{section in toc}
{\leavevmode\leftskip=3em\rlap{\hskip-3em\insertshortlecture.\inserttocsectionnumber}\inserttocsection\par}
\setbeamertemplate{subsection in toc}
{\leavevmode\leftskip=3em\rlap{\hskip-3em\insertshortlecture.\inserttocsectionnumber.\inserttocsubsectionnumber}\inserttocsubsection\par}
\else

\setbeamertemplate{enumerate item}
{
  \usebeamerfont*{item projected}%
  \usebeamercolor[bg]{item projected}%
  \begin{pgfpicture}{-.55em}{0ex}{.55em}{1em}
    \pgfpathcircle{\pgfpoint{0pt}{.33em}}{0.6em}
    \pgfusepath{fill}
    \pgftext[base]{\color{fg}\insertenumlabel}
  \end{pgfpicture}%
}

\setbeamertemplate{enumerate subitem}
{
  \usebeamerfont*{subitem projected}%
  \usebeamercolor[bg]{subitem projected}%
  \begin{pgfpicture}{-.55em}{0ex}{.55em}{1em}
    \pgfpathcircle{\pgfpoint{0pt}{.33em}}{0.6em}
    \pgfusepath{fill}
    \pgftext[base]{\color{fg}\insertsubenumlabel}
  \end{pgfpicture}%
}

\setbeamertemplate{enumerate subsubitem}
{
  \usebeamerfont*{subsubitem projected}%
  \usebeamercolor[bg]{subsubitem projected}%
  \begin{pgfpicture}{-.55em}{0ex}{.55em}{1em}
    \pgfpathcircle{\pgfpoint{0pt}{.33em}}{0.6em}
    \pgfusepath{fill}
    \pgftext[base]{\color{fg}\insertsubsubenumlabel}
  \end{pgfpicture}%
}


\setbeamertemplate{section in toc}
{\leavevmode\leftskip=1em%
  \llap{%
    \usebeamerfont*{section number projected}%
    \usebeamercolor{section number projected}%
    \begin{pgfpicture}{-.55em}{0ex}{.55em}{1em}
      \color{bg}
      \pgfpathcircle{\pgfpoint{0pt}{.33em}}{0.6em}
      \pgfusepath{fill}
      \pgftext[base]{\color{fg}\inserttocsectionnumber}
    \end{pgfpicture}\kern0.6em%
  }%
  \inserttocsection\par}
\fi

\alt<presentation>{
  \newenvironment{under construction}{}{}
}
{
\newenvironment{under construction}{
  \underconstructiontrue
  \marginpar{%
    \color{red}%
    \hrule width 1cm height 1.6pt%
    \vskip1pt
    \hrule width 1cm height .8pt%
    \vskip1pt
    \hrule width 1cm height .4pt%
    \vskip1pt
    \hbox to 1cm{\hss$\downarrow$\hss}
    \hbox to 1cm{\hss\scriptsize\sffamily\strut in Arbeit\hss}
  }
  \vskip1em
}
{
  \marginpar{%
    \color{red}%
    \hbox to 1cm{\hss$\uparrow$\hss}%
    \vskip1pt
    \hrule width 1cm height .4pt%
    \vskip1pt
    \hrule width 1cm height .8pt%
    \vskip1pt
    \hrule width 1cm height 1.6pt%
  }
  \vskip1em
  \global\underconstructionendedonthispagetrue%
}
}

% Article version layout settings

\mode<article>

\def\ddimarginmark#1{%
  % Put a mark on both sides (one will be correct...)
  \par\noindent\leavevmode%
  \llap{\textcolor{gray}{\ddiputinbox{#1}}\hskip\marginparsep}%
  \rlap{\hskip\textwidth\hskip\marginparsep\textcolor{gray}{\ddiputinbox{#1}}}%
}

\def\ddiputinbox#1{%
  \scriptsize\sffamily%
  \setbox\marginbox=\hbox to1cm{\hfil%
  \begin{minipage}[t]{1cm}%
    \leftskip0pt plus 1fill\relax%
    \rightskip0pt plus 1fill\relax%
    #1%
  \end{minipage}\hfil%
  }%
  \dp\marginbox=0pt%
  \box\marginbox%
}
\newbox\marginbox

\setbeamertemplate{frame begin}{%
  \def\@currentlabel{\insertframenumber}%
  \avoidwiddow{2cm}{150}%
  \par\vskip\medskipamount\penalty-100%
  \ddimarginmark{\insertframenumber}\ignorespaces%
}
\setbeamertemplate{frametitle}{%
  \unskip{%
    \raggedright%
    \normalsize\selectfont\noindent%
    \textsf{%
      \ifcd\color{structure.fg}\fi
      \insertframetitle%
      \ifx\insertframesubtitle\@empty%
      \else%
        \hfil\break\small\textcolor{structure.fg}{\insertframesubtitle}%
      \fi%
    }\par%
  }\noindent\expandafter\ignorespaces
}

\setbeamertemplate{frame end}{%
  \par
}
\setlength{\marginparwidth}{1cm}
\setlength{\marginparsep}{5cm}


\renewcommand\maketitle{
  \par
  \thispagestyle{onlypagenumber}
  \ifonelecture
		\addcontentsline{toc}{chapter}{\protect\textcolor{structure.fg}{\translate{Vortrag}} \insertlecture}
	\else
		\addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}\insertlecture}
	\fi
  \null
  \ifodd\c@page%
  \else%
  \leftskip-4.75cm
  \fi
  \chapterlikeheadline{\translate{Vortrag}%\insertshortlecture
		}{\insertlecture}{\insertsubtitle\newline\newline
  \begin{footnotesize}
   \versionsinfo 
  \end{footnotesize}
  }
}

%\renewenvironment{titlepage}{\clearpage\null}{\vfill\vfill\clearpage}
\renewenvironment{titlepage}{}{}
\newcommand\maintitle{
  \thispagestyle{empty}
  {%
    \rightskip-4cm plus 1fil\relax%
    \leftskip6.5mm\relax%
    \vskip-2.2cm
    \leavevmode\hbox{\hskip-1.2cm{}%\includegraphics[scale=0.35]{hglion.pdf}%
			\hskip4cm{}\scalebox{3.2}{}%\ddiLogo}%
\hskip5cm{}%\includegraphics[scale=0.4]{ddi_qr_url.pdf}
			}\vskip1cm
%      {\vskip-2.75cm{}\hskip16.5cm{}\qrcode[height=2.5cm]{http://ddi.uni-wuppertal.de/}}}\vskip1cm
    \sffamily
    {\fontsize{48pt}{48pt}\selectfont \translate{Skript} \par\vskip6pt}
    {\fontsize{36pt}{44pt}\selectfont \color{structure.fg}
      \lecturename\par\vskip8pt}
    {\fontsize{24pt}{28pt}\selectfont \color{black} \insertsemester\vskip6pt\par}
    {\normalsize Fassung vom \today}
    \vskip3em\par
    \large
    {\color{structure.fg}\@author}\par
		%\maintableofcontents 
  }
}


%\def\thesection{\insertshortlecture.\the\c@section}
%\def\thesubsection{\insertshortlecture.\the\c@section.\the\c@subsection}

\def\sectionmarktext#1{%
  \typesetheadlinemain{%
    %\hbox to3em{\ \ \insertshortlecture\hss}\quad\insertlecture\\[1pt]%
    %\hbox to3em{\ \ \thesection\hss}\quad#1%
    \hbox to3em{\ \ \hss}\quad\insertlecture\\[1pt]%
    \hbox to3em{\ \ \thesection\hss}\quad#1%
  }%
}

\def\sectionstarmarktext#1{%
  \typesetheadlinemain{%
   % \hbox to3em{\ \ \insertshortlecture\hss}\quad\insertlecture\\[1pt]%
   % \hbox to3em{\ \ \hss}\quad#1%
    \hbox to3em{\ \ \hss}\quad\insertlecture\\[1pt]%
    \hbox to3em{\ \ \hss}\quad#1%
  }%
}

\def\chapterstarmarktext#1#2{%
  \typesetheadlinemain{%
    \quad#1\\[1pt]%
    \hbox{}\quad#2%
  }%
}

\def\sectionmark#1{%
  \markboth{\noexpand\sectionmarktext{#1}}{\noexpand\sectionmarktext{#1}}%
}

\def\sectionstarmark#1{%
  \markboth{\noexpand\sectionstarmarktext{#1}}{\noexpand\sectionstarmarktext{#1}}%
}

\def\chapterstarmark#1#2{%
  \markboth{\noexpand\chapterstarmarktext{#1}{#2}}{\noexpand\chapterstarmarktext{#1}{#2}}%
}

\def\ps@onlypagenumber{
  \def\@oddhead{\rightbgbar{4.6cm}\setupheadcolor\typesetheadlinemain{\hbox to3em{\ \
        \insertshortlecture\hss}\quad\insertlecture\\}%
    \hfill\oddouterborder}
  \def\@evenhead{\leftbgbar{4.6cm}\setupheadcolor\evenouterborder\typesetheadlinemain{\hbox to3em{\ \ \insertshortlecture\hss}\quad\insertlecture\\}}
}

\def\@oddfoot{}
\def\@evenfoot{}

\newif\ifunderconstruction
\newif\ifunderconstructionendedonthispage




\def\typesetheadlinemain#1{%
  \smash{%
    \sffamily\normalsize%
    \fboxsep=3pt%
    \colorbox{head.bg}{\vrule height15pt depth1pt width0pt%
      \smash{\hbox to \textwidth{%
        \hss{%
          \fontsize{7}{8}\selectfont%
          \hsize=\textwidth
          \vbox{%
            \textcolor{white}{#1}
          }%
        }%
      }}\hskip-6pt}}%
}

\def\typesetpagenumber{%
  \hbox to1cm{%
    \sffamily\normalsize%
    \hss%
    \fboxsep=3pt%
    \colorbox{head.bg}{%
      \vrule height15pt depth1pt width0pt%
      \raise4pt\hbox to 16pt{\hss\textcolor{white}{\thepage}\hss}}%
    \hss%
  }%
}

\def\setupheadcolor{%
  \ifunderconstruction\colorlet{head.bg}{red}\fi%
  \ifunderconstructionendedonthispage\colorlet{head.bg}{red}\fi%
  \global\underconstructionendedonthispagefalse%
}

\def\oddouterborder{\smash{\rlap{\rlap{\hskip-3pt\hskip2em\copy\fancypicturebox}\hskip\gapskip\typesetpagenumber}}}
\def\evenouterborder{\smash{\llap{\typesetpagenumber\hskip\gapskip\llap{\copy\fancypicturebox\hskip2em}}}}

\def\@oddhead{\rightbgbar{0pt}\setupheadcolor\rightmark\hfill\oddouterborder}
\def\@evenhead{\leftbgbar{0pt}\setupheadcolor\evenouterborder\leftmark}

\newdimen\extraheight
\extraheight=\paperheight
\advance\extraheight by 2cm

\pgfdeclarehorizontalshading{bgleft}{\extraheight}{color(0pt)=(black95); color(4pt)=(white)}
\pgfdeclarehorizontalshading{bgright}{\extraheight}{color(0pt)=(white);  color(4pt)=(black95)}


\def\leftbgbar#1{%
  \llap{%
    \setbox\mybox=\hbox{%
      \textcolor{black95}{\vrule width 7cm height \extraheight}%
      \pgfuseshading{bgleft}\hskip1em\hskip-2pt\hskip#1%
    }%
    \ht\mybox=0pt%
    \dp\mybox=0pt%
    \hbox{\vbox{\vskip\paperheight\vskip-1cm\box\mybox\vskip-\paperheight\vskip1cm}}%
  }%
  \rlap{%
    \hskip\textwidth%    
    \setbox\mybox=\hbox{%
      \hskip1em\hskip-2pt%
      \pgfuseshading{bgright}%
      \textcolor{black95}{\vrule width 2cm height \extraheight}%
    }%
    \ht\mybox=0pt%
    \dp\mybox=0pt%
    \hbox{\vbox{\vskip\paperheight\vskip-1cm\box\mybox\vskip-\paperheight\vskip1cm}}%
  }%
}


\def\rightbgbar#1{%
  \llap{%
    \setbox\mybox=\hbox{%
      \textcolor{black90}{\vrule width 2cm height \extraheight}%
      \pgfuseshading{bgleft}\hskip1em\hskip-2pt%
    }%
    \ht\mybox=0pt%
    \dp\mybox=0pt%
    \hbox{\vbox{\vskip\paperheight\vskip-1cm\box\mybox\vskip-\paperheight\vskip1cm}}%
  }%
  \rlap{%
    \hskip\textwidth%    
    \setbox\mybox=\hbox{%
      \hskip#1\hskip1em\hskip-2pt%
      \pgfuseshading{bgright}%
      \textcolor{black90}{\vrule width 7cm height \extraheight}%
    }%
    \ht\mybox=0pt%
    \dp\mybox=0pt%
    \hbox{\vbox{\vskip\paperheight\vskip-1cm\box\mybox\vskip-\paperheight\vskip1cm}}%
  }%
}

% Cannot print this:
\def\leftbgbar#1{}
\def\rightbgbar#1{}

\def\insertsubtitle{}

\newenvironment{frontmatter}
{
  \pagenumbering{roman}
}
{
  \cleardoublepage
  \pagenumbering{arabic}
}


% Fancy mini pictures

\newbox\fancypicturebox
\newcommand\fancypictures[1]{%
  \global\setbox\fancypicturebox=\hbox{#1}}

\let\ddi@fancy@other@option=\@empty
\let\ddi@fancy@filename=\@empty
\def\ddi@fancy@view@lx{0}
\def\ddi@fancy@view@ly{0}
\def\ddi@fancy@view@ux{25}
\def\ddi@fancy@view@uy{25}
\newif\ifddi@fancy@size@set

\pgfkeys{/ddi/fancypicture/extra options/.store in=\ddi@fancy@other@option}
\pgfkeys{/ddi/fancypicture/x/.code={%
  \pgfmathparse{#1}%
  \let\ddi@fancy@view@lx=\pgfmathresult%
}}
\pgfkeys{/ddi/fancypicture/y/.code={%
  \pgfmathparse{#1}%
  \let\ddi@fancy@view@ly=\pgfmathresult%
}}
\pgfkeys{/ddi/fancypicture/size/.code={%
  \pgfmathparse{\ddi@fancy@view@lx+#1}%
  \let\ddi@fancy@view@ux=\pgfmathresult%
  \pgfmathparse{\ddi@fancy@view@ly+#1}%
  \let\ddi@fancy@view@uy=\pgfmathresult%
  \ddi@fancy@size@settrue}%
}
\pgfkeys{/ddi/fancypicture/filename/.store in=\ddi@fancy@filename}

\newcommand\fancypicture[1][]{%
  {\ddi@fancy@size@setfalse%
    \pgfkeys{/ddi/fancypicture/.cd,#1}%
  \edef\ddi@marshal{\noexpand
  \includegraphics[
    clip,height=50pt,width=50pt, % angepasst -- ursprünglich 22 x 22, lh
    \ifddi@fancy@size@set viewport=\ddi@fancy@view@lx\space\ddi@fancy@view@ly\space\ddi@fancy@view@ux\space\ddi@fancy@view@uy,\fi%
    \ddi@fancy@other@option]
    {\ddi@fancy@filename}}%
  \lower4pt\hbox{\ddi@marshal}%
  }\ignorespaces
}

\mode
<all>

\mode<presentation>{\def\fancypictures#1{}}


\mode<article>

% Bibliography
\renewenvironment{thebibliography}[1]
     { 
%\begin{comment}
%\subsection*{\refname}%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
%\end{comment}

\mode
<all>


% Lectures in article mode

\mode
<article>
{
  \renewcommand\lecture[3][]{
    \clearpage
    \gdef\insertlecture{#2}
    \gdef\insertshortlecture{#1}
    \refstepcounter{chapter}
    \setcounter{framenumber}{0}%
    \label{#3}%
  }
  \renewcommand\thechapter{\insertshortlecture}
	\ifonelecture
		\renewcommand*{\thesection}{\arabic{section}}
		\renewcommand*{\thesubsection}{\arabic{section}.\arabic{subsection}}
		\renewcommand*{\thesubsubsection}{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}}
	\fi
}


% Chapters like Introdcution

\def\chapter#1{
  \clearpage
  \null
  \addcontentsline{toc}{chapterstar}{#1}
  \ifodd\c@page%
  \else%
  \leftskip-4.75cm
  \fi
  \chapterlikeheadline{#1}{}{}
  \chapterstarmark{#1}{}
}



% New useful definitions:

\newcommand\ddiborderpicture[1]{%
  \hbox{}\par%
  {%
    \setlength{\marginparsep}{2em}%
    \setlength{\marginparwidth}{5cm-2em}%
    \ddibordercommentpicture{#1}%
    \par%
    \vskip-\baselineskip%
  }
  \ignorespaces%
}

\newcommand\ddibordercommentpicture[1]{%
  \marginpar{\begin{minipage}[t]{4cm}\small\raggedright\hrule
      width0pt\par\vskip-4pt\par%
      \color{black!50}\scriptsize\sffamily\tikzset{every picture/.append style={black,font=\small}}#1\end{minipage}}%
}


\newcommand\includegraphicscopyrightborder[3][]{%
  \hbox{}\par%
  {%
    \setbox\mytempbox=\hbox{\includegraphicscopyright[#1]{#2}{#3}}%
    \setlength{\marginparsep}{2em}%
    \setlength{\marginparwidth}{\wd\mytempbox}%
    \marginpar{\leavevmode\raise\baselineskip\hbox{\lower\ht\mytempbox\box\mytempbox}}%
    \par%
    \vskip-\baselineskip%
  }
  \ignorespaces%
}

\newcommand\includegraphicscopyrightborderautowidth[3][]{%
  \includegraphicscopyrightborder[#1,width=4cm]{#2}{#3}
}
\only<presentation>{
  \let\includegraphicscopyrightborder=\includegraphicscopyright
  \let\includegraphicscopyrightborderautowidth=\includegraphicscopyright
}



\only<presentation>{\newcommand\tafel{\hfill\beamergotobutton{Tafel}}}
\only<article>{\newcommand\tafel{\par\smallskip{\noindent (Details an der Tafel)}}}




% Regie

\mode<article>
{
\newenvironment{lecture notes only}[1][]{
\everythingsmaller
\par\bigskip
\noindent
\ddimarginmark{#1}%
\parskip.5em plus 1pt minus 1pt
\ignorespaces
}
{
\bigskip
}
}

\mode<beamer>
{
  \newenvironment{lecture notes
    only}[1][]{\bgroup\setbox0=\hbox\bgroup}
  {\egroup\egroup}
}

\newenvironment{lecture notes intro}[1][\translate{Worum es heute geht}]
{\begin{lecture notes only}[#1]\normalsize\ignorespaces}{\end{lecture notes only}}

\newenvironment{lecture notes reference}[1][]
{
  \par
  \mode<article>{#1}%
  \noindent%
  \ddimarginmark{\translate{Skript-Referenz}}%
  \everythingsmaller%
  \noindent%
  \ignorespaces%
  }{\bigskip}



% Exercises 
  
\newif\ifddiwideexercises

\mode<article>

\newenvironment{lecture exercises}
{
  \ifddiwideexercises
    \begin{wide pages}\twocolumn[]
    \fi
  \small
  \parskip=2pt plus 1pt minus 1pt
  {\def\thesection{}\let\@seccntformat=\@gobble\translatelet\mytemp{Uebungen zu diesem Vortrag}\section{\mytemp}}
  \sectionstarmark{\translate{Uebungen zu diesem Vortrag}}
}
{
  \ifddiwideexercises
  \end{wide pages}
  \fi
}

\newenvironment{exam exercises}
{  \parskip=2pt plus 1pt minus 1pt\avoidwiddow{3cm}{550}\subsection*{\translate{Pruefungsaufgaben zu diesem Seminar}}
}
{}

\newcommand\appendixchapter[3]
{
  \clearpage
  \parskip=2pt plus 1pt minus 1pt
  \null
  \chapterlikeheadline{Anhang}{#1}{#2}
  \chapterstarmark{Anhang}{#3}
  \addcontentsline{toc}{subsection}{#3}
}

\newenvironment{lecture solutions}
{
  \appendixchapter{Lösungen}{Beispiellösungen zu ausgewählten Übungsaufgaben}{Lösungen zu ausgewählten Übungsaufgaben}
}
{}


\renewcommand\appendix{
  \clearpage
  \chapterstarmark{Anhang}{}
  \addcontentsline{toc}{part}{\protect\numberline{Anhang}}
}


\pgfkeys{
  /ddi/exercise/@credits/ignore/.initial=yes,
  /ddi/exercise/how/ignore/.initial=yes,
  /ddi/exercise/time/ignore/.initial=yes,
  /ddi/exercise/bonus/ignore/.initial=yes,
  /ddi/every exercise/.code=\everythingsmaller,
  /ddi/every solution/.code=\everythingsmaller}

\newcounter{exercisenumber}[chapter]
\renewcommand{\theexercisenumber}{\insertshortlecture.\the\c@exercisenumber}

\renewcommand\insertexercisetext{\translate{Uebung}}

\newcommand\everythingsmaller{%
\small%
\def\@listI{\leftmargin\leftmargini
  \parsep 0pt
  \topsep 3\p@   \@plus2\p@ \@minus3\p@
  \itemsep0pt}%
\let\@listi=\@listI%
\def\@listii{\leftmargin\leftmarginii
  \parsep 0pt
  \topsep 3\p@ \@plus2\p@ \@minus3\p@
  \itemsep0pt}%
\lstset{%
    basicstyle=\ttfamily\footnotesize,
}%
}


\mode
<all>




% Sorting sparklines

\colorlet{varcolor1}{orange!80!red}
\colorlet{varcolor2}{blue}
\colorlet{varcolor3}{violet!70}
\colorlet{varcolor4}{red}
\colorlet{varcolor5}{green!50!black}

\pgfkeys{/algolab/sorting/seq/.code={\global\algolabseq#1\relax}}
\pgfkeys{/algolab/sorting/max value/.initial=5}
\pgfkeys{/algolab/sorting/num values/.initial=5}
\pgfkeys{/algolab/sorting/num vars/.initial=2}
\pgfkeys{/algolab/sorting/compare/.code args={#1 and #2}{\def\possiblecompare{\showcompare{#1}{#2}}}}
\pgfkeys{/algolab/sorting/swap/.code args={#1 and #2}{\def\possibleswap{\showswap{#1}{#2}}}}

\def\possiblecompare{}
\def\possibleswap{}

\def\showcompare#1#2{
  \draw[red!50,very thick,line join=round]
  (\csname algolabvalue#1\endcsname,#1) -- (\pgfkeysvalueof{/algolab/sorting/max value}+2,#1)
  -- (\pgfkeysvalueof{/algolab/sorting/max value}+2,#2) -- (\csname algolabvalue#2\endcsname,#2);
}
\def\showswap#1#2{
  \coordinate (s1) at (\csname algolabvalue#1\endcsname,#1);
  \coordinate (s2) at (\pgfkeysvalueof{/algolab/sorting/max value},#1);
  \coordinate (t1) at (\csname algolabvalue#2\endcsname,#2);
  \coordinate (t2) at (\pgfkeysvalueof{/algolab/sorting/max value},#2);
  \draw[red,very thick,line join=round]
     (s1) -- ([shift={(0.5,0)}]s2) -- ([shift={(1.5,0)}]t2) -- ([shift={(2,0)}]t2) --
     ([shift={(2,0)}]s2)  --  ([shift={(1.5,0)}]s2) -- ([shift={(0.5,0)}]t2) -- (t1);
}

\pgfkeys{/algolab/sorting/offset/.code args={#1=#2}{\pgfkeysalso{/algolab/sorting/vars/offsets/#1/.initial=#2}}}

\pgfkeys{/algolab/sorting/vars/.initial=}
\pgfkeys{/algolab/sorting/@show vars/phantom/.code=\advance\algolabsortingcount by 1\relax}
\pgfkeys{/algolab/sorting/@show vars/.unknown/.code=
  {
    {
      \colorlet{current}{varcolor\the\algolabsortingcount}
      \let\name=\pgfkeyscurrentname
      \let\value=\pgfkeyscurrentvalue
      \pgfkeysifdefined{/algolab/sorting/vars/offsets/\name}
      {\pgfkeysgetvalue{/algolab/sorting/vars/offsets/\name}{\offset}}{\def\offset{0}}
      \@tempcnta=\value\relax
      \advance\@tempcnta by\offset\relax
      \edef\pos{\the\@tempcnta}
      \node [current] (x) at (-1*\pgfkeysvalueof{/algolab/sorting/num vars}-2,2*\algolabsortingcount-2)
      [anchor=mid east,inner sep=1pt]
      {\scriptsize{$\mathit{\name}=\value$}}; 
      \draw [current,semithick] (x.mid east) --
      ++(\pgfkeysvalueof{/algolab/sorting/num vars}-\the\algolabsortingcount+1,0) -- (-1.5,\pos) -- (0,\pos);
      \algolabsortline[current]{\csname algolabvalue\pos\endcsname}{\pos}
    }
    \advance\algolabsortingcount by 1\relax
  }
}
\pgfkeys{/algolab/sorting/values/.initial=0}
\newcount\algolabsortingcount
\newcount\algolabvarnum


\newcommand\algolabsortline[3][]{
  \ifnum#2<0\relax
  \else
    \draw[black!50,line width=.75ex,#1] ([xshift=-0.4pt]0,#3) -- (#2,#3);
  \fi
}

\newcount\algolabseq
\newenvironment{sorting example}[1][]
{
  \global\algolabseq=0\relax
  \pgfkeys{/algolab/sorting/.cd,#1}
}
{}

\newcommand\sortsparkline[1]{%
  \global\advance\algolabseq by1\relax%
  \begin{tikzpicture}[x=.725ex,y=-1ex,join=round]
    \pgfkeys{/algolab/sorting/.cd,#1}
    \path (\pgfkeysvalueof{/algolab/sorting/max value}+3,0);
%    \fill[blue!20]
%      (-10-\pgfkeysvalueof{/algolab/sorting/num vars},-3) rectangle
%      (\pgfkeysvalueof{/algolab/sorting/max value}+3,\pgfkeysvalueof{/algolab/sorting/num values});

%    \fill[blue!20]
%      (-10-\pgfkeysvalueof{/algolab/sorting/num vars},-3) rectangle
%      (\pgfkeysvalueof{/algolab/sorting/max
%        value}+3,\pgfkeysvalueof{/algolab/sorting/num vars}*2-1);

%    \path ([yshift=-2mm]current bounding box.south);

    \tikzset{slide=\the\algolabseq}
%    \node[tiny numbering,below right] at
%    (-9.5-\pgfkeysvalueof{/algolab/sorting/num vars},-2.5) {\the\algolabseq};
      
    \pgfkeysgetvalue{/algolab/sorting/values}{\values}
    \algolabsortingcount=0\relax%
    \expandafter\foreach\expandafter \i\expandafter i\expandafter n\expandafter {\values}
    {
      \algolabsortline{\i}{\algolabsortingcount}
      \expandafter\xdef\csname algolabvalue\the\algolabsortingcount\endcsname{\i}
      \global\advance\algolabsortingcount by 1\relax
    }

    \pgfkeysgetvalue{/algolab/sorting/vars}{\vars}

    \possiblecompare
    \possibleswap
    
    \algolabsortingcount=1\relax%
    \pgfkeys{/algolab/sorting/@show vars/.cd,/utils/exec=\expandafter\pgfkeysalso\expandafter{\vars}}
  \end{tikzpicture}%
  \hfil\penalty0\hfilneg\hskip1mm\ignorespaces
  % 
}



% Typesetting memory models

\newcount\ddimemoryline

\newenvironment{object}[1]
{
  \def\objectname{#1}
  \ddimemoryline=0\relax
  \lstset{basicstyle=\scriptsize\ttfamily}
  \tikzset{@kind/.style=memory}
  \scope
}
{
  \endscope
}

\newenvironment{variables}[1]
{
  \def\objectname{#1}
  \ddimemoryline=0\relax
  \lstset{basicstyle=\scriptsize\ttfamily}
  \tikzset{@kind/.style=var,y=.5cm}
  \scope
}
{
  \endscope
}

\def\attribute#1 #2=#3;{%
  \node [@kind,minimum height=4mm,text height=1mm,text depth=0pt,anchor=base west] (\objectname-#2) at (0,-1*\ddimemoryline) {\scantokens{\javacode|#3|}};
  \node [text height=1mm,text depth=0pt,minimum height=4mm,anchor=base east] at (0,-1*\ddimemoryline) {\javacode|#1 #2|};
  \advance\ddimemoryline by 1\relax
}


% Bars

\pgfdeclareverticalshading{ddibar}{\textwidth}{
  color(0pt)=(white);
  color(1.5pt)=(structure.fg!50);
  color(3pt)=(white)}
  
\newcommand\articlebar{%
  \only<article>{\parskip=0pt\baselineskip=0pt\medskip%
  %\textcolor{structure.fg!50}{\hrule height1pt}%
  \par%
  \pgfuseshading{ddibar}
  \par\medskip}}
  

% Quotations

\mode<article>{
\renewenvironment{quotation}{
  \list{}{\small}\item
  \parindent0em
  \parskip.75em plus 1pt minus 1pt
  \ignorespaces
}
{\endlist}
}


% Rezepte

\newcount\proofcomments

\mode<article>{
  \newenvironment{commented proof}[1][\translate{Proof}]{
    \only<article>{\parskip.1em plus 1pt minus 1pt\proofcomments=0\relax}
    \proof[#1]%
      \setlength{\marginparsep}{2em}%
      \setlength{\marginparwidth}{5cm-2em}%
      \proofcomment[]{\textcolor{structure.fg}{Kommentare zum Rezept}}\noindent\ignorespaces%
  }
  {
    \endproof
  }
  \newcommand\proofcomment[2][\the\proofcomments]{%
    \def\temp{#1}\ifx\temp\pgfutil@empty\else%
    \advance\proofcomments by1\relax%
    \leavevmode\smash{$^{\hbox{\fontsize{6}{7}\selectfont\textcolor{black!50}{#1}}}$}\fi%
    \marginpar{\scriptsize\sffamily\raggedright\textcolor{black!50}{\llap{\smash{\raise 2.8pt\hbox{\tiny#1\ }}}#2}}%
  }%
  \newenvironment{commented definition}[1][]{
    \only<article>{\parskip.1em plus 1pt minus 1pt}
    \definition[#1]%
      \setlength{\marginparsep}{2em}%
      \setlength{\marginparwidth}{5cm-2em}%
      \par\definitioncomment[]{\textcolor{structure.fg}{Kommentare zur Definition}}\noindent\ignorespaces%
  }
  {
    \enddefinition
  }
  \newenvironment{commented paragraph}[1][]{
    \begingroup
      \setlength{\marginparsep}{2em}%
      \setlength{\marginparwidth}{5cm-2em}%
  }
  {
      \par
    \endgroup
  }
}
  
\mode<presentation>

\newenvironment{proof method}[1][]
{
  \pgfkeys{/ddi/proof method/.cd,#1}
  \begin{frame}[fragile=singleslide,t]
    \frametitle{Rezept: \emph{\textcolor{black}%
        {\pgfkeysvalueof{/ddi/proof method/title}}}}
    \begin{columns}[onlytextwidth]
      \column{\textwidth-2.5cm}
        \begin{block}{Ziel}
          \emph{\pgfkeysvalueof{/ddi/proof method/goal}}
        \end{block}
      \column{2cm}
        \vskip1mm
        %\includegraphics[width=1.5cm]{ddi-icon-kochmuetze.pdf}
      \end{columns}
      \begin{block}{Rezept}
}
{
        \end{block}
   \pgfkeysvalueof{/ddi/proof method/also on frame}   
\end{frame}
}


\newcommand\proofcomment[1]{\par{\leftskip0pt plus1fill\rightskip0pt\textcolor{black!50}{(#1)}\par}}
\newenvironment{commented proof}{\proof}{\endproof}
\newenvironment{commented definition}{\definition}{\enddefinition}




% Handling of seminar files

\mode<presentation>{\def\bodydir{.}}

\mode
<article>

\let\ddilecturelist\@empty
	
\defbibheading{bibchap}[\bibname]{%
		%\chapter{#1}
		\addchap{#1}
  	\addcontentsline{toc}{section}{}
  	%\if@twoside\ifx\@mkboth\markboth\markright{#1}\fi\fi
		%\addcontentsline{toc}{chapter}{#1}
	}
		

\def\InsertLectureAndExercises#1{
 %\IfFileExists{../#1/body.bib}{
  %\begin{refsection}[../#1/body.bib]
 %}{
	%\begin{refsection}
 %}
   \def\bodydir{../#1}
   \g@addto@macro\ddilecturelist{\InputIfFileExists{../#1/solutions.tex}{}{}}
   \InputIfFileExists{../#1/body.tex}{}{}
   \InputIfFileExists{../#1/bib-config.tex}{}{}
   \InputIfFileExists{../#1/exercises.tex}{}{}
  %\end{refsection} 
}

\def\InsertSolutions{%
  %\fancypictures{}
  \appendix
  \begin{lecture solutions}
    \ddilecturelist
  \end{lecture solutions}
}

\mode
<all>



\let\definitioncomment=\proofcomment


% Translations

\providetranslation[to=German]{Skript}{Skript}
\providetranslation[to=English]{Skript}{Notes}

\providetranslation[to=German]{DDI}{Fachgebiet Didaktik der Informatik}
\providetranslation[to=English]{DDI}{Department of Didactics of Informatics}

\providetranslation[to=German]{BUW}{\universitaet}
\providetranslation[to=English]{BUW}{\university}

\providetranslation[to=German]{Uebung}{Übung}
\providetranslation[to=English]{Uebung}{Problem}

\providetranslation[to=German]{Zur Uebung}{Zur Übung}
\providetranslation[to=English]{Zur Uebung}{Exercise}

\providetranslation[to=German]{Zur Diskussion}{Zur Diskussion}
\providetranslation[to=English]{Zur Diskussion}{Discussion}

\providetranslation[to=German]{Uebungen zu diesem Vortrag}{Übungen zu diesem Vortrag}
\providetranslation[to=English]{Uebungen zu diesem Vortrag}{Problems for this talk}

\providetranslation[to=German]{Pruefungsaufgaben zu diesem Vortrag}{Prüfungsaufgaben zu diesem
Vortrag}
\providetranslation[to=English]{Pruefungsaufgaben zu diesem Vortrag}{Exam Problems}

\providetranslation[to=German]{Worum es heute geht}{Worum es heute geht}
\providetranslation[to=English]{Worum es heute geht}{Today's topic}

\providetranslation[to=German]{Zum Weiterlesen}{Zum Weiterlesen}
\providetranslation[to=English]{Zum Weiterlesen}{For Further Reading}

\providetranslation[to=German]{Kompetenzen}{Kompetenzen}
\providetranslation[to=English]{Kompetenzen}{Competencies}

\providetranslation[to=German]{Zusammenfassung}{Zusammenfassung}
\providetranslation[to=English]{Zusammenfassung}{Summary}

\providetranslation[to=German]{ vom}{ vom}
\providetranslation[to=English]{ vom}{,}

\providetranslation[to=German]{ von}{ von}
\providetranslation[to=English]{ von}{ by}

\providetranslation[to=German]{Minuten-Aufgaben}{-Minuten-Aufgaben}
\providetranslation[to=English]{Minuten-Aufgaben}{-Minute Exercises}

\providetranslation[to=German]{Minuten-Aufgabe}{-Minuten-Aufgabe}
\providetranslation[to=English]{Minuten-Aufgabe}{-Minute Exercise}

\providetranslation[to=German]{Skript-Referenz}{Skript-\penalty0Referenz}
\providetranslation[to=English]{Skript-Referenz}{Lecture notes material}

