
% Acronyms
% ========
% The argument appears in small caps.
\newcommand\acro[1]{\textsc{\lowercase{#1}}}

% Variables
% =========
\newcommand\widefiguremargin{-.22\textwidth}
\newcommand\widefigurewidth{.49\textwidth}
\newcommand\widefiguregap{.02\textwidth}
\newcommand\widefiguresum{1.4\textwidth}

% Fachschaft logo
% ===============
\newcommand*{\fslogo}{\raisebox{+1.25ex}{\includegraphics[height=6cm]{graphics/logo-fachschaft}}}

% Wide box
% ========
% Box that runs into both margins. To be used inside a floating environment like figure or table.
\newcommand\widebox[1]{
	\hspace{\widefiguremargin}
	\begin{minipage}{\widefiguresum}
		#1
	\end{minipage}
}

% Column rules
% ============
% Adds two rules each spanning approximately half of the available textwidth (as defined by \widefigurewidth).
\newcommand\colrules{
	\rule{\widefigurewidth}{0.4pt}
	\hspace{\widefiguregap}
	\rule{\widefigurewidth}{0.4pt}
}

% Simple code examples
% ====================
% Box for example code next to the rendered example.
%
% Arguments:
% 1. Label.
% 2. Content path without extension. If a corresponding PDF file exists, it gets included as an image. Otherwise, the LaTeX code gets rendered directly.
% 3. Caption.
\newcommand\example[3]{
	\Example{#1}{#2}{#2}{#3}
}

% Extended code examples
% ======================
% Box for example code next to the rendered example.
% Depending on the third argument, the source path for the right-side rendering can differ from the source path of the left-side listing.
% Useful if only an excerpt of the document to be rendered affects the entire output.
%
% Arguments:
% 1. Label.
% 2. Content path without extension. If a corresponding PDF file exists, it gets included as an image. Otherwise, the LaTeX code gets rendered directly.
% 3. Alternative path for Rendering (c.f. 2.)
% 4. Caption.
\newcommand\Example[4]{
	\begin{figure}[htp]
		\widebox{
			% Top rules:
			\colrules
			% Left content: code listing:
			\begin{subfigure}{\widefigurewidth}
				\inputminted[breaklines]{tex}{listings/#2.tex}
			\end{subfigure}
			\hspace{\widefiguregap}
			% Right content: image or rendered example:
			\begin{subfigure}{\widefigurewidth}
				\IfFileExists{listings/#3.pdf}{
					\includegraphics[width=\linewidth]{listings/#3.pdf}
				}{
					\medskip
					\input{listings/#3}
					\medskip
				}
			\end{subfigure}
			% Bottom rules:
			\colrules
			% Left caption:
			\begin{subfigure}[t]{\widefigurewidth}
				\caption{\LaTeX-Code}
				\label{#1-code}
			\end{subfigure}
			\hspace{\widefiguregap}
			% Right caption:
			\begin{subfigure}[t]{\widefigurewidth}
				\caption{Ergebnis}
				\label{#1-result}
			\end{subfigure}
		}
		% General caption:
		\caption{#4}
		\label{#1}
	\end{figure}
}

% Exercise mode
% =============
% The exercise mode can be chosen by writing one of the following to the exercise-mode.tex file before compilation:
% \newcommand\exercisemode{none}      % for a blank script without exercises
% \newcommand\exercisemode{exercises} % for a script with exercises only
% \newcommand\exercisemode{solutions} % for a script with solutions only
% \newcommand\exercisemode{any}       % for a script containing all available material
% The following lines include that file or make \exercisemode default to 'any' so that any derivatives of this project will work even without the file.
\IfFileExists{exercise-mode.tex}{
	\input{exercise-mode.tex}
}{
	\newcommand\exercisemode{any}
}

% Exercises
% =========
% Includes the task.tex file within the given subfolder of exercises and adds a heading.
\newcommand\exercise[1]{
	\ifthenelse{\equal{\exercisemode}{none}}{
		% Exercises disabled.
	}{
		\newpage
		\definecolor{latexblue}{rgb}{0.9,0.925,0.95}
		\pagecolor{latexblue}
		%\definecolor{latexblue}{rgb}{0.73,0.84,0.92}
		\section*{Übung \thechapter}
		\addcontentsline{toc}{section}{Übung}%
		\input{exercises/#1/task.tex}
		\newpage
		\nopagecolor
	}
}

% Exercise Material
% =================
% Takes a project-relative path, and inserts matching exercise material and/or solutions, depending on the exercise mode.
\newcommand\exercisematerial[1]{
	% Mode 'exercises': raw material only
	\ifthenelse{\equal{\exercisemode}{exercises}}{
		\IfFileExists{#1.raw.tex}{
			\input{#1.raw.tex}
		}{}
	}{}
	% Mode 'solutions': completed material only
	\ifthenelse{\equal{\exercisemode}{solutions}}{
		\IfFileExists{#1.done.tex}{
			\input{#1.done.tex}
		}{}
	}{}
	% Mode 'any': all existing material. If both raw and completed material exist, headings are added for each.
	\ifthenelse{\equal{\exercisemode}{any}}{
		\IfFileExists{#1.raw.tex}{
			\IfFileExists{#1.done.tex}{
				\subsubsection*{Vorschau des ungelösten Materials}
			}{}
			\input{#1.raw.tex}
		}{}
		\IfFileExists{#1.done.tex}{
			\IfFileExists{#1.raw.tex}{
				\subsubsection*{Vorschau des gelösten Materials}
			}{}
			\input{#1.done.tex}
		}{}
	}{}
}

