% ib102.sty
% style for homeworks for IB102 Automata, Grammars, and Complexity
% (c) 2013 -- 2014 Vladimír Štill <xstill@fi.muni.cz>
%     CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
%     you must keep this copyright notice and license link and indicate changes
%     in preamble comment, no copyright notice in resulting document is required

\ProvidesClass{ib102}[2014/09/08 v 0.2 IB102]
\NeedsTeXFormat{LaTeX2e}


\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}

\ProcessOptions \relax
\LoadClass{article}

\RequirePackage[utf8]{inputenc}
\RequirePackage[a4paper, left=2.5cm, right=2.5cm, top=2.5cm, bottom=2.5cm]{geometry}
\RequirePackage[T1]{fontenc}
\RequirePackage{fancyhdr}
\RequirePackage{ifthen}
\RequirePackage{enumerate}

\RequirePackage{pgf}
\RequirePackage{tikz}
\RequirePackage{amssymb}
\RequirePackage{amsmath}
\RequirePackage{amsthm}   %důkazy
\usetikzlibrary{calc,arrows,automata}

\newcommand{\eps}{\varepsilon}
\newcommand{\co}[1]{\textrm{co}\mbox{$-$}#1}
\newcommand{\move}{\rightarrow}
\newcommand{\set}[1]{\ensuremath{\{ #1 \}}}

%% BASIC COMMANDS

\addtolength{\headheight}{2.5cm}
\addtolength{\textheight}{-2.5cm}
\addtolength{\headsep}{-0.4cm}

\newcommand{\check@notEmpty}[3]{%
    \if\relax\detokenize{#1}\relax
        \typeout{Chybi #3, nastavte prosim pomoci prikazu #2.}
        \missing@required@field@error
    \fi
}

\def\@student{}
\newcommand{\setstudent}[1]{\check@notEmpty{#1}{setstudent}{jmeno studenta}\def\@student{#1}}

\def\@group{}
\newcommand{\setgroup}[1]{\check@notEmpty{#1}{setgroup}{cislo skupiny}\def\@group{#1}}

\def\@uco{\hspace{3cm}$ $}
\newcommand{\setuco}[1]{\check@notEmpty{#1}{setuco}{uco}\def\@uco{#1}}

\def\@assignment{0}
\newcommand{\setassignment}[1]{\def\@assignment{#1}}

\def\@exercise{0}
\newcommand{\setexercise}[1]{\def\@exercise{#1}}

\def\@points{0}
\newcommand{\setpoints}[1]{\def\@points{#1}}

\def\@dueday{1}
\def\@duemonth{9}
\def\@dueyear{2013}
\newcommand{\setduedate}[3]{\def\@dueday{#1}\def\@duemonth{#2}\def\@dueyear{#3}}

\newcommand{\body}[1]{#1 \ifthenelse{#1 = 1}{bod}{\ifthenelse{#1 = 0 \or #1 > 4}{bodů}{body}}}

%% HEADER
\pagestyle{fancyplain}
\fancyhf{}

\lhead{\large
    \textbf{IB102 -- úkol \@assignment, příklad \@exercise
        \ifx\@solution\@empty
        {} -- řešení
        \fi
        \hfill Odevzdání: \@dueday.\,\@duemonth.\,\@dueyear}
    \vspace{2mm}
    \hrule
    \vspace{2mm}
    Vypracoval(a): \@student\hfill{}UČO: \@uco \\
    Skupina: \@group
    \vspace{1mm}
}

%% DOCUMENT ENVIRONMENTS

% magic to make it possible to disable indetnation after the end of environment
% http://tex.stackexchange.com/a/27559
\newcommand*{\@doendeq}{%
 \everypar{{\setbox\z@\lastbox}\everypar{}}%
 }
\newcommand*{\@noindentafter}{%
 \ignorespacesafterend\par\noindent\aftergroup\@doendeq%
}

\newenvironment{zadani}{%
    \noindent\ignorespaces\textbf{\@exercise.\, [\body{\@points}]}
}{\par\bigskip\@noindentafter}

\newenvironment{bonus}[1]{%
    \noindent\ignorespaces\textbf{Bonus\, [\body{#1}]}
}{\par\bigskip\@noindentafter}

\newenvironment{reseni}{
    \hrule
    \bigskip
    \global\let\@solution\@empty
}{}

\cfoot{\thepage}


% extra commands useful in automata theory typesetting
% http://tex.stackexchange.com/a/29091

\newcommand\turnstile[3][2]{
  \mathrel{\calcturnstile{#1}
  \setbox0=\hbox{$\tsvstyle\vdash$}
  \setbox2=\hbox{$\vcenter{\copy0}$}
  \hbox{\vrule\vphantom{$\tsvstyle\vdash$}}
  \raise\dimexpr\ht0-\ht2\relax\hbox{$\vcenter{\offinterlineskip
   \ialign{\hfil\kern1pt$\tsstyle##\vphantom{by}$\kern1pt\hfil\cr
           \relax\if\relax\detokenize{#2}\relax\hphantom{\vdash}\kern-2pt\else#2\fi\cr
           \noalign{\kern0.4pt\hrule\kern0.4pt}
           \relax\if\relax\detokenize{#2}\relax\hphantom{\vdash}\kern-2pt\else#3\fi\cr}}$}
}}
\newcommand\Turnstile[3][2]{
  \mathrel{\calcturnstile{#1}
  \vcenter{\hbox{\vrule\vphantom{$\tsvstyle\models$}}}
  \vcenter{\offinterlineskip
   \ialign{\hfil\kern1pt$\tsstyle##\vphantom{by}$\hfil\cr
           \relax\if\relax\detokenize{#2}\relax\hphantom{=}\kern-2pt\else#2\fi\cr
           \noalign{\kern0.4pt\hrule\kern\fontdimen22\tsfont2\hrule\kern0.4pt}
           \relax\if\relax\detokenize{#2}\relax\hphantom{-}\kern-2pt\else#3\fi\cr}}
}}
\def\calcturnstile#1{
  \ifcase#1\let\tsstyle\textstyle\let\tsvstyle\textstyle\let\tsfont\textfont\or
    \let\tsstyle\textstyle\let\tsvstyle\textstyle\let\tsfont\textfont\or
    \let\tsstyle\scriptstyle\let\tsvstyle\textstyle\let\tsfont\scriptfont\or
    \let\tsstyle\scriptscriptstyle\let\tsvstyle\scriptstyle\let\tsfont\scriptscriptfont\fi}
