@slide(layout=chapter-slide)

@number
2

@title
Basic documents

@slide(layout=wide-content)

@title
Commands

@content
General structure of a command:

``` {.hljs .lang-txt}
\<command>[<optional_parameters>]{<obligatory_parameters>}
```

++ A few examples:

``` {.lang-tex .tex .hljs .fragment}
\newpage % inserts a new page
\textbf{bold text} % formats the text bold
\documentclass[a4paper,12pt,landscape]{article} % configures the document class
\frac{1}{4} % inserts a mathematical fraction
```


@slide(layout=content-only)

@title
Backslash

@content
Assuming a German keyboard layout, you get the backslash by pressing

<kbd>AltGr</kbd>&nbsp;+&nbsp;<kbd>ß</kbd>&nbsp;(Windows/Linux)

<kbd>Alt</kbd>&nbsp;+&nbsp;<kbd>Shift</kbd>&nbsp;+&nbsp;<kbd>7</kbd>&nbsp;(MacOS)


@slide(layout=content-and-preview)

@title
Preamble & document environment

@content
<p style="text-indent: -1.3em"><span class="emoji">👁</span> Every LaTeX document is composed of</p>

* a **preamble:** global settings (document class, encoding, language, page format, additional packages, …) and
* a **document environment:** content of the document.

``` {.lang-tex .hljs .fragment}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}

\begin{document}
Hello world!
\end{document}
```

@preview
![](svg/basic-documents/hello-crop.svg)


@slide(layout=wide-content)

@title
Document class

@content
``` {.lang-tex .hljs}
\documentclass[<parameter>]{<document_class>}
```

For example:

``` {.lang-tex .hljs}
\documentclass[10pt,a5paper,landscape]{article}
```


@slide(layout=content-only)

@title
Encoding

@content
``` {.lang-tex .hljs}
\usepackage[utf8]{inputenc}
\usepackage[t1]{fontenc}
```

* The character encoding determines which characters are available.
* **ASCII** contains no special characters like German umlauts.
* **UTF-8** is a universal encoding.


@slide(layout=content-only)

@title
Language

@content
``` {.lang-tex .hljs}
\usepackage[ngerman]{babel}
```

* The package **`babel`** provides language-specific information (e.&thinsp;g., hyphenation, special characters, font changes, translated labels like ‘chapter,’ ‘table of contents’ or ‘figure’).
* **`ngerman`** is the German new spelling.


@slide(layout=content-and-preview)

@title
Continuous Text

@content
``` {.lang-tex .hljs}
Continous text can be written directly ↲
in the source code. ↲
Simple line breaks ↲
are ignored, ↲
just as     multiple space characters. ↲
↲
An empty line creates a new paragraph ↲
which has an indentation by default. ↲
Manual line breaks can be forced ↲
using two backslashes, but this use ↲
is strongly discouraged \\ ↲
within continuous text.
```

@preview
![](svg/basic-documents/paragraphs-crop.svg)


@slide(layout=content-and-preview)

@title
Comments

@content
After a percent sign, the rest of the line is ignored by the compiler. It is called a comment and does not appear in the resulting document.

``` {.lang-tex .hljs}
% profile start
Name: Donald Knuth \\
Date of birth: \\ % TODO: insert
Place of birth: Milwaukee, Wisconsin
% profile end
```

Shortcuts: <kbd>Ctrl</kbd> + <kbd>T</kbd> and <kbd>Ctrl</kbd> + <kbd>U</kbd>

@preview
![](svg/basic-documents/comments-crop.svg)


@slide(layout=content-and-preview-with-category)

@category
Caution!

@title
Reserved characters

@content
Some characters do things in LaTeX:

`# $ % ^ & _ { } ~ \`

``` {.lang-tex .hljs}
50% is one half.
```

Solution: prefix with ‘`\`’:

``` {.lang-tex .hljs}
50\% is one half.
```

Does not work for ‘`\\`’, use `\textbackslash` instead. <span class="fragment">Also: Consider using a thin space between numbers and units (`50\,\%`).</span>

@preview
![](svg/basic-documents/reserved-characters-crop.svg)


@slide(layout=content-and-preview)

@title
Sections and chapters

@content
Texts are structured by beeing subdivided in sections and chapters. Always available:

``` {.lang-tex .hljs}
\section{Level 1}
\subsection{Level 2}
\subsubsection{Level 3}
\paragraph{Level 4}
\subparagraph{Level 5}
```

Additionally, for some document classes:

``` {.lang-tex .hljs}
\chapter{Chapter}
\part{Part}
```

@preview
![](svg/basic-documents/sections-crop.svg)


@slide(layout=wide-content)

@title
Title page

@content
``` {.lang-tex .hljs data-source=title.tex}
\title{The World of Truffles}
\author{Fooboar Rüssel \and Fachschaft WIAI}
\date{\today}
\begin{document}
\maketitle
\end{document}
```

* The values for the entries are stored in the preamble.
* `\maketitle` typesets the title page within the document environment.
* The exact appearance depends on the document class.
* Multiple authors can be joined with `\and`.
* If no date is given, the current date will be used. A different date can be defined with `\date{}`.


@slide(layout=content-and-preview)

@title
Front matter

@content
``` {.lang-tex .hljs data-source=title.tex}
\documentclass{article}
\usepackage{babel}
\title{The World of Truffles}
\author{Fooboar Rüssel 
\and Fachschaft WIAI}
\date{\today}

\begin{document}
    \maketitle
    \section{Truffle hunt}
    \subsection{Hunt with a pig}
    \subsection{Hunt without a pig}
    Why would you do that?
    \section{Truffle recipes}
    My favorite recipe
\end{document}
```

@preview
![](svg/basic-documents/title-orig.svg)


@slide(layout=content-only)

@title
Registers

@content
``` {.lang-tex .hljs}
\tableofcontents
\listoffigures
\listoftables
```

* automatic numbering
* elements with an asterisk (`*`) are hidden from the register: e.&thinsp;g. `\section*{}`.
* **generally requires two rounds of compilation**


@slide(layout=content-and-preview)

@title
Table of contents

@content
``` {.lang-tex .hljs data-source=title.tex}
\documentclass{article}
\usepackage{babel}
\begin{document}
    \tableofcontents
    \section{Truffle hunt}
    The first section.
    \subsection{Hunt with a pig}
    A subsection.
    \subsection{Hunt without a pig}
    Another subsection.
    \subsubsection[But why?]{Why would 
    you do that?}
    Sub-subsection.
    \section{Truffle recipes}
    My favorite recipe
\end{document}
```

@preview
![](svg/basic-documents/contents-crop.svg)


@slide(layout=wide-task)

@task-number
2

@title
Structure your document and text

@content
::: {.box .warning}
**Close all open tabs** from previous tasks.
::: 

* Open the file `document-structure.tex`. It is located in the directory `exercises/basic-document-structure`. 
* Wrap the entire text in a **document** environment and insert the following **preamble**.

``` {.lang-tex .hljs}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
```

* As you may already have noticed, **paragraphs** are marked as ‘`\\`’. Use real paragraphs instead.
* Time to structure our document! Use LaTex commands to declare all **headings** (`\section`, `\subsubsection`, etc.).
* Add a **table of contents** to your document.


@slide(layout=extra-wide-content)

@title
Document classes

@content
* There are also other document classes than `article`.
* Based on the document class, the layout of the generated pdf file changes.
* Normally spelled classes adhere to American English layout norms.
* **`scr`** document classes usually adhere to European layout norms.

Following document classes are available:

* **`scrartcl`, `article`** for short documents
* **`scrreprt`, `report`** for longer documents
* **`scrbook`, `book`** for books
* **`beamer`** for presentations


@slide(layout=extra-wide-content)

@title
Languages

@content
A document can use multiple languages at once:

``` {.lang-tex .hljs}
\usepackage[ngerman, swedish, ukrainian, greek, english]{babel}
```

To switch languages:

``` {.lang-tex .hljs}
\selectlanguage{<language a>}
\selectlanguage{<language b>}
```

Embedded Text in another language:

``` {.lang-tex .hljs}
\selectlanguage{<language a>}
\foreignlanguage{<language b>}{Text of language B in a text of language A}
```


@slide(layout=extra-content-and-preview)

@title
Languages&hairsp;—&hairsp;an example

@content
``` {.lang-tex .hljs}
\today
\selectlanguage{ngerman}
\today
\selectlanguage{swedish}
\today
\selectlanguage{ukrainian}
\today
\selectlanguage{greek}
\today
\selectlanguage{english}
\today
```

@preview
![](svg/basic-documents/languages-crop.svg)


@slide(layout=extra-content-and-preview)

@title
Headlines and the table of contents

@content
With an asterisk, there is no numbering and no entry in the table of contents:

``` {.lang-tex .hljs}
\section*{No entry in table of contents}
```

You can also provide an alternative title for the table of contents:

``` {.lang-tex .hljs}
\section[Entry in table of contents]
{Actual chapter heading}
```

@preview
![](svg/basic-documents/sections-differently-crop.svg)


@slide(layout=extra-content-only)

@title
Headers and footers

@content
The `fancyhdr` package helps us with that.

``` {.lang-tex .hljs}
% activate in general
\pagestyle{fancy}     

% apply to the first page as well
\thispagestyle{fancy} 

% reset values
\fancyhead{} % and/or \fancyfoot{}
\fancyhead[L]{Left header}
\fancyfoot[C]{Center footer}
\fancyfoot[R]{\thepage}
```

A comprehensive tutorial can be found on [Overleaf](https://www.overleaf.com/learn/latex/Headers_and_footers).


@slide(layout=wide-task)

@task-number
2x

@title
Make it fit your needs

@content
+ Add a **title** to the document.
+ Make today's date appear in a **language of your choice**.
+ **Hide** one section title in the table of contents.
+ Add a **short title** to a different section title.
+ Split the text in **two columns** (keyword: `twocolumn`).
+ Add a **header** with the title on the right and a **footer** with the page number on the left.
+ Try out what changes when you change the **document class**.
+ Research the possibilities of [traditional](https://hartwork.org/beamer-theme-matrix/) and [modern](https://gitlab.cs.fau.de/i4/tex/i4neo) **beamer presentation templates**.
