% License: GNU Free Documentation License (GFDL) http://www.gnu.org/copyleft/fdl.html

%==============
% Custom Colors
%==============

\definecolor{darkgray}{gray}{0.35}
\definecolor{mediumgray}{gray}{0.85}
\definecolor{lightgray}{gray}{0.93}
\definecolor{link}{rgb}{0.7,0.28,0.0}
\definecolor{url}{gray}{0.35}

%===========================================
% Counters/Variables and their getter/setter
%===========================================

% neuer Zähler für Links in einem Artikel
\newcounter{linkcounter}

% Zähler zurücksetzen
\newcommand{\resetcounter}{\setcounter{linkcounter}{1}\setcounter{lstlisting}{0}\SetListingSize{\normalsize}}

% Umstellen der Schriftgröße in Listing- und Befehlsumgebungen.
\newcommand{\SetListingSize}[1]{\renewcommand{\ListingSize}{#1}}

% Definition für die Schriftgröße in den Listing- und Befehlsumgebungen.
\newcommand{\ListingSize}{\normalsize}

% Festes Leerzeichen (non breaking space), wird benötigt für \BildabsatzV, wenn es am Anfang der Zeile steht.
% Benutzung: \nbsp
\newcommand{\nbsp}{~}

\setcounter{tocdepth}{1}

% is being renewed in each article (see below)
\newcommand{\currentArticle}{}

%====================
% Structural commands
%====================

% Sections of an article/impressum
% Usage: \FMSection{TITLE}
\newcommand{\FMSection}[1]{\subsection*{#1}}

% Creates an editorial page
% Usage: \begin{fm_editorial}{TITLE}{SECTION}{SHORT_TITLE}
\newenvironment{FMEditorial}[3]{\FMPageHeader{#2}{#3}\vspace{2cm}{\Large #1}}{}

\newcommand{\FMTOC}[2]{\FMPageHeader{#1}{#2}\tableofcontents}

% Article without entry in table of contents and without page header (e.g. for the impressum)
% Usage: \begin{FMStrippedArticle}{TITLE}{AUTHOR}{TAG} ... \end{FMStrippedArticle}
% Usually NOT to be used directly, use FMImpressum or FMArticle instead
\newenvironment{FMStrippedArticle}[3]{\renewcommand{\currentArticle}{#3}\begin{multicols}{2}[\FMArticleHeadline{#1}{#2}{#3}]}{\end{multicols}}

% Creates an impressum (2 columns, no author, no page header)
% Usage: \FMImpressum{TITLE}
\newenvironment{FMImpressum}[0]{\begin{FMStrippedArticle}{Impressum}{}{impressum}}{\end{FMStrippedArticle}}

% Defines an article
% Usage: \begin{FMArticle}{TITLE}{AUTHOR}{SECTION}{SHORT_TITLE}{TAG} ... \end{Artikel}
% TAG is the name of the article directory. It is also being used as PDFTAG
% SECTION and SHORT_TITLE are used for the page header (\FMPageHeader)
\newenvironment{FMArticle}[5]{\addcontentsline{toc}{section}{#1}\FMPageHeader{#3}{#4}\begin{FMStrippedArticle}{#1}{#2}{#5}}{\end{FMStrippedArticle}}

% Shows all sources (usually at the end of an article)
% Usage: \begin{FMSources} ... \end{FMSources}
\newenvironment{FMSources}
{\nbsp\\[-10mm]
\begin{tabular}{@{}p{\columnwidth}}
\hfill \textcolor{black}{\normalfont\large\scshape Links} \\[-2ex]
\end{tabular}
\renewcommand*\labelenumi{[\theenumi]}
\begin{small}
\begin{FMItemize}}
{\end{FMItemize}
\end{small}
\renewcommand*\labelenumi{\theenumi.}}

% Shows a single Source (intended to be used in the FMSources environment)
% Benutzung: \FMSource{URL}
\newcommand{\FMSource}[1]{\item \url{#1}}

%==================================
% Commands to be used inside an article
%==================================

% Inserts an image
% Usage: \Bild[WIDTH]{FILEPATH}{SUBTITLE}
% WIDTH (optional) is a relative number between 0 and 1
% FILEPATH is relative to the directory of the current article
\newcommand{\FMImage}[4][.95]
{\begin{minipage}[t]{1\linewidth}
  \centering
  \href{\currentArticle/#2}{\includegraphics[width=#1\textwidth]{content/#2}}\\
  \emph{#4}~\href{\currentArticle/#2}{}
\end{minipage}}

% Itemize with parameters
\newenvironment{FMItemize}
{\begin{enumerate}[topsep=-2mm,parsep=1mm,itemsep=0mm,leftmargin=*]}
{\end{enumerate}}

% Insert a link
% Usage: \FMLink{URL}
\newcommand{\FMLink}[2][\arabic{linkcounter}\stepcounter{linkcounter}]{~\href{#2}{[#1]}}

%===========================
% Helpers (for internal use)
%===========================

% Überschrift für jeden Abschnitt
% Benutzung: \Headline{ÜBERSCHRIFT}{PDFMARKE}
% Dies wird nur in der befehle.tex verwendet!
\newcommand{\FMHeadline}[2]{\resetcounter\pdfbookmark[2]{#1}{#2}\textcolor{darkgray}{\textbf{{\Large \hypertarget{#2}{#1}\label{#2}}}}\\[-6px] \FMLine}

% Headline für Artikel
% Benutzung: \FMArticleHeadline{TITEL}{AUTOR}{PDFMARKE}
\newcommand{\FMArticleHeadline}[3]{\resetcounter\pdfbookmark[2]{#1}{#3}\textcolor{darkgray}{\textbf{{\Large \hypertarget{#3}{#1}\label{#3}} \hspace*{4mm}#2}}\\[-
6px] \FMLine}

% Textbox, e.q. for quotes
% Benutzung: \begin{Textbox}[WIDTH] ... \end{BefehlUmg}
\lstnewenvironment{FMTextbox}[1][1]
{\lstset{style=FMTextBoxStyle,linewidth=#1\linewidth}}
{}

% Textbox fuer Programmcode
% Benutzung: \begin{BefehlUmgS}[BREITE] ... \end{BefehlUmg}
\lstnewenvironment{FMListing}[1][1]
{\lstset{style=FMListingStyle,linewidth=#1\linewidth}}
{}

% Textbox fuer Programmcode ohne Zeilennummern
% Benutzung: \begin{FMListingWithoutNumbers}[BREITE] ... \end{FMListingWithoutNumbers}
\lstnewenvironment{FMListingWithoutNumbers}[1][1]
{\lstset{style=FMListingWithoutNumbersStyle,linewidth=#1\linewidth}}
{}

% Arrow, e.g. for listings
\newcommand{\FMArrow}{$\curvearrowright$}

% Page header
% Usage: \FMPageHeader{SECTION}{SHORT_TITLE}
\newcommand{\FMPageHeader}[2]{
\lhead{
\begin{textblock}{1}(58,1)
\vspace{2px}
\end{textblock}
\begin{textblock}{30}[1.025,0](44,1)
\vspace{4px}
\hfill\textcolor{darkgray}{\textsc{\Large cat #1 | grep #2}}\\[-0.4cm]
\end{textblock}
\begin{textblock}{60}(0,0)
\vspace{10px}
\includegraphics[width=\textwidth,height=36px]{img/titellinie-oben.png}
\end{textblock}
}
}

% Produces a line with shadow
% Usage: \FMLine[WIDTH]
% WIDTH (optional) is a relative number between 0 and 1
\newcommand{\FMLine}[1][.67]{
\hspace*{2px}\textcolor{mediumgray}{\rule{#1\textwidth}{3px}}\\[-16px]
\textcolor{darkgray}{\rule{#1\textwidth}{3px}\\[-20px]}
}

\makeindex
