103 lines
6.9 KiB
TeX
103 lines
6.9 KiB
TeX
\chapter{How does \LaTeX{} work?}
|
||
\label{sec:basic-functionality}
|
||
|
||
Word processing and document creation programs have to decide how to translate user input into a document layout.
|
||
There are different concepts to approach this topic.
|
||
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 Word and other popular programs thus result in a direct visual change.
|
||
This type of formatting is called \emph{What you see is what you get} (\acro{WYSIWYG} for short).
|
||
Content and formatting 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 formatting are separated more clearly.
|
||
The content is placed in a document in plain text form, together with so-called \emph{commands}.
|
||
The combination of text content and commands is also called \emph{source} code.
|
||
|
||
To customize the presentation of the content, we do not set the text appearance 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 in Word.
|
||
|
||
As a brief example for a command, we shall use the emphasis of words or sentences.
|
||
The command is \code{latex}{\textbackslash emph\{\}}.
|
||
We write the text we want to emphasize inside the curly braces in the source code, like this:
|
||
\code{latex}{\textbackslash emph\{Good morning!\}}.
|
||
In the resulting \acro{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 emphasized by the use of a command.
|
||
|
||
This simple example illustrates a strength of the \acro{WYGIWYM} principle.
|
||
We mark text elements on a 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 once.
|
||
At all places where \code{latex}{\textbackslash emph\{\}} is used, the final result will be adjusted accordingly.
|
||
There is no need to make adjustments at each occurrence of an emphasized word.
|
||
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}
|
||
|
||
If we want to generate a \acro{PDF} document with \LaTeX{}, we need at least two programs.
|
||
One to create the source code, and a second one 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 provide such programs out of the box.
|
||
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 \TeX{}studio\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, but we recommend to use \TeX{}studio.
|
||
|
||
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}\textit{.}
|
||
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.}
|
||
|
||
Multiple different \LaTeX{} distributions exist.
|
||
Some of the well-known ones 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.
|
||
|
||
\section{The commands}
|
||
\label{subsec:command-structure}
|
||
The commands used in source code follow a general structure:
|
||
\codeblock{xml}{listings/basic-functionality/command-structure.txt}
|
||
|
||
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 & Effect \\
|
||
\midrule
|
||
\code{latex}{\textbackslash newpage} & inserts a new page \\
|
||
\code{latex}{\textbackslash textbf\{Text\}} & prints the text in bold font \\
|
||
\code{latex}{\textbackslash usepackage[utf8]\{inputenc\}} & sets the text encoding to \acro{UTF-8} \\
|
||
\code{latex}{\textbackslash documentclass[a4paper,12pt]\{article\}} & specifies the document class \\
|
||
\code{latex}{\textbackslash 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 similar inputs, it is sometimes necessary to specify which parameter is meant.
|
||
For example, the command for embedding graphics accepts optional parameters for width and height.
|
||
If \mono{[12cm, 4cm]} were entered, it would be unclear which value is intended for which parameter.
|
||
To make the assignment more concrete, it is possible to specify the parameters
|
||
explicitly:
|
||
\codeblock{latex}{listings/basic-functionality/parameters.tex}
|
||
|
||
As the examples already show, many different commands can be used.
|
||
Some are intended for use in mathematical formulas, others allow the inclusion of graphics.
|
||
In the beginning, it will take some getting used to.
|
||
However, you don’t have to learn every single command by heart: As soon as you remember the most important commands, you can easily create simple documents and look up everything else.
|
||
|