% Prof. Dr. Andreas Podelski: Computer Science - Bridge Course
% Exercise sheets and related material for SS 2014.
% With the collaboration of David Zschocke und Dirk Steinmetz

% csbridge.cls: Student's recommended class file.
% Some stuff that might help students TeXing the submissions.

% Style Guide ------------------------------------------------------------------
% 
% The key word "SHOULD", "MUST" and "MAY" are to be interpreted as described in
% RFC 2119.
% 
% Code Formatting:
% - Lines SHOULD not exceed 80 characters in width.
% - \begin{env} and \end{env} SHOULD only appear on separate lines.
% - Environment's content SHOULD be indented by 2 spaces.
% - If content of brackets spawns multiple lines, it SHOULD be indented with 2
%   spaces.
% - When breaking a long line, subsequent lines on the same logical level MAY
%   be indented with 2 spaces.
% - When breaking a long command, subsequent lines MAY be indented with spaces
%   to align subsequent lines with the command or its curly brackets.
% - Forced line breaks SHOULD be followed by a line break in code.
% - Operators SHOULD be enclosed in spaces.
% - Commas SHOULD be followed by a space character.
% - \section{title} SHOULD be preceded by 4 empty lines.
% - \subsection{title} SHOULD be preceded by 3 empty lines.
% - \subsubsection{title} SHOULD be preceded by 2 empty lines.
% 

% ------------------------------------------------------------------------------
\ProvidesClass{submission}
\LoadClass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}

% Load some packages we need, and configure them where required ----------------
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{titling}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{marvosym}
\usepackage{color}
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{mdframed}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{tikz}
\usetikzlibrary{
  arrows, decorations.pathmorphing, backgrounds, positioning, fit, petri,
  automata
}
\usepackage[hidelinks]{hyperref}
\makeatletter
\AtBeginDocument{
  \hypersetup{
    pdftitle = {\@title},
    pdfauthor = {\@author}
  }
}
\makeatother

% Style ------------------------------------------------------------------------

\setlength\parindent{0pt}
\setlength\parskip{5pt}

% Commands ---------------------------------------------------------------------

% \todo: A note that there is something missing in the script.
% Parameters: #1 Description of what's missing
\newcommand{\todo}[1]{
  \textbf{\textcolor{red}{(Fehlender Inhalt: #1)}}
}

% \mvspace: Glyph for visible spaces, for math mode.
\newcommand\mvspace[1][.5em]{%
  \makebox[#1]{%
    \kern.07em
    \vrule height.3ex
    \hrulefill
    \vrule height.3ex
    \kern.07em
  }%
}

% Environments -----------------------------------------------------------------
% script: the main environment, to use in the main file instead of document.
\newenvironment{submission}[0]{
  \document % \begin{document}
    \begin{center}
      \textbf{Submission for the Tutorial}\\
      \textbf{\large Computer Science Theory (Bridging Course)}\\
      \textit{\thetitle - \theauthor - \thedate}
    \end{center}
}{
  \enddocument % \end{document}
}

% automate: shorthands for pictures of automata.
\newenvironment{automate}[0]{
  \begin{tikzpicture}[baseline=-\the\dimexpr\fontdimen22\textfont2\relax]
  % \state{args}{reference}{label (Math)}:  A regular state
  \newcommand{\state}[3]{
    \node[state, ##1] (##2) {$##3$};
  }
  % \initialstate{args}{reference}{label (Math)}: An initial state
  \newcommand{\initialstate}[3]{
    \state{initial, initial text={}, ##1}{##2}{##3}
  }
  % \acceptingstate{args}{reference}{label (Math)}: An accepting state
  \newcommand{\acceptingstate}[3]{
    \state{accepting, ##1}{##2}{##3}
  }
  % \advtransition{args}{from}{word (Math)}{to}: A transition from one state to
  % another, with custom arguments
  \newcommand{\advtransition}[4]{
    \path[->] (##2) edge [anchor=center, ##1] node {$##3$} (##4);
  }
  % \advtransitionWord{args}{from}{word (Math)}{to}: A word-transition from one
  % state to another, with custom arguments
  \newcommand{\advtransitionWord}[4]{
    \path[->] (##2) edge [anchor=center, decorate, decoration={snake,
      amplitude=.4mm, segment length=2mm, post length=1mm}, ##1] node {$##3$}
    (##4);
  }
  % \transition{from}{word (Math)}{to}: A character-transition from one state to
  % another
  \newcommand{\transition}[3]{
    \advtransition{sloped, above}{##1}{##2}{##3}
  }
  % \transitionWord{from}{word (Math)}{to}: A word-transition from one state to
  % another
  \newcommand{\transitionWord}[3]{
    \advtransitionWord{sloped, above}{##1}{##2}{##3}
  }
}{
  \end{tikzpicture}
}

% graph: shorthands for pictures of graphs.
\newenvironment{graph}[0]{
  \begin{tikzpicture}[baseline=-\the\dimexpr\fontdimen22\textfont2\relax]
  % \gnode{args}{reference}{label (Math)}:  A labeled node
  \newcommand{\gnode}[3]{
    \node[state, ##1] (##2) {$##3$};
  }
  % \gtext{args}{reference}{label (Math)}:  A labeled node
  \newcommand{\gtext}[3]{
    \node[##1] (##2) {$##3$};
  }
  % \gadvline{args}{from}{label (Math)}{to}: A line from one object to another,
  % with custom arguments
  \newcommand{\advline}[4]{
    \path[-] (##2) edge [anchor=center, ##1] node {$##3$} (##4);
  }
  % \gline{from}{to}: A line from one object to another
  \newcommand{\gline}[2]{
    \advline{}{##1}{}{##2}
  }
}{
  \end{tikzpicture}
}

% algorithm: environment for algorithms. An algorithm ONLY consists of formal
% descriptions of the algoritm, as well as its name.
\definecolor{definitionbackground}{RGB}{235, 235, 235}
\lstnewenvironment{algorithm}[0]{
  \lstset{
    mathescape,
    backgroundcolor=\color{definitionbackground},
    morekeywords={Input, Output, while, for, foreach, with, add, remove, to,
      from, return, execute, if},
    tabsize=2,
    framexleftmargin=0.3cm,
    framexrightmargin=0.3cm,
    frame=tb,
    framerule=0pt,
    escapeinside={\%*}{*)},
    literate=
      {á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1
      {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1
      {à}{{\`a}}1 {è}{{\'e}}1 {ì}{{\`i}}1 {ò}{{\`o}}1 {ò}{{\`u}}1
      {À}{{\`A}}1 {È}{{\'E}}1 {Ì}{{\`I}}1 {Ò}{{\`O}}1 {Ò}{{\`U}}1
      {ä}{{\"a}}1 {ë}{{\"e}}1 {ï}{{\"i}}1 {ö}{{\"o}}1 {ü}{{\"u}}1
      {Ä}{{\"A}}1 {Ë}{{\"E}}1 {Ï}{{\"I}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1
      {â}{{\^a}}1 {ê}{{\^e}}1 {î}{{\^i}}1 {ô}{{\^o}}1 {û}{{\^u}}1
      {Â}{{\^A}}1 {Ê}{{\^E}}1 {Î}{{\^I}}1 {Ô}{{\^O}}1 {Û}{{\^U}}1
      {œ}{{\oe}}1 {Œ}{{\OE}}1 {æ}{{\ae}}1 {Æ}{{\AE}}1 {ß}{{\ss}}1
      {ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1 {å}{{\r a}}1 {Å}{{\r A}}1
      {€}{{\EUR}}1 {£}{{\pounds}}1
  }
}{
}