latex-wochenende/slides/chapter-04.en.md

213 lines
4.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@slide(layout=chapter-slide)
@number
4
@title
Project structure
@slide(layout=content-and-preview)
@title
Goal
@content
Create a bigger LaTeX project and …
* prevent LaTeX documents from growing monstrously <span class="emoji">👹</span>
* keep the overview over the project structure
@preview
![](svg/chapter-04/langes-dokument.jpg){style="padding: .2em; height: 100vh"}
@slide(layout=content-and-preview)
@title
Main file <span class="emoji">👑</span>
@content
* contains basic structure and front matter
* includes separate sections with \
`\input{path/to/file}`
``` {.lang-tex .hljs data-sourcefile=main.tex}
\documentclass{article}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\title{A Title}
\begin{document}
\maketitle
\tableofcontents
\input{section1.tex}
\input{section2.tex}
\end{document}
```
@preview
![](svg/chapter-04/main-orig.svg)
@slide(layout=content-and-preview)
@title
File with a section
@content
* contains **no preamble**
* contains **no** `\begin{document}` or `\end{document}`
``` {.hljs .lang-tex data-sourcefile=part1.tex}
\section{This is section 1}
A paragraph about the content
of section 1.
% …
```
``` {.hljs .lang-tex data-sourcefile=part2.tex}
\section{This is section 2}
A paragraph about the content
of section 2.
% …
```
@preview
![](svg/chapter-04/main-parts-crop.svg){.thin-padding}
@slide(layout=content-and-preview-with-category)
@category
Excursion
@title
Specifying file paths <span class="emoji">👣</span>
@content
* important for `\input{}`, but later also for other media types
* file and folder structure = tree structure <span class="emoji">🌳</span>
* with `\input{}`, you can specify the path relative to the main file
<p data-category="Caution!" class="fragment">In **LaTeX,** you have to use UNIX-style paths. They are separated by a forward slash: `path/to/file`. We will use those from here on.</p>
@preview
![](svg/chapter-04/tree-english-crop.svg)
@slide(layout=content-and-preview-with-category)
@category
Excursion
@title
Specifying file paths <span class="emoji">👣</span>
@content
<p data-category="Example">`main.tex` → `part1.tex`</p>
<div class="fragment">
`./part1.tex`
A **single dot `.`** represents the current folder (in this case: `latex`). It is optional, you could also write `part1.tex` here.
</div>
@preview
![](svg/chapter-04/relative-path-english-crop.svg)
@slide(layout=content-and-preview-with-category)
@category
Excursion
@title
Specifying file paths <span class="emoji">👣</span>
@content
<p data-category="Example">`main.tex` → `part1.tex` (in a subfolder)</p>
<pre class="fragment">./sections/part1.tex</pre>
@preview
![](svg/chapter-04/relative-path-subdir-english-crop.svg)
@slide(layout=content-and-preview-with-category)
@category
Excursion
@title
Specifying file paths <span class="emoji">👣</span>
@content
<p data-category="Example">`main.tex` → `part1.tex` (from one subfolder into a different subfolder)</p>
<div class="fragment">
<pre>../sections/part1.tex</pre>
**Two dots `..`** represent the parent folder of the current folder (in this case: `latex`, parent of `main`).
</div>
@preview
![](svg/chapter-04/relative-path-superdir-english-crop.svg)
@slide(layout=content-only)
@title
Compiling the project
@content
* **Only the main file** has to be compiled to get the complete PDF document.
* Error messages include a reference to the corresponding subfile.
* Subfiles cannot be compiled on their own as they dont have a preamble.
@slide(layout=content-and-preview)
@title
Outsourcing the preamble
@content
What do you think happens when we outsource the preamble into its own subfile?
Will the document compile?
++ **Yes, it will!** \
A simple way of keeping the main file even more organised.
@preview
![](svg/chapter-04/main-parts-preamble-crop.svg){.thin-padding}
@slide(layout=task)
@task-number
4
@title
A structured project
@content
You will find a file named `main.tex` in the folder `exercises/project-structure`.
* Extract the sections into their own files (`section1.tex`, `section2.tex`, and `section3.tex`) and insert them using the `\input` command.
* Have a look at the project archive, starting from `main.tex`.
@slide(layout=content-only-with-category)
@category
Demo
@title
Compiling larger projects
@content
* From now on, we will compile the file `main.tex` in the project root.
* To do so, right click on the file in TeXstudio and choose “Select as explicit root document” from the dropdown.
* Next, compile as usual.