%%%%% title %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{\textbf{\huge\sffamily\tr{Introduction to\\[1ex] Scientific Computing}%
       {Einf\"uhrung in die\\[1ex] wissenschaftliche Datenverarbeitung}}}
%\title{\textbf{\huge\sffamily\tr{Scientific Computing for Neurobiologists}%
%       {Wissenschaftliche Datenverarbeitung f\"ur Neurobiologen}}}

\author{{\LARGE Jan Grewe \& Jan Benda}\\[5ex]Neuroethology Lab\\[2ex]%
        \includegraphics[width=0.3\textwidth]{UT_WBMW_Rot_RGB}\vspace{3ex}}

\date{WS 2020/2021\\\vfill%
      \centerline{\includegraphics[width=0.7\textwidth]{announcements/correlationcartoon}%
      \rotatebox{90}{\footnotesize\url{www.xkcd.com}}}}

%%%% language %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\tr}[2]{#1}  % en
% \newcommand{\tr}[2]{#2}  % de
\usepackage[ngerman,english]{babel}

%%%% encoding %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[T1]{fontenc}

%%%% fonts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{pslatex}   % nice font for pdf file

%%%% layout %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[a4paper,left=25mm,right=25mm,top=20mm,bottom=30mm]{geometry}
\usepackage[within=chapter]{newfloat}
\usepackage{tocloft}
\setlength{\cftfigindent}{1.2em}
\setlength{\cftfignumwidth}{2.6em}

%%%%% section style %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[sf,bf,it,big,clearempty]{titlesec}
\setcounter{secnumdepth}{1}
\setcounter{tocdepth}{1}

%%%%% index %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[makeindex]{splitidx}
\makeindex
\usepackage[totoc]{idxlayout}
\newindex[Glossary]{enterm}
\newindex[Deutsche Fachbegriffe]{determ}
\newindex[\tr{MATLAB code}{MATLAB Code}]{mcode}
\newindex[\tr{Python code}{Python Code}]{pcode}

%%%%% units %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[mediumspace,mediumqspace,Gray]{SIunits}      % \ohm, \micro

%%%%% graphics %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{subcaption}
\usepackage{graphicx}

%%%%%%%%%%%%% colors %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{xcolor}
\definecolor{myyellow}{HTML}{FFEE00}
\definecolor{myblue}{HTML}{0055DD}

\colorlet{codeback}{myblue!10}
\colorlet{exerciseback}{myyellow!20}
\colorlet{importantback}{myblue!15}
\colorlet{importantline}{myblue!50}
\colorlet{infoback}{myyellow!20}
\colorlet{infoline}{myyellow!60}

\definecolor{mygreen}{rgb}{0.2,0.7,0.2}  % for 'TRUE'
\definecolor{myred}{rgb}{1.,0,0}         % for 'FALSE'

\pagecolor{white}

%%%%% figures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% maximum number of floats:
\setcounter{topnumber}{1}
\setcounter{bottomnumber}{1}
\setcounter{totalnumber}{2}

% float placement fractions:
\renewcommand{\textfraction}{0.1}
\renewcommand{\topfraction}{0.9}
\renewcommand{\bottomfraction}{0.9}
\renewcommand{\floatpagefraction}{0.7}

% spacing for floats:
\setlength{\floatsep}{12pt plus 2pt minus 2pt}
\setlength{\textfloatsep}{10pt plus 4pt minus 2pt}
\setlength{\intextsep}{12pt plus 2pt minus 2pt}

% spacing for a floating page:
\makeatletter
  \setlength{\@fptop}{0pt}
  \setlength{\@fpsep}{8pt plus 2.0fil}
  \setlength{\@fpbot}{0pt plus 1.0fil}
\makeatother

% rules for floats:
%\newcommand{\topfigrule}{\vspace*{10pt}{\hrule height0.4pt}\vspace*{-10.4pt}}
%\newcommand{\bottomfigrule}{\vspace*{-10.4pt}{\hrule height0.4pt}\vspace*{10pt}}

% captions:
\usepackage[singlelinecheck=off,labelfont=bf,font={small,sf}]{caption}
\newcommand{\titlecaption}[2]{\caption[#1]{\textbf{#1} #2}}

% put caption on separate float:
\newcommand{\breakfloat}{\end{figure}\begin{figure}[t]}

%%%%% figure references %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% references to panels of a figure within the caption:
\newcommand{\figitem}[1]{\textsf{\bfseries\uppercase{#1}}}
% references to figures:
\newcommand{\panel}[1]{\textsf{\uppercase{#1}}}
\newcommand{\fref}[1]{\textup{\ref{#1}}}
\newcommand{\subfref}[2]{\textup{\ref{#1}}\,\panel{#2}}
% references to figures in normal text:
\newcommand{\fig}{\tr{Fig.}{Abb.}}
\newcommand{\Fig}{\tr{Figure}{Abb.}}
\newcommand{\figs}{\tr{Figs.}{Abb.}}
\newcommand{\Figs}{\tr{Figures}{Abb.}}
\newcommand{\figref}[1]{\fig~\fref{#1}}
\newcommand{\Figref}[1]{\Fig~\fref{#1}}
\newcommand{\figsref}[1]{\figs~\fref{#1}}
\newcommand{\Figsref}[1]{\Figs~\fref{#1}}
\newcommand{\subfigref}[2]{\fig~\subfref{#1}{#2}}
\newcommand{\Subfigref}[2]{\Fig~\subfref{#1}{#2}}
\newcommand{\subfigsref}[2]{\figs~\subfref{#1}{#2}}
\newcommand{\Subfigsref}[2]{\Figs~\subfref{#1}{#2}}
% references to figures within bracketed text:
\newcommand{\figb}{\tr{Fig.}{Abb.}}
\newcommand{\figsb}{\tr{Figs.}{Abb.}}
\newcommand{\figrefb}[1]{\figb~\fref{#1}}
\newcommand{\figsrefb}[1]{\figsb~\fref{#1}}
\newcommand{\subfigrefb}[2]{\figb~\subfref{#1}{#2}}
\newcommand{\subfigsrefb}[2]{\figsb~\subfref{#1}{#2}}

%%%%%%%%%%%%% tables %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{multirow}

%%%%% table references %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\tref}[1]{\textup{\ref{#1}}}
% references to tables in normal text:
\newcommand{\tab}{\tr{Tab.}{Tabelle}}
\newcommand{\Tab}{\tr{Tabel}{Tabelle}}
\newcommand{\tabs}{\tr{Tabs.}{Tabellen}}
\newcommand{\Tabs}{\tr{Tabels.}{Tabellen}}
\newcommand{\tabref}[1]{\tab~\tref{#1}}
\newcommand{\Tabref}[1]{\Tab~\tref{#1}}
\newcommand{\tabsref}[1]{\tabs~\tref{#1}}
\newcommand{\Tabsref}[1]{\Tabs~\tref{#1}}
% references to tables within bracketed text:
\newcommand{\tabb}{\tr{Tab.}{Tabelle}}
\newcommand{\tabsb}{\tr{Tab.}{Tabelle}}
\newcommand{\tabrefb}[1]{\tabb~\tref{#1}}
\newcommand{\tabsrefb}[1]{\tabsb~\tref{#1}}

% invisible rule for expanding the height of a row in a table header:
\newcommand{\erh}{\rule[-1.2ex]{0pt}{3.5ex}}
% invisible rule for expanding the height of a row in a table body:
\newcommand{\erb}{\rule{0pt}{2.5ex}}

%%%%% equation references %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\newcommand{\eqref}[1]{(\ref{#1})}
\newcommand{\eqn}{\tr{Eq}{Gl}.}
\newcommand{\Eqn}{\tr{Eq}{Gl}.}
\newcommand{\eqns}{\tr{Eqs}{Gln}.}
\newcommand{\Eqns}{\tr{Eqs}{Gln}.}
\newcommand{\eqnref}[1]{\eqn~\eqref{#1}}
\newcommand{\Eqnref}[1]{\Eqn~\eqref{#1}}
\newcommand{\eqnsref}[1]{\eqns~\eqref{#1}}
\newcommand{\Eqnsref}[1]{\Eqns~\eqref{#1}}

%%%%% math stuff: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amsmath}
\usepackage{bm} 
\usepackage{dsfont}
\newcommand{\naZ}{\mathds{N}}
\newcommand{\gaZ}{\mathds{Z}}
\newcommand{\raZ}{\mathds{Q}}
\newcommand{\reZ}{\mathds{R}}
\newcommand{\reZp}{\mathds{R^+}}
\newcommand{\reZpN}{\mathds{R^+_0}}
\newcommand{\koZ}{\mathds{C}}

%%%%% listings %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{listings}
\lstset{
  basicstyle=\ttfamily\footnotesize,
  numbers=left,
  showstringspaces=false,
  language=Matlab,
  commentstyle=\itshape\color{red!60!black},
  keywordstyle=\color{blue!50!black},
  stringstyle=\color{green!50!black},
  backgroundcolor=\color{codeback},
  breaklines=true,
  breakautoindent=true,
%  columns=flexible,   % this kills the monospace font
  frame=single,
  caption={\protect\filename@parse{\lstname}\protect\filename@base},
  captionpos=t,
  xleftmargin=21pt,
  xrightmargin=1mm,
  aboveskip=1ex,
  belowskip=2ex
}
\SetupFloatingEnvironment{lstlisting}{chapterlistsgaps=on}
% format list of listing exactly like list of figures:
\makeatletter
\let\l@lstlisting\l@figure
\makeatother

% \lstinputlisting wrapped in a minipage to avoid page breaks:
\newcommand{\pageinputlisting}[2][]{\vspace{-2ex}\noindent\begin{minipage}[t]{1\linewidth}\lstinputlisting[#1]{#2}\end{minipage}}

%%%%% listing environment: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% usage:
%
% \begin{pagelisting}[label=listing1, caption={A script.}]
%   >> x = 6
% \end{pagelisting}
%
% This is the lstlisting environment but wrapped in a minipage to avoid page breaks.
\lstnewenvironment{pagelisting}[1][]%
  {\vspace{-2ex}\lstset{#1}\noindent\minipage[t]{1\linewidth}}%
  {\endminipage}

%%%%% english and german terms: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{ifthen}

% \enterm[en-index]{term}: Typeset term and add it to the index of english terms
%
% \determ[de-index]{term}: Typeset term and add it to the index of german terms
%
% \entermde[en-index]{de-index}{term}: Typeset term and add it to the index of english terms
%                                      and de-index to the index of german terms
%
% how to specificy an index:
% \enterm{term}                                 - just put term into the index
% \enterm[en-index]{term}                       - typeset term and put en-index into the index
% \enterm[statistics!mean]{term}                - mean is a subentry of statistics
% \enterm[statistics!average|see{statistics!mean}]{term} - cross reference to statistics mean
% \enterm[statistics@\textbf{statistics}]{term} - put index at statistics but use 
%                                               \textbf{statistics} for typesetting in the index

% \enterm[english index entry]{<english term>}
% typeset the term in italics and add it (or rather the optional argument) to
% the english index.
\newcommand{\enterm}[2][]{\textit{#2}\ifthenelse{\equal{#1}{}}{\protect\sindex[enterm]{#2}}{\protect\sindex[enterm]{#1}}}

% \entermde[english index entry]{<german index entry>}{<english term>}
% typeset the english term in italics and add it (or the first
% optional argument) to the english index. In addition add the german
% index entry to the german index without printing it.
\newcommand{\entermde}[3][]{\textit{#3}\ifthenelse{\equal{#1}{}}{\protect\sindex[enterm]{#3}}{\protect\sindex[enterm]{#1}}\protect\sindex[determ]{#2}}

% \determ[index entry]{<german term>}
% typeset the term in quotes and add it (or the optional argument) to
% the german index.
\newcommand{\determ}[2][]{\selectlanguage{ngerman}``#2''\selectlanguage{english}\ifthenelse{\equal{#1}{}}{\protect\sindex[determ]{#2}}{\protect\sindex[determ]{#1}}}

\newcommand{\file}[1]{\texttt{#1}}

% for escaping special characters into the index:
\newcommand{\scor}{"|}

%%%%% key-shortcuts %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tikz}
\usetikzlibrary{shapes}
\tikzstyle{keybox} = [draw=blue!50!black,fill=white,thick,rectangle,rounded corners,inner sep=3pt,inner ysep=2pt]
\newcommand{\keycode}[1]{\begin{tikzpicture}[baseline=(box.base)]\node[keybox](box){\texttt{#1}};\end{tikzpicture}}

%%%%% code/matlab commands: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{textcomp}

% typeset code inline:
\newcommand{\varcode}[1]{\setlength{\fboxsep}{0.5ex}\colorbox{codeback}{\texttt{#1\protect\rule[-0.1ex]{0pt}{1.6ex}}}}

% typeset code and add it to the python index:
\newcommand{\pcode}[2][]{\varcode{#2}\ifthenelse{\equal{#1}{}}{\protect\sindex[pcode]{#2}}{\protect\sindex[pcode]{#1}}}

% typeset code and add it to the matlab index:
\newcommand{\mcode}[2][]{\varcode{#2}\ifthenelse{\equal{#1}{}}{\protect\sindex[mcode]{#2}}{\protect\sindex[mcode]{#1}}}

% XXX typeset code and put it into matlab index: 
% THIS SHOULD actually take both the matlab and the python code!
\newcommand{\code}[2][]{\varcode{#2}\ifthenelse{\equal{#1}{}}{\protect\sindex[mcode]{#2}}{\protect\sindex[mcode]{#1}}}

% the name of the python language:
\newcommand{\python}{Python}

% the name of the matlab language:
\newcommand{\matlab}{\texorpdfstring{MATLAB$^{\copyright}$}{MATLAB}}

% typeset '(python-function #1)' and add the function to the python index:
\newcommand{\pythonfun}[1]{(\tr{\python-function}{\python-Funktion} \varcode{#1})\protect\sindex[pcode]{#1}}

% typeset '(matlab-function #1)' and add the function to the matlab index:
\newcommand{\matlabfun}[1]{(function \varcode{#1})\protect\sindex[mcode]{#1}}


%%%%% shortquote and widequote commands: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \shortquote{Something to be quoted}{Source}
\newcommand{\shortquote}[2]{\begin{list}{}{\rightmargin\leftmargin}\item\relax\itshape #1 \hfill \upshape #2\end{list}}

% \widequote{Something to be quoted}{Source}
\newcommand{\widequote}[2]{{\itshape #1} \hfill #2}

%%%%% exercises environment: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% usage:
%
% \begin{exercise}{somecode.m}{someoutput.out}
%   Write a function that computes the median.
% \end{exercise}
%
% result in a nicely colored box with the content:
%
% Exercise 1:
% Write a function that computes the median.
% Listing 1: somecode.m
% the listing
% Output:
% content of someoutput.out
%
% Within the exercise environment enumerate is redefined to generate (a), (b), (c), ...
%
% The boolean showexercisesolutions controls whether solutions for the exercises
% are actually included.
%
% \exercisesolutions controls where the solutions of the exercises are placed:
% - 'here': solutions are printed right after the exercises in the same box
% - 'chapter': solutions are printed at the end of each chapter
% - 'end': all solutions are printed at the end of the script
% if you change this you probably need to run make cleantex before
%
\newboolean{showexercisesolutions}
\setboolean{showexercisesolutions}{true}
\newcommand{\exercisesolutions}{end}  % 0: here, 1: chapter, 2: end
% we need this also as numbers:
\ifthenelse{\equal{\exercisesolutions}{end}}{\newcommand{\exercisesolutionsnum}{2}}{%
  \ifthenelse{\equal{\exercisesolutions}{chapter}}{\newcommand{\exercisesolutionsnum}{1}}{%
    \newcommand{\exercisesolutionsnum}{0}}}
\newcommand{\codepath}{}
\newcommand{\setcodepath}[1]{\ifthenelse{\not\equal{\exercisesolutions}{here}}{\renewcommand{\codepath}{#1/}}{}\lstset{inputpath=#1}}
\usepackage{mdframed}
\usepackage{xstring}
\newlistof{exercisef}{loe}{\tr{Exercises}{\"Ubungen}}
\DeclareFloatingEnvironment[
  fileext=loe,
  name={\tr{Exercise}{\"Ubung}},
  placement=t,
  chapterlistsgaps=on,
]{exercisef}
\newwrite\solutions  % file descriptor for writing solutions
% we need to know the name of the included file as \currentjobname:
\usepackage{xpatch}
% the following does not work with \ifthenelse
\ifnum\exercisesolutionsnum=1
  \def\currentjobname{\jobname}
  \xpretocmd{\include}{\def\currentjobname{#1}\immediate\openout\solutions=\currentjobname-solutions}{}{}\fi%
\ifnum\exercisesolutionsnum=2
  \def\currentjobname{\jobname}
  \immediate\openout\solutions=\currentjobname-solutions
  \def\exercisechapter#1{\immediate\write\solutions{\unexpanded{\pagebreak[3]\section}{\thechapter. #1}}}
\else
  \def\exercisechapter#1{}
\fi
\newenvironment{exercise}[2]%
  { \setlength{\fboxsep}{2mm}%
    \newcommand{\saveenumi}{\theenumi}\renewcommand{\labelenumi}{(\alph{enumi})}%
    \captionsetup{singlelinecheck=off,hypcap=false,labelfont={large,sf,it,bf},%
                  font={large,sf,it,bf},skip={0.5ex}}%
    \begin{mdframed}[linewidth=0pt,backgroundcolor=exerciseback]%
      \captionof{exercisef}[\protect\StrSubstitute{#1}{_}{\_}]{}%
      \captionsetup{font={normal,sf,it}}%
      \ifthenelse{\equal{\exercisesolutions}{here}}{%
        \newcommand{\exercisesource}{#1}%
        \newcommand{\exercisefile}{\protect\StrSubstitute{#1}{_}{\_}}%
        \newcommand{\exerciseoutput}{#2}%
      }{%
        \immediate\write\solutions{\unexpanded{\subsection}{Exercise \thechapter.\arabic{exercisef}}}%
        \immediate\write\solutions{\unexpanded{\label}{solution\arabic{chapter}-\arabic{exercisef}}}%
        \immediate\write\solutions{\unexpanded{\begin{minipage}{1\linewidth}\lstinputlisting[belowskip=0ex,aboveskip=0ex,%
          nolol=true, title={\textbf{Source code:} \protect\StrSubstitute{#1}{_}{\_}}]}{\codepath#1}\unexpanded{\end{minipage}}}%
        \ifthenelse{\equal{#2}{}}{}%
          {\immediate\write\solutions{\unexpanded{\begin{minipage}{1\linewidth}\lstinputlisting[language={},%
             nolol=true, title={\textbf{Output:}}, belowskip=0ex, aboveskip=1ex]}{\codepath#2}\unexpanded{\end{minipage}}}}%
        \immediate\write\solutions{\unexpanded{\vspace*{\fill}}}%
        \immediate\write\solutions{}%
      }%
  }%
  { \ifthenelse{\equal{\exercisesolutions}{here}}{%
      \ifthenelse{\boolean{showexercisesolutions}}%
        { \hypersetup{hypertexnames=false}%
          \ifthenelse{\equal{\exercisesource}{}}{}%
          { \addtocounter{lstlisting}{-1}%
            \par\noindent\begin{minipage}[t]{1\linewidth}%
            \lstinputlisting[belowskip=1ex,aboveskip=-1ex,nolol=true,%
                             title={\textbf{Solution:} \exercisefile}]%
                            {\exercisesource}%
            \end{minipage}%
            \ifthenelse{\equal{\exerciseoutput}{}}{}%
              { \addtocounter{lstlisting}{-1}%
                \par\noindent\begin{minipage}[t]{1\linewidth}%
                \lstinputlisting[language={},title={\textbf{Output:}},%
                                 nolol=true,belowskip=0pt,aboveskip=-0.5ex]%
                                {\exerciseoutput}%
                \end{minipage}%
              }%
          }%
          \hypersetup{hypertexnames=true}%
        }{}}{%
          \ifthenelse{\boolean{showexercisesolutions}}%
             {\hspace*{\fill}\hyperref[solution\arabic{chapter}-\arabic{exercisef}]{\mbox{$\rightarrow$ solution}}}{}}%
    \renewcommand{\theenumi}{\saveenumi}%
    \end{mdframed}%
  }
\newcommand{\printsolutions}{\ifthenelse{\equal{\exercisesolutions}{chapter}%
    \or\(\equal{\exercisesolutions}{end}\and\not\isundefined{\chapternumber}\)}{%
    \immediate\closeout\solutions%
    \ifthenelse{\boolean{showexercisesolutions}}{%
      \clearpage\ifthenelse{\equal{\exercisesolutions}{chapter}}%
        {\section{Solutions to the exercises}}%
        {\chapter{Solutions to the exercises}}%
      \ifthenelse{\isundefined{\chapternumber}}{\lstset{inputpath=}}{}%
      \input{\currentjobname-solutions} }{}}{}}
\newcommand{\printallsolutions}{\ifthenelse{\equal{\exercisesolutions}{end}}{%
    \immediate\closeout\solutions%
    \ifthenelse{\boolean{showexercisesolutions}}{%
      \setcounter{secnumdepth}{0}\lstset{inputpath=}%
      \clearpage\chapter{Solutions to the exercises}%
      \input{\currentjobname-solutions} }{}}{}}
\setlength{\cftexercisefindent}{1.2em}
\setlength{\cftexercisefnumwidth}{2.6em}

%%%%% info box environment: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% usage:
%
% \begin{ibox}[tp]{Python}
%   The cooler programming language.
% \end{ibox}
%
% results in a nicely colored float:
%
% Info Box 1: Python
% The cooler programming language.
\newlistof{iboxf}{lob}{\tr{Info Boxes and Topics}{Info- und Merk-Boxen}}
\DeclareFloatingEnvironment[
  fileext=lob,
  name={Info-Box},
  placement=t,
  chapterlistsgaps=on,
]{iboxf}
\newenvironment{ibox}[2][tp]
{\SetupFloatingEnvironment{iboxf}{placement=#1}%
  \begin{iboxf}%
    \captionsetup{singlelinecheck=off,labelfont={large,sf,it,bf},font={large,sf,it,bf}}%
    \begin{mdframed}[linecolor=infoline,linewidth=1ex,%
      backgroundcolor=infoback,font={\sffamily},%
      frametitle={\caption{#2}},frametitleaboveskip=-1ex,%
      frametitlebackgroundcolor=infoline]%
    \setlength{\parindent}{0pt}\setlength{\parskip}{1ex}%
      \captionsetup{singlelinecheck=off,labelfont={normalsize,sf,bf},font={normalsize,sf}}}%
{\end{mdframed}%
  \end{iboxf}}
\setlength{\cftiboxfindent}{1.2em}
\setlength{\cftiboxfnumwidth}{2.6em}


%%%%% important environment: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% usage:
%
% \begin{important}[Apples are important]
%   Something you should really remember.
% \end{important}
%
% results in a nicely colored box with the text inside.
% The optional title of the box "Apples are important"
% also appears in the list of important things.
% \DeclareFloatingEnvironment[
%   fileext=loi,
%   listname={\tr{Important hints}{Merk-Boxen}},
%   name={Merk-Box},
%   placement=t,
%   chapterlistsgaps=on,
% ]{importantf}
\newenvironment{important}[1][]%
  { \captionsetup{singlelinecheck=off,hypcap=false,labelformat={empty},%
                  labelfont={large,sf,it,bf},font={large,sf,it,bf}}
    \ifthenelse{\equal{#1}{}}%
    { \begin{mdframed}[nobreak=true,linecolor=importantline,linewidth=1ex,%
                       backgroundcolor=importantback,font={\sffamily}]%
        \setlength{\parindent}{0pt}%
        \setlength{\parskip}{1ex}%
    }%
    { \begin{mdframed}[nobreak=true,linecolor=importantline,linewidth=1ex,%
                       backgroundcolor=importantback,font={\sffamily},%
                       frametitle={\captionof{iboxf}{#1}},frametitleaboveskip=-1ex,%
                       frametitlebackgroundcolor=importantline]%
        \setlength{\parindent}{0pt}%
        \setlength{\parskip}{1ex}%
    }%
  }%
  {\end{mdframed}}


%%%%% hyperref %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[bookmarks=true,bookmarksopen=true,%
  pdfpagemode=UseNone,pdfstartview=FitH,%
  plainpages=false,pdfpagelabels,%
  breaklinks=true,colorlinks=true,%
  citecolor=blue!50!black,linkcolor=red!70!black,urlcolor=blue!50!black]{hyperref}
