@slide(layout=chapter-slide) @number 3 @title Complex projects @slide(layout=content-and-preview) @title Goal @content Create a bigger LaTeX project and … * prevent LaTeX documents from growing monstrously 👹 * keep the overview over the project structure @preview ![](svg/project-structure/langes-dokument.jpg){style="padding: .2em; height: 100vh"} @slide(layout=content-and-preview) @title Main file 👑 @content * contains basic structure * 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/project-structure/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/project-structure/main-parts-crop.svg){.thin-padding} @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 don’t have a preamble. @slide(layout=task) @task-number 3 @title A structured project @content ::: {.box .warning} **Close all open tabs** from previous tasks. ::: You will find a file named `main.tex` in the folder `exercises/project-structure`. * Put the sections of the file into separate files, named `section1.tex` and `section2.tex`. * Include them using the `\input` command. * Move the preamble to its own file in a similar fashion. * Finally, have a look at the general project archive, starting from `main-exercises.tex` (in the root folder of the project archive). How do we include the different sections here? @slide(layout=extra-content-only) @title Embedding PDF documents @content The `pdfpages` package allows for embedding entire PDF documents. ``` {.lang-tex .hljs} \includepdf[pages={-}]{} ``` Further options make multiple pages appear in tiles and change the orientation to landscape, among other things. See the [package documentation](https://www.ctan.org/pkg/pdfpages) for a complete list. @slide(layout=extra-wide-content) @title Macros @content It may be helpful to specify custom macros for often-used code. ``` {.lang-tex .hljs} \newcommand{\}[][]{} ``` In the script, we used these macros for margins and acronyms (see `commands.tex` for more examples): ``` {.lang-tex .hljs} \newcommand{\widefiguremargin}{-.22\textwidth} \newcommand{\acro}[1]{\textsc{\lowercase{#1}}} ``` It is also possible to customize existing commands. $\LaTeX$ even allows you to use programming patterns like variables, conditionals, and loops. To learn more, have a look at [this WikiBook chapter](https://en.wikibooks.org/wiki/LaTeX/Macros). @slide(layout=content-and-preview-with-category) @category Excursion @title Specifying file paths 👣 @content * important for `\input{}`, but later also for other media types * file and folder structure = tree structure 🌳 * with `\input{}`, you can specify the path relative to the main file

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.

@preview ![](svg/project-structure/tree-english-crop.svg) @slide(layout=content-and-preview-with-category) @category Excursion @title Specifying file paths 👣 @content

`main-exercises.tex` → `praeamble.tex`

::: {.fragment} `./praeamble.tex` A **single dot ‘`.`’** represents the current folder (in this case: `latex-script`). It is optional, you could also write `praeamble.tex` here. ::: @preview ![](svg/project-structure/relative-path-english-crop.svg) @slide(layout=content-and-preview-with-category) @category Excursion @title Specifying file paths 👣 @content

`main-exercises.tex` → `basic-document-structure.tex` (in a subfolder)

./content/basic-document-structure.tex
@preview ![](svg/project-structure/relative-path-subdir-english-crop.svg) @slide(layout=content-and-preview-with-category) @category Excursion @title Specifying file paths 👣 @content

`basic-functionality.tex` → `graphics.raw.tex`

(`basic-functionality.tex` is imported into `main-exercises.tex`) ::: {.fragment} `./exercises/graphics/graphics.raw.tex`

Paths are always relative to the root document that imports other files as fragments.

::: @preview ![](svg/project-structure/relative-path-transitive-english-crop.svg) @slide(layout=content-only) @title Note @content + From now on, we will compile the file `main-exercises.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.