% -*- coding: utf-8; -*-
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -+
%                                                                                                  |
% (C)opyright A. Hilbig, mail@andrehilbig.de                                                       |
%             http://www.andrehilbig.de/Publications                                               |
%                                                                                                  | 
% diese Datei: ahilbig-common.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-common}

\newif\ifdraftversion
\newif\ifbw
\newif\ifcd
\newif\ifschule
\newif\ifpalatino

\DeclareOption{draft}{\draftversiontrue}
\DeclareOption{blackandwhite}{\bwtrue}
\DeclareOption{cd}{\cdtrue}
\DeclareOption{schule}{\schuletrue}
\DeclareOption{palatino}{\palatinotrue}

\ProcessOptions

\RequirePackage[german=guillemets]{csquotes}

% Automatische Skalierung zu grosser (breiter) Grafiken
\RequirePackage[Export]{adjustbox}
\adjustboxset{max size={\textwidth}{0.9\textheight}}

%\RequirePackage{svn-multi}
%\RequirePackage[all]{svn-multi}
%\RequirePackage[filehooks,autokw]{svn-multi}
\RequirePackage{staves}
\RequirePackage{rotating} 
\RequirePackage{scalerel}  

\RequirePackage{longtable,booktabs,supertabular,array}
\newcolumntype{C}[1]{>{\centering}p{#1}}
\newcolumntype{L}[1]{>{\raggedright}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft}p{#1}}
\renewcommand{\arraystretch}{1}
\providecommand{\newArrayStretch}[1]{%
	\renewcommand{\arraystretch}{#1}%
}
\providecommand{\oldArrayStretch}{%
	\renewcommand{\arraystretch}{1}%
}

\RequirePackage[official]{eurosym} 
\RequirePackage{fancybox} 
\@ifclassloaded{beamer}{}{\RequirePackage{beamerarticle}}
\ifschule
	\RequirePackage{schule}
	\let\schuleSo\so
	\let\so\relax
\fi

\RequirePackage{tabularx} 
\RequirePackage{xmpmulti} 
\RequirePackage{pdfcomment} 
\RequirePackage{xspace}

\RequirePackage{prettyref}
\RequirePackage{nameref}
%%% Für Kapitel %%%
\newrefformat{chp}{Kapitel~\ref{#1} \enquote{\nameref{#1}}, S.\,\pageref{#1}}
%%% Für Abschnitte %%%
\newrefformat{sec}{Abschnitt~\ref{#1}, S.\,\pageref{#1}}
%%% Für Abbildungen %%%
\newrefformat{fig}{Abb.~\ref{#1}, S.\,\pageref{#1}}
%%% Für Tabellen %%%
\newrefformat{tab}{Tab.~\ref{#1}, S.\,\pageref{#1}}
%%% Für Formeln %%%
\newrefformat{form}{Formel~\ref{#1}}
%%% Für Aufgaben %%%
\newcommand{\refexercise}[1]{} % siehe weiter unten Definition
\newrefformat{ex}{\refexercise{#1}}


%\RequirePackage{paralist}  % < führt zu Problemen mit beamer

%\RequirePackage[svgnames,rgb]{color} % Option Clash ....

\RequirePackage[curves]{struktex} 

% Vorlesung 2
\newcommand\specparrightplus[3]{%
\begin{flushleft}
  \newdimen\breite
  \breite=#1cm
  \scaleleftright[\breite]{.}{\parbox{2.\breite}{#2}}{\}}{\parbox{2.\breite}{#3}}
\end{flushleft}
}

% ab Vorlesung 9
\newcommand\kreisc[1]{\ensuremath{\mathbin{\settowidth{\dimen7}{\mbox{$\bigcirc$}}%
              \makebox[0pt][l]{$\bigcirc$}\raisebox{-0.2mm}{\makebox[\dimen7]{#1}}}}}

 
\RequirePackage{bookmark}

\RequirePackage{amsmath}
\RequirePackage{accents}

\RequirePackage{array}

\RequirePackage{delarray}

\RequirePackage{comment}

\RequirePackage{pgfkeys}
\RequirePackage{ifluatex}
\ifluatex
 \RequirePackage[utf8]{luainputenc}
\else
 \RequirePackage[utf8]{inputenc}
\fi


\def\UrlFont{}

%%\ifcd\else
%\RequirePackage{futura}
%% \RequirePackage{utopia}
%%\fi
%\RequirePackage{Myriad}
%\RequirePackage{droid}
\RequirePackage{lmodern}
\RequirePackage{courier}


\def\headingfont{\small\sffamily}


% Basic colors

\colorlet{structure.fg}{orange!80!red}
\definecolor{black50}{rgb}{.50,.50,.51}

\definecolor{black90}{rgb}{.90,.90,.91}
\definecolor{black95}{rgb}{.94,.94,.95}

\long\def\hilight#1{{\ifbw\else\color{structure.fg}\fi#1}}
\ifbw
  \colorlet{head.bg}{black}
\else
  \colorlet{head.bg}{structure.fg}
\fi

\ifcd
%  \RequirePackage[mixedgreek,textlf]{Myriad}
  \RequirePackage{microtype}
  \let\sfdefault\rmdefault
  \definecolor{oceangreen}{cmyk}{1,0,.2,.78} 
  \colorlet{structure.fg}{oceangreen!75!white}
  \colorlet{head.bg}{oceangreen}
  \def\headingfont{\sffamily}
  \AtBeginDocument{
    % \renewcommand\scshape{\error}
    \DeclareTextFontCommand{\orig@textsc}{\scshape}
    \edef\MyriadText{\sfdefault}
    \DeclareRobustCommand\textsc[1]{\ifx\f@family\MyriadText{\ifdim\f@size pt=10pt\relax\small\fi\edef\ddi@temp{#1}\expandafter\uppercase\expandafter{\ddi@temp}}\else\orig@textsc{#1}\fi}
  }
\fi

\RequirePackage{ahilbig-letterspace}
\ifpalatino
	\RequirePackage{palatino}
\fi

\providecommand{\RightArrow}{\textcolor{structure.fg}{$\Rightarrow$}}
\providecommand{\TCs}[1]{\textcolor{structure.fg}{#1}}

\newenvironment{colitemize}[1][2]{
	\begin{multicols}{#1}
		\begin{itemize}
}{
		\end{itemize}
	\end{multicols}
}

\mode<article>
{
%%  \ifcmmath
%%  \else
    \RequirePackage{mathptmx}
    \DeclareSymbolFont{symbols}     {OMS}{cmsy}{m}{n}
    \DeclareSymbolFont{largesymbols}{OMX}{cmex}{m}{n}
    \DeclareSymbolFont{rmletters}   {OML}{ztmcm}{m}{it}
    \DeclareSymbolFont{letters}     {OML}{ztmcm} {m}{it}
%    \ifcd\My@Greek@Mix\fi
%%  \fi
  %\RequirePackage[bookmarksnumbered,pdfborder={0 0 0}]{hyperref}
  %\RequirePackage[plainpages=false,bookmarksnumbered,pdfborder={0 0 0}]{hyperref}
\RequirePackage{paralist} %% wg. pasternak
\RequirePackage{tcolorbox} 

}
\def\rmdefault{qtm}
%\ifcd\else\def\sfdefault{Futura}\fi


\mode<article>
{


% Lists/enumerations/descriptions
  
\def\@listI{\leftmargin\leftmargini
  \parsep 0pt
  \topsep 5\p@   \@plus3\p@ \@minus5\p@
  \itemsep0pt}
\let\@listi=\@listI
\def\@listii{\leftmargin\leftmarginii
  \parsep 0pt
  \topsep 3\p@ \@plus3\p@ \@minus3\p@
  \itemsep0pt}
\leftmargini=1.85em

\parindent=0pt
\parskip=2pt plus 1pt minus 1pt

\renewenvironment{description}
{
  \list{}{\advance\leftmargin by1cm
    \labelwidth\leftmargin
    \itemindent0pt
    \let\makelabel\descriptionlabel
    \itemsep3pt plus2pt minus 2pt}}
{\endlist}

\renewcommand*\descriptionlabel[1]{%
  \hfil\hspace\labelsep{\normalfont\headingfont\hilight{#1}}}


\def\enumerate{%
  \ifnum \@enumdepth >\thr@@\@toodeep\else
    \advance\@enumdepth\@ne
    \edef\@enumctr{enum\romannumeral\the\@enumdepth}%
      \expandafter
      \list
        \csname label\@enumctr\endcsname
        {\usecounter\@enumctr\def\makelabel##1{\hss\llap{\footnotesize\sffamily##1}}}%
  \fi}

\def\itemize{%
  \ifnum \@itemdepth >\thr@@\@toodeep\else
    \advance\@itemdepth\@ne
    \edef\@itemitem{labelitem\romannumeral\the\@itemdepth}%
    \expandafter
    \list
      \csname\@itemitem\endcsname
      {\def\makelabel##1{\hss\llap{\sffamily##1}}}%
  \fi}

\renewcommand\labelitemi{\normalfont\hilight{\bfseries–}}
\renewcommand\labelitemii{\normalfont\bfseries–}

\renewcommand\theenumi{\@arabic\c@enumi}
\renewcommand\theenumii{\@arabic\c@enumi.\@arabic\c@enumii}
\renewcommand\theenumiii{\@arabic\c@enumi.\@arabic\c@enumii.\@arabic\c@enumiii}

\renewcommand\labelenumi{\hilight{\theenumi.}}
\renewcommand\labelenumii{\textcolor{black}{\theenumii}}

\setbeamertemplate{block begin}
  {\avoidwiddow{2cm}{50}\par\vskip\medskipamount\penalty-100\parskip0pt{\raggedright\headingfont{\noindent\hilight{\insertblocktitle}}\par}\noindent\ignorespaces}
\setbeamertemplate{block alerted begin}
  {\avoidwiddow{2cm}{50}\par\vskip\medskipamount\penalty-100\parskip0pt{\raggedright\headingfont{\noindent\color{red!90!black}\insertblocktitle}\par}\noindent\ignorespaces}
}


% Common packages

%\RequirePackage[german]{babel}

\RequirePackage[T1]{fontenc}
\RequirePackage{colortbl}


% Chapter-like Headline

\newcommand\chapterlikeheadline[3]{
  {%
    \rightskip0pt plus1fil
    \parindent=0pt
    \sffamily
    \vskip2em%
    {\fontsize{36pt}{36pt}\selectfont #1 \par\vskip2pt}
    {\fontsize{24pt}{28pt}\selectfont \hilight{#2}\par\vskip4pt}
    \expandafter\def\expandafter\temp\expandafter{#3}%
    \ifx\temp\@empty\else{\Large\selectfont \color{black} \temp\par}\fi
    \vskip10pt
  }
  \par
  \vskip 1.5em%
}


\theoremstyle{definition}
\newtheorem{notation}[theorem]{Notation}


\mode
<article>


% Sections

\let\origstartsection=\@startsection
\def\@startsection#1#2#3#4#5#6{%
  \origstartsection{#1}{#2}{#3}{#4}{#5}{#6\raggedright\normalfont\sffamily\ifodd#2\relax\else\ifbw\color{black}\else\color{structure.fg}\fi\fi\selectfont}}

\def\avoidwiddow#1#2{\par\vskip 0pt plus #1\penalty-#2\vskip 0pt plus -#1\ignorespaces}

\renewcommand\section{\avoidwiddow{3cm}{600}
  \@startsection {section}{1}{\z@}%
  {-3.5ex \@plus -1ex \@minus -.2ex}%
  {1.5ex \@plus.2ex}%
  {\normalfont\Large\bfseries}}
\renewcommand\subsection{\avoidwiddow{3cm}{300}\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {.5ex \@plus .2ex}%
                                     {\normalfont\large\bfseries}}
\renewcommand\subsubsection{\avoidwiddow{3cm}{250}\@startsection{subsubsection}{3}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\normalsize\bfseries}}

% Theorems and such

\newenvironment{definitionlike}[2][]{%
  \def\test{#1}%
%  \par%
%  \color{structure.fg}%
%  \hbox\bgroup\hskip-1.5ex\vrule width .5ex\hskip1ex\vbox\bgroup%
%  \color{black}%
  \block{\ddibordericon{{\ddiborderpointer}}%
    #2\ifx\test\@empty\else: \textcolor{black}{#1}\fi}
  \ignorespaces
}
{\endblock}

\newenvironment{examplelike}[2][]{%
  \def\test{#1}
  \block{%
    #2\ifx\test\@empty\else: \textcolor{black}{#1}\fi}
  \ignorespaces
}
{\endblock}

\newenvironment{theoremlike}[2][]{%
  \def\mytest{#1}
  \block{\ddibordericon{{\ddiborderpointer}}%
    #2\ifx\mytest\@empty\else: \textcolor{black}{#1}\fi}
  \itshape\ignorespaces
}
{\endblock}

\newcommand\ddiborderpointer{{\textcolor{structure.fg}{\large$\blacktriangleright$}}}%\LARGE\ding{43}}}}
%\newcommand\ddiborderpointer{{\includegraphics[height=2em]{ddi-icon-bulb-red-ccas.png}}}
\newcommand\ddiborderannote{{\textcolor{structure.fg}{\staveVI}}} 

\renewenvironment{problem}[1][]{\definitionlike[#1]{Problem}}{\enddefinitionlike}
\renewenvironment{definition}[1][]{\definitionlike[#1]{\translate{Definition}}}{\enddefinitionlike}
\renewenvironment{example}[1][]{\examplelike[#1]{\translate{Beispiel}}}{\endexamplelike}
\renewenvironment{examples}[1][]{\examplelike[#1]{\translate{Beispiele}}}{\endexamplelike}
\renewenvironment{theorem}[1][]{\theoremlike[#1]{\translate{Satz}}}{\endtheoremlike}
\renewenvironment{lemma}[1][]{\theoremlike[#1]{\translate{Lemma}}}{\endtheoremlike}
\renewenvironment{corollary}[1][]{\theoremlike[#1]{\translate{Folgerung}}}{\endtheoremlike}
\renewenvironment{notation}[1][]{\definitionlike[#1]{Notation}}{\enddefinitionlike}

\mode
<all>

\providetranslation[to=German]{Einordnung}{Einordnung}
\providetranslation[to=English]{Einordnung}{Qualifying}

\providetranslation[to=German]{Erläuterung}{Erläuterung}
\providetranslation[to=English]{Erläuterung}{Annotation}
\providetranslation[to=German]{Erläuterungen}{Erläuterungen}
\providetranslation[to=English]{Erläuterungen}{Annotations}

\providetranslation[to=German]{Erklärung}{Erklärung}
\providetranslation[to=English]{Erklärung}{Explanation}
\providetranslation[to=German]{Erklärungen}{Erklärungen}
\providetranslation[to=English]{Erklärungen}{Explanations}

\providetranslation[to=German]{Beispiel}{Beispiel}
\providetranslation[to=English]{Beispiel}{Example}

\providetranslation[to=German]{Beispiele}{Beispiele}
\providetranslation[to=English]{Beispiele}{Examples}

\providetranslation[to=German]{Satz}{Satz}
\providetranslation[to=English]{Satz}{Theorem}

\providetranslation[to=German]{Folgerung}{Folgerung}
\providetranslation[to=English]{Folgerung}{Corollary}

%~~
\newtranslation[to=German]{Advantages}{Vorteile}
\newtranslation[to=English]{Advantages}{Advantages}

\newtranslation[to=German]{Disadvantages}{Nachteile}
\newtranslation[to=English]{Disadvantages}{Disadvantages}

\newenvironment{advantages}[1][\translate{Advantages}]{
  \setbeamercolor{structure}{fg=green!50!black}
  \only<article>{\colorlet{structure.fg}{green!50!black}}
  \begin{block}{#1}%
    \alt<article>{\renewcommand\labelitemi{\normalfont\hilight{\bfseries+}}}%
    {\setbeamertemplate{itemize item}{+}}%
  }
  {\end{block}}
\newenvironment{disadvantages}[1][\translate{Disadvantages}]{
  \setbeamercolor{structure}{fg=red!50!black}
  \only<article>{\colorlet{structure.fg}{red!75!black}}
  \begin{block}{#1}%
    \only<presentation>{\setbeamertemplate{itemize item}{–}}%
  }
  {\end{block}}
  

% Typesetting Listings

\RequirePackage{listings}
\lstset{extendedchars=true}

\newif\ifemphlistings
\def\colorunlessemph#1{\ifemphlistings\else\color{#1}\fi}

% Allow German umlauts:
\lstset{%
  literate={ä}{{\"a}}1
           {ö}{{\"o}}1
           {ü}{{\"u}}1
           {Ä}{{\"A}}1
           {Ö}{{\"O}}1
           {Ü}{{\"U}}1
           {ß}{{\ss}}1
}

\lstset{%
  basicstyle=\footnotesize\ttfamily,
  commentstyle=\itshape\colorunlessemph{green!50!black},
  keywordstyle=\bfseries\colorunlessemph{structure.fg},
  identifierstyle=\colorunlessemph{blue},
  stringstyle=\colorunlessemph{violet},
  emphstyle=\color{red},
  numbersep=1em,
  breaklines=true,
  breakatwhitespace=true,
  numberstyle=\scriptsize\color{black!50}
}

\only<article>
{
  \lstset{%
    basicstyle=\ttfamily\small,
    backgroundcolor=\color{structure.fg!10},
    frame=lines,
    framerule=1pt,
    rulecolor=\color{structure.fg},
    numberstyle=\scriptsize\sffamily\color{black!50}
  }
  \ifbw
    \lstset{backgroundcolor=}
  \fi
  \ifcd
    \lstset{backgroundcolor=\color{structure.fg!5}}
  \fi
}

\alt<article>
{
  \lstdefinestyle{presentationscriptsize}{}
}
{
  \lstdefinestyle{presentationscriptsize}{basicstyle=\ttfamily\scriptsize}
}

\alt<article>
{
  \lstdefinestyle{presentationtinysize}{basicstyle=\ttfamily\scriptsize}
}
{
  \lstdefinestyle{presentationtinysize}{basicstyle=\ttfamily\tiny}
}

\lstdefinelanguage{css}{
   morekeywords={
      border,padding,color,font,font-size,height,width,margin,background-image,
      red,green,blue,float,left,right,top,bottom,position,absolute,relative,
      solid,
      margin-top,margin-bottom,margin-left,margin-right,
      border-top,border-bottom,border-left,border-right,
      padding-top,padding-bottom,padding-left,padding-right
    },%
   morecomment=[s]{/*}{*/},%
   morestring=[b]",%
   alsoletter={-},%
}
\lstdefinelanguage{MySQL}[]{SQL}{
  morekeywords={ADD,ALL,ALTER,ANALYZE,AND,AS,ASC,ASENSITIVE,BEFORE,BETWEEN,BIGINT,BINARY
    BLOB,BOTH,BY,CALL,CASCADE,CASE,CHANGE,CHAR,CHARACTER,CHECK,COLLATE,COLUMN,
    CONDITION,CONSTRAINT,CONTINUE,CONVERT,CREATE,CROSS,CURRENT_DATE,
    CURRENT_TIME,CURRENT_TIMESTAMP,CURRENT_USER,CURSOR,DATABASE,DATABASES,
    DAY_HOUR,DAY_MICROSECOND,DAY_MINUTE,DAY_SECOND,DEC,DECIMAL,DECLARE,DEFAULT,
    DELAYED,DELETE,DESC,DESCRIBE,DETERMINISTIC,DISTINCT,DISTINCTROW,DIV,DOUBLE,
    DROP,DUAL,EACH,ELSE,ELSEIF,ENCLOSED,ESCAPED,EXISTS,EXIT,EXPLAIN,FALSE,FETCH,
    FLOAT,FLOAT4,FLOAT8,FOR,FORCE,FOREIGN,FROM,FULLTEXT,GRANT,
    GROUP,HAVING,HIGH_PRIORITY,HOUR_MICROSECOND,HOUR_MINUTE,HOUR_SECOND,
    IF,IGNORE,IN,INDEX,INFILE,INNER,INOUT,INSENSITIVE,INSERT,
    INT,INT1,INT2,INT3,INT4,INT8,INTEGER,INTERVAL,INTO,
    IS,ITERATE,JOIN,KEY,KEYS,KILL,LEADING,LEAVE,LEFT,
    LIKE,LIMIT,LINES,LOAD,LOCALTIME,LOCALTIMESTAMP,LOCK,LONG,LONGBLOB,
    LONGTEXT,LOOP,LOW_PRIORITY,MATCH,MEDIUMBLOB,MEDIUMINT,MEDIUMTEXT,
    MIDDLEINT,MINUTE_MICROSECOND,MINUTE_SECOND,MOD,MODIFIES,NATURAL,NOT,
    NO_WRITE_TO_BINLOG,NULL,NUMERIC,ON,OPTIMIZE,OPTION,OPTIONALLY,
    OR,ORDER,OUT,OUTER,OUTFILE,PRECISION,PRIMARY,PROCEDURE,PURGE,
    READ,READS,REAL,REFERENCES,REGEXP,RELEASE,RENAME,REPEAT,REPLACE,
    REQUIRE,RESTRICT,RETURN,REVOKE,RIGHT,RLIKE,SCHEMA,SCHEMAS,SECOND_MICROSECOND,
    SELECT,SENSITIVE,SEPARATOR,SET,SHOW,SMALLINT,SONAME,SPATIAL,SPECIFIC,
    SQL,SQLEXCEPTION,SQLSTATE,SQLWARNING,SQL_BIG_RESULT,SQL_CALC_FOUND_ROWS,
    SQL_SMALL_RESULT,SSL,STARTING,STRAIGHT_JOIN,TABLE,TERMINATED,
    THEN,TINYBLOB,TINYINT,TINYTEXT,TO,TRAILING,TRIGGER,TRUE,UNDO,
    UNION,UNIQUE,UNLOCK,UNSIGNED,UPDATE,USAGE,USE,USING,UTC_DATE,
    UTC_TIME,UTC_TIMESTAMP,VALUES,VARBINARY,VARCHAR,VARCHARACTER,
    VARYING,WHEN,WHERE,WHILE,WITH,WRITE,XOR,YEAR_MONTH,ZEROFILL,
    ASENSITIVE,CALL,CONDITION,CONNECTION,CONTINUE,CURSOR,
    DECLARE,DETERMINISTIC,EACH,ELSEIF,EXIT,FETCH,
    GOTO,INOUT,INSENSITIVE,ITERATE,LABEL,LEAVE,
    LOOP,MODIFIES,OUT,READS,RELEASE,REPEAT,
    RETURN,SCHEMA,SCHEMAS,SENSITIVE,SPECIFIC,SQL,
    SQLEXCEPTION,SQLSTATE,SQLWARNING,
    TRIGGER,UNDO,UPGRADE,WHILE
  }
}

\lstdefinelanguage{pseudocode}{
  morekeywords={
    if,then,else,while,do,repeat,until,seq,seqdo,return,call,
    for,pardo,in,foreach,print,output,input,exit,
    break,loop,end,begin,goto,pardo,par,global,read,write,to,stop,idle,procedure,function
  },
  sensitive=true,
  morecomment=[l]{//},
  morecomment=[l]{\%},
  morestring=[b]",
}

\lstdefinestyle{text}{
  basicstyle=\ttfamily\footnotesize,
}

\lstdefinestyle{pseudocodebase}{
  language=pseudocode,
  numbers=left,
  basicstyle=\rmfamily\footnotesize,
  keywordstyle=\bfseries\itshape\colorunlessemph{structure.fg},
  columns=fullflexible,
  mathescape=true,
  identifierstyle=\itshape,
  literate={<}{{$<$}}1
           {>}{{$>$}}1
           {-}{{-}}1
           {+}{{$+$}}1
           {*}{{$\cdot$}}1
           {<-}{{$\gets$\ }}2
           {<=}{{$\leq$}}1
           {>=}{{$\geq$}}1
           {!=}{{$\neq$}}1
           {==}{{$=$}}1
           {ä}{{\"a}}1
           {ö}{{\"o}}1
           {ü}{{\"u}}1
           {Ä}{{\"A}}1
           {Ö}{{\"O}}1
           {Ü}{{\"U}}1
           {ß}{{\ss}}1
}

\lstdefinelanguage{while}{
   morekeywords={
      uint,return,while,loop
    }
}

  
\lstdefinelanguage{MuML}{
   morekeywords={
      fun,0,succ,min
    }
}
\alt<article>
{\lstdefinestyle{pseudocode}{style=pseudocodebase,basicstyle=\rmfamily}}
{\lstdefinestyle{pseudocode}{xleftmargin=1em,style=pseudocodebase,basicstyle=\sffamily\small,keywordstyle=\itshape\colorunlessemph{structure.fg}}}

\lstdefinestyle{alerts}{% We want easy hilighting
  moredelim=**[is][\color{red}\emphlistingstrue]{(!}{!)}%
}

\lstdefinestyle{escapes}{
  escapechar=\#
}

\def\pythoncode{\lstinline[language=Python]}
\def\javacode{\lstinline[language=Java]}
\def\ccode{\lstinline[language=C]}
\def\htmlcode{\lstinline[language=html]}
\def\csscode{\lstinline[language=css]}
\def\sqlcode{\lstinline[language=MySQL]}
\def\pseudocode{\lstinline[style=pseudocode]}
\def\texcode{\lstinline[language={[LaTeX]tex}]}
\def\whilecode{\lstinline[language=while,mathescape=true]}
\def\mucode{\lstinline[language=MuML]}

\alt<article>
{
  \def\verbatim@font{\normalfont\small\ttfamily}
}
{
  \def\verbatim@font{\normalfont\footnotesize\ttfamily}
}

% New useful definitions:

\newbox\mytempbox
\newdimen\mytempdimen

\newcommand\includegraphicscopyright[3][]{%
  \leavevmode\vbox{\vskip3pt\raggedright\setbox\mytempbox=\hbox{\includegraphics[#1]{#2}}%
    \mytempdimen=\wd\mytempbox\box\mytempbox\par\vskip1pt%
    \sffamily\fontsize{3}{3.5}\selectfont\spaceskip=.333em\xspaceskip=.5em{\color{black}{\vbox{\hsize=\mytempdimen#3}}}\vskip3pt%
}}


\newenvironment{colortabular}[1]{\medskip\rowcolors[]{1}{structure.fg!10}{structure.fg!3}\tabular{#1}\rowcolor{structure.fg!20}}{\endtabular\medskip}

\def\equad{\leavevmode\hbox{}\quad}

\newenvironment{greencolortabular}[1]
{\medskip\rowcolors[]{1}{green!50!black!20}{green!50!black!5}%
  \tabular{#1}\rowcolor{green!50!black!40}}%
{\endtabular\medskip}

\only<article>{\let\greencolortabular=\colortabular\let\endgreencolortabular=\endcolortabular}



% Exercises

\mode<article>

\newif\ifbonus

\pgfkeys{
  /ddi/exercise/title/.initial=,
  /ddi/exercise/credits/.initial=,
  /ddi/exercise/@credits/.initial=,
  /ddi/exercise/level/.initial=,
  /ddi/exercise/how/.initial=,
  /ddi/exercise/@solution/.initial=,
  /ddi/exercise/solution/.style={@solution=mit~Lösung},
  /ddi/exercise/@examtext/.initial=,
  /ddi/exercise/exam/.is choice,
  /ddi/exercise/exam/no/.style={@examtext=nicht~klausurrelevant},
  /ddi/exercise/exam/used/.style={@examtext=original~Klausuraufgabe},
  /ddi/exercise/exam/typical/.style={@examtext=typische~Klausuraufgabe},
  /ddi/exercise/bonus/.is if=bonus,
  /ddi/exercise/time/.initial=,
  /ddi/exercise/label/.store in=\exerciselabel}
  
\newif\ifignorekey
\def\ddiyestext{yes}

\def\possiblyuse#1{%
  \ignorekeyfalse%
  \pgfkeysifdefined{/ddi/exercise/#1/ignore}
  {%
    \pgfkeysgetvalue{/ddi/exercise/#1/ignore}\dditemp
    \ifx\dditemp\ddiyestext%
      \ignorekeytrue%
    \fi%
  }%
  {}%
  \ifignorekey
  \else
    \pgfkeysgetvalue{/ddi/exercise/#1}{\mymacro}%
    \ifx\mymacro\@empty%
    \else%
      \ifx\infostring\@empty%
        \let\infostring=\mymacro%
      \else
        \expandafter\expandafter\expandafter\def
        \expandafter\expandafter\expandafter\infostring
        \expandafter\expandafter\expandafter
        {\expandafter\infostring\expandafter,\expandafter\ \mymacro}% 
      \fi%
    \fi%
  \fi%
}

\newbox\mybox

\newenvironment{exercise}[1][]%
{
  \pgfkeys{/ddi/exercise/.cd,/ddi/every exercise/.try,#1}%
  \parindent0pt%
  \refstepcounter{exercisenumber}%
  \goodbreak\medskip\noindent
  {%
    \parskip=0pt%
    \raggedright%
    \headingfont%
    \hilight{%
    \setbox\mybox=\hbox{%
      \insertexercisetext%
      \pgfkeysifdefined{/ddi/exercise/bonus/ignore}{}{{\ifbonus*\fi}}\
      \theexercisenumber%
      \hskip2ex% 
    }%
    \ddisetupcredits%
    \leftskip\wd\mybox%
    \llap{\box\mybox}%
    \def\infostring{}%
    \possiblyuse{title}%
    \possiblyuse{level}%
    \possiblyuse{@credits}%
    \possiblyuse{how}%
    \possiblyuse{time}%
    \possiblyuse{@examtext}%
    \possiblyuse{@solution}%
    \ifx\infostring\@empty\else{\textcolor{black}{\infostring}}\fi\hfill%
  \par}%
  }%
  \ifx\exerciselabel\@undefined\else\expandafter\label\expandafter{\exerciselabel}\fi%
  \pgfkeys{/ddi/exercise/at begin/.try}%
  \ignorespaces
}
{
  \parskip0pt
  \par\medskip
}

\newcommand\insertexercisetext{\translate{Aufgabe}}
\newcommand\insertpointtext{Punkt}
\newcommand\insertpointstext{Punkte}
\newcommand\insertbonuspointtext{Bonuspunkt}
\newcommand\insertbonuspointstext{Bonuspunkte}
\newtranslation[to=German]{Aufgabe}{Aufgabe}
\newtranslation[to=English]{Aufgabe}{Problem}

\def\ddisetupcredits{%
  \pgfkeysgetvalue{/ddi/exercise/credits}{\ddipoints}%
  \ifx\ddipoints\@empty%
    \ddi@plain@numberfalse%
  \else%
    \afterassignment\ddi@check\expandafter\@tempcnta\expandafter1\ddipoints\relax%
  \fi%
  \ifddi@plain@number%
    \ifbonus%
      \ifnum\ddipoints=1\relax%
        \pgfkeys{/ddi/exercise/@credits/.expanded=\ddipoints\ \insertbonuspointtext}%
      \else%
        \pgfkeys{/ddi/exercise/@credits/.expanded=\ddipoints\ \insertbonuspointstext}%
      \fi%
    \else%
      \ifnum\ddipoints=1\relax%
        \pgfkeys{/ddi/exercise/@credits/.expanded=\ddipoints\ \insertpointtext}%
      \else%
        \pgfkeys{/ddi/exercise/@credits/.expanded=\ddipoints\ \insertpointstext}%
      \fi%
    \fi%
  \else%
    \pgfkeys{/ddi/exercise/@credits/.expanded=\ddipoints}%
  \fi%
}
\newif\ifddi@plain@number

\def\ddi@check{%
  \@ifnextchar\relax{\ddi@plain@numbertrue\ddi@gobble@to@stop}{\ddi@plain@numberfalse\ddi@gobble@to@stop}%
}
\def\ddi@gobble@to@stop#1\relax{}%




% Solutions

\pgfkeys{/ddi/solution/of/.initial=}


\renewenvironment{solution}[1][]
{
  \pgfkeys{/ddi/solution/.cd,/ddi/every solution/.try,#1}
  \parindent0pt%
  \goodbreak\medskip\noindent
  {\sffamily%
    \parskip0pt\hilight{%
    Beispiellösung zu \refexercise{\pgfkeysvalueof{/ddi/solution/of}}}\hfill
  \par%
  }%
  \ignorespaces
}
{
  \parskip0pt
  \par\medskip
}

\renewcommand\refexercise[1]{\insertexercisetext~\ref{#1}}

\mode
<all>


\newcommand\ddibordericon[1]{%
  \llap{\smash{\hbox{#1}}\kern1ex}%
}


% Rezept
\pgfkeys{/ddi/proof method/title/.initial=}
\pgfkeys{/ddi/proof method/goal/.initial=}
\pgfkeys{/ddi/proof method/also on frame/.initial=}

\mode
<article>

% \newenvironment{proof method}[1][]
% {
%   \pgfkeys{/ddi/proof method/.cd,#1}
%   \par%
%   \vfil\penalty100\vfilneg%
%   \begin{frame}{}
%     \addcontentsline{lop}{subsection}{\pgfkeysvalueof{/ddi/proof method/title}}
%     \advance\hsize by-20pt
%     \setbox\mybox=\vbox
%     \bgroup
%       \begin{minipage}[t]{\textwidth-2.5cm-20pt}
%         \textsf{\hilight{Beweisrezept f\"ur}\\ \large\pgfkeysvalueof{/ddi/proof method/title}\smallskip}      

%         \begin{block}{Ziel}
%           \pgfkeysvalueof{/ddi/proof method/goal}
%         \end{block}
%       \end{minipage}\hskip5mm
%       \begin{minipage}[t]{2cm}
%         \ \par\vskip-1em\includegraphics[width=2cm]{ddi-icon-kochmuetze.pdf}
%       \end{minipage}
%       \par
%       \begin{minipage}{\textwidth-20pt}
%       \begin{block}{Rezept}
% }
% {
%       \end{block}
%     \end{minipage}
%     \egroup%
%     \parskip0pt
%     \advance\hsize by20pt
%     \vskip-1em{\fboxsep=1em%
%       \color{structure.fg}\hrule height2pt depth0pt%
%       \color{black}\colorbox{black90}{\box\mybox}%
%       \color{structure.fg}\hrule height2pt%
%     }\medskip
%     \pgfkeysvalueof{/ddi/proof method/also on frame}   
%   \end{frame}  
% }


\newenvironment{proof method}[1][]
{
  \pgfkeys{/ddi/proof method/.cd,#1}
  \par%
  \vfil\penalty100\vfilneg%
	\begin{frame}{\ddibordericon{\lower3pt\hbox{}}%\includegraphics[height=1.5em]{ddi-icon-kochmuetze.pdf}{}}}%
      Rezept: \emph{\hilight{\pgfkeysvalueof{/ddi/proof method/title}}}}
    \addcontentsline{lop}{subsection}{\pgfkeysvalueof{/ddi/proof method/title}}
    \begin{block}{Ziel}
      \emph{\pgfkeysvalueof{/ddi/proof method/goal}}
    \end{block}
    \begin{block}{Rezept}
}
{
    \end{block}
    \pgfkeysvalueof{/ddi/proof method/also on frame}   
  \end{frame}  
}


\mode
<all>


%
% TikZ styles
%

\RequirePackage{tikz}
\usetikzlibrary{mindmap,trees,backgrounds,arrows,calendar,fadings,shadows,  
                matrix,shapes,shapes.geometric,shapes.misc,petri,fit,
                decorations.markings,
                decorations.pathmorphing,
                decorations.pathreplacing,
}

\tikzset{
  plain/.style={minimum  size=0mm,shape=rectangle,font=,draw=none,thin,fill=none,inner
    sep=0.333em,text depth=,text height=,text width=},
  node/.style={minimum size=6mm,shape=circle,font=\small,draw=structure.fg,thick, 
    fill=structure.fg!10,inner sep=1pt
  },
  tiny node/.style={minimum size=3mm,shape=circle,font=\tiny,draw=structure.fg,thick, 
    fill=structure.fg!10,inner sep=0.3pt
  },
  long label/.style={shape=rounded rectangle,text depth=0.15em,text
    height=0.7em},
  rectangular/.style={rectangle,minimum height=1cm,minimum width=4cm,rounded corners},
  box/.style={node,shape=rectangle},
  blue node/.style={node,fill=blue!20,draw=blue},
  tiny blue node/.style={tiny node,fill=blue!20,draw=blue},
  red node/.style={node,fill=red!20,draw=red},
  tiny red node/.style={tiny node,fill=red!20,draw=red},
  orange node/.style={node,fill=orange!20,draw=orange},
  tiny orange node/.style={tiny node,fill=orange!20,draw=orange},
  green node/.style={node,fill=green!50!black!20,draw=green!50!black},
  tiny green node/.style={tiny node,fill=green!50!black!20,draw=green!50!black},
  black node/.style={node,fill=black!20,draw=black},
  tiny black node/.style={tiny node,fill=black!20,draw=black},
  gray node/.style={node,fill=black!20,draw=black!50,text=black!50},
  tiny gray node/.style={tiny node,fill=black!20,draw=black!50,text=black!50},
  graph/.style={semithick,>=spaced stealth'},
  tree/.style={
    every node/.style={node,long label},
    edge from parent/.style={draw,>=spaced stealth',semithick},
    grow=down,
    level 1/.style={level distance=1cm,sibling distance=2cm},
    level 2/.style={sibling distance=1cm}
  },
  reverse tree/.style={tree,edge from
    parent/.style={draw,>=spaced stealth',semithick,<-}},
  graphs/suffix tree/.style={
    trie,
    simple,
    edges={nodes={inner sep=1pt,anchor=mid,fill=white}},
    nodes={tiny node},
    sibling distance=1.5cm,
    empty nodes,
    /tikz/every edge quotes/.style={}
  },
  graphs/trie graph/.style={
    trie,
    simple,
    edges={nodes={inner sep=1pt,anchor=mid,fill=white}},
    nodes={tiny node},
    sibling distance=1.5cm,
    put node text on incoming edges
  },
  labeling/.style={below right,inner sep=2pt,font=\scriptsize},
  gate/.style={node,rectangle,minimum height=6mm,minimum width=4mm},
  tiny gate/.style={gate,minimum size=0pt,inner sep=1pt,thin},  
  numbering/.style={circle,fill=structure.fg,text=white,inner sep=0.5pt,font=\footnotesize\sffamily,minimum size=1.25em},
  tiny numbering/.style={numbering,font=\tiny\sffamily},
  memory/.style={thick,draw=blue,fill=blue!20,rectangle,minimum width=#1cm,minimum height=5mm},
  memory/.default=1,
  var/.style={node,long label,minimum height=4.5mm,minimum width=1cm},
  pointer/.style={shorten <=-8pt,*-spaced stealth',semithick},
  petrinet/.style={
    graph,
    every transition/.style={font=\small,draw=blue,thick,fill=blue!20},
    every place/.style={font=\small,draw=structure.fg,thick,fill=structure.fg!10,minimum
      size=7mm}
  },
  automaton/.style={graph,every state/.style=node},
  dot/.style={circle,fill=structure.fg,minimum size=4pt,inner sep=0pt,outer sep=0pt,draw=none},
  slide/.style={
    execute at end picture={
      \pgfonlayer{background}
        \fill [rounded corners,draw=black!15,very thick,fill=black!5]
        ([shift={(-3mm,-3mm)}]current bounding box.south west) rectangle ([shift={(3mm,3mm)}]current bounding box.north east);
        \def\temp{#1}
        \ifx\temp\pgfutil@empty
        \path ([yshift=1.5mm]current bounding box.north);
        \else
        \node[node,draw=black!15,very thick,fill=white,long label,text
        depth=1.5pt,text height=5pt,minimum height=3mm,minimum
        width=6mm,font=\tiny\sffamily,right] at ([xshift=3mm]current bounding box.north west)
        {#1};
        \fi
        \path ([yshift=-1.5mm]current bounding box.south);
      \endpgfonlayer
    }
  },
  slide/.default=
}

\pgfarrowsdeclarecombine*{spaced stealth'}{spaced
  stealth'}{stealth'}{stealth'}{space}{space}

% Myriad fixes

\ifcd
\let\epsilon\varepsilon
\let\phi\varphi
\fi

% Till's two favorite macros

\mode
<presentation>
\newcommand\Class[1]{\mathsf{#1}}
\newcommand\Lang[1]{\text{\normalfont\footnotesize{\uppercase{#1}}}}

\mode
<article>
\newcommand\Class[1]{\mathchoice{\text{\upshape\small$\mathrm{#1}$}}{\text{\upshape\small$\mathrm{#1}$}}{\text{\upshape$\mathrm{#1}$}}{\text{\upshape$\mathrm{#1}$}}}
\newcommand\Lang[1]{\text{\normalfont\textsc{\lowercase{#1}}}}


\mode
<all>

