\chapter{How does \LaTeX{} function?}
\label{sec:basic-functionality}

\todo{Really ``function'', not ``work''?}

Word processing and document creation programs use different approaches to create a document based on an edited file.
When working with Microsoft Word, the rule is: a document exported as \acro{PDF} looks exactly like the source document in Word. Where a graphic is placed in Word, it is also found in the \acro{PDF}. Adjustments to the appearance in MS Word and other popular programs thus result in a direct visual change in the resulting export. This type of formatting is called \emph{What you see is what you get} (\acro{WYSIWYG} for short). Content and structure are closely linked.

\LaTeX{}, on the other hand, works according to the principle \emph{What you get is what you mean} (\acro{WYGIWYM} for short). Content and structure are separated more clearly.
The content is placed in a document in plain text form, together with so-called \emph{commands}. The combination of content text and commands is also called \emph{source} text. To customize the presentation of the content, we do not change the content text itself, but add appropriate commands instead. These are processed by a \emph{compiler}, which adjusts the resulting appearance depending on the command. Line by line, the compiler processes text and commands from our source code. When all the source code has been processed by the compiler, we get the final document. There are different export options, but most of the time we output the document as a \acro{PDF} - just like Word.

%Als kurzes Beispiel für einen Befehl dient uns hier das Hervorheben von Wörtern oder Sätzen. Der Befehl lautet \mintinline{latex}{\emph{}}. Den Text, den wir hervorheben möchten, schreiben wir im Quellcode innerhalb der geschweiften Klammern, etwa so: \mintinline{latex}{\emph{Guten Tag!}}. Im resultierenden \acro{PDF} erscheint dieser Text dann kursiv: \emph{Guten Tag!} Von dem Befehlsbezeichner und den Sonderzeichen ist keine Spur mehr zu sehen. Wir schreiben also keinen kursiven Text innerhalb des Quellcodes, sondern teilen dem Compiler einfach mit, dass bestimmte Wörter doch bitte hervorgehoben werden sollen.

As a brief example for a command, we shall use the highlighting of words or sentences. The command is \mintinline{latex}{\emph{}}. We write the text we want to highlight inside the curly brackets in the source code, like this: \mintinline{latex}{\emph{Good morning!}}. In the resulting PDF, this text will appear in italics: \emph{Good morning!} There is no trace of the command identifier and the special characters. You can see, we are not writing italic text inside the source code, we just tell the compiler that certain words should be highlighted by use of a command.

%Dieses einfache Beispiel verdeutlicht eine Stärke des \acro{WYGIWYM}-Prinzips.  Wir markieren Textelemente auf der semantischen Ebene und können die zugehörigen typographischen Anpassungen an zentraler Stelle vornehmen -- oder lassen \LaTeX{} die Konfiguration selbst erledigen. Wenn wir etwa die Art und Weise des Hervorhebens ändern möchten, dann können wir dies zentral konfigurieren. An allen Stellen, wo \mintinline{latex}{\emph{}} verwendet wird, wird das Endresultat entsprechend angepasst. Es besteht keine Notwendigkeit, an jeder einzelnen Stelle Anpassungen vorzunehmen. Das Prinzip ist ähnlich zu Formatvorlagen in Office-Programmen, wenn auch konsequenter und mächtiger. 

This simple example illustrates a strength of the \acro{WYGIWYM} principle. 
We mark text elements on the semantic level and can make the associated typographic adjustments centrally - or let \LaTeX{} do the configuration itself.
For instance, if we want to change the way highlighting is done, we can configure this centrally. At all places where \mintinline{latex}{\emph{}} is used, the final result will be adjusted accordingly. There is no need to make adjustments at each individual place. The principle is similar to style sheets in Office programs, although more consistent and powerful.


\section{What do we need to use \LaTeX{}?}
\label{subsec:what-we-need}

%Oxford komma wie?
If we want to generate a PDF document with LaTeX, we need at least two programs. One to create the source code, and a second to process the source code. The latter is the already mentioned compiler.

In principle, a simple text editing program is sufficient for creating the source code. Most operating systems already include such programs. Maybe you are already used to applications like Notepad++\footnote{Available at \url{https://notepad-plus-plus.org/}.}, these are usable as well. Then there are advanced programs like TeXstudio\footnote{Available at \url{https://www.texstudio.org/}.} or Texmaker\footnote{Available at \url{https://www.xm1math.net/texmaker/}.}, which integrate additional functions that facilitate the use of commands. You are free to choose. 

%Zum Kompilieren des Quelltexts wird, wie bereits erwähnt, ein Compiler benötigt. Der Compiler ist meist Teil einer Sammlung von Programmen und Paketen, die zusammen eine \LaTeX-Distribution bilden. Auf die Hilfsprogramme werden wir für den Moment nicht näher eingehen.\footnote{Eines dieser Hilfsprogramme kommt später im Kapitel \ref{sec:literature} zum Einsatz, wenn wir Literatur referenzieren.} Die enthaltenen Pakete stellen verschiedene Befehle zur Verfügung.

% Kleine Anpassung, emph's hinzugefügt
As mentioned before, we need a compiler to be able to compile our source code.
The compiler is usually part of a collection of \emph{programs} and \emph{packages}, which are together called a \LaTeX-\emph{distribution}. The included packages provide various additional commands. For now, we will skip over the many programs\footnote{We will get to know one of these helper programs later on, in \ref{sec:literature}, when we are citing literature.}. 

% usable? Ich dachte an ein Analog zu "well maintained", aber passt das vielleicht einfach selbst?
Multiple different usable distributions exist. Known distributions are MiK\TeX,\footnote{For Windows, macOS and Linux. Available at \url{https://miktex.org/}.} Mac\TeX\footnote{For macOS and Linux. Available at \url{https://www.tug.org/mactex/}.} and \TeX{} Live\footnote{For Windows, macOS and Linux. Available at \url{https://www.tug.org/texlive/}.}. It is best to install one of them right away. The installation may take several hours. For this reason, some distributions are available for download in a small and a full version. 
The full version contains all packages, while the small version downloads packages only when they are needed.
Unfortunately, we cannot take away the decision if you would rather wait for the download at the beginning or later while you are working. %Oxford-Komma?

%Wir verwenden den Compiler einer Distribution unserer Wahl. Bekannte Distributionen sind MiK\TeX,\footnote{Für Windows, macOS und Linux. Verfügbar unter \url{https://miktex.org/}.} Mac\TeX\footnote{Für macOS und Linux. Verfügbar unter \url{https://www.tug.org/mactex/}.} und \TeX{} Live.\footnote{Für Windows, macOS und Linux. Verfügbar unter \url{https://www.tug.org/texlive/}.}
%Installiert euch am besten gleich eine davon. Die Installation kann unter Umständen mehrere Stunden dauern. Manche Distributionen gibt es daher als kleine und als vollständige Variante zum Download.  Die vollständige Variante enthält alle Pakete, während in der normalen Version Pakete erst dann heruntergeladen werden, wenn sie benötigt werden. Die Entscheidung, ob ihr lieber zu Beginn oder später während des Arbeitens auf den Download wartet, können wir euch leider nicht abnehmen. 

\section{The commands}
\label{subsec:command-structure}
The commands used in source code follow a general structure:
\begin{minted}{xml}
\<command>[<optional_parameters>]{<mandatory_parameters>}
\end{minted}
A command can use several optional and/or mandatory parameters. Some commands have no mandatory parameters at all. Some examples are shown in \cref{tbl:latex-commands}.

\begin{table}[h!]
	\widebox{
		\begin{tabular}{@{}p{\widefigurewidth}p{\widefigurewidth}@{}}
			\toprule
			Command                                                  & Effekt                             \\
			\midrule
			\mintinline{latex}{\newpage}                              & inserts a new page           \\
			\mintinline{latex}{\textbf{Text}}                         & prints the text in bold font \\
			\mintinline{latex}{\usepackage[utf8]{inputenc}}           & specifies the text encoding to \acro{UTF-8}  \\
			\mintinline{latex}{\documentclass[a4paper,12pt]{article}} & specifies the document class  \\
			\mintinline{latex}{\frac{3}{4}}               & inserts a mathematical fraction  \\
			\bottomrule
		\end{tabular}
	}
	\caption{Examples for \LaTeX-commands}
	\label{tbl:latex-commands}
\end{table}

If a command allows multiple optional parameters that accept the same input types, it is necessary to specify which parameter is meant. For example, the command for embedding graphics accepts optional parameters for width and height. If \mintinline{tex}|[12cm, 4cm]| were entered, it would be unclear which value is intended for which parameter. To make the assignment more concrete, we can specify the parameters explicitly:
\begin{minted}{tex}
\includegraphics[width=12cm, height=4cm]{picture.png}
\end{minted}

As the examples already show, there are many different commands that can be used. Some are intended for use in mathematical formulas, others allow the inclusion of graphics. At the beginning it will take some getting used to. Remembering all the relevant commands is hard, but after some practice and patience simple documents can be created in no time.