From 0581584181585ad110c6239c139a9b7b2c407357 Mon Sep 17 00:00:00 2001 From: Florian Knoch Date: Mon, 9 May 2022 16:01:22 +0200 Subject: [PATCH] Update project structure exercises --- commands.tex | 2 +- content/project-structure.tex | 33 +++++++++---------- .../main-with-preamble.done.tex | 9 +++-- exercises/project-structure/main.done.tex | 9 +++-- exercises/project-structure/tasks.done.tex | 33 +++---------------- exercises/project-structure/tasks.raw.tex | 15 +++------ 6 files changed, 37 insertions(+), 64 deletions(-) diff --git a/commands.tex b/commands.tex index 2fab6cb..7539a59 100644 --- a/commands.tex +++ b/commands.tex @@ -86,12 +86,12 @@ % =========== % Code snippets with syntax highlighting. % TODO: Fix special character mess. +% Caution: Must not be used inside `\textbf{}' % % Arguments: % 1. Language. % 2. Source code. \newcommand\code[2]{% - % \mintinline{#1}{#2} \texttt{#2}% } diff --git a/content/project-structure.tex b/content/project-structure.tex index a34536b..daf7a2e 100644 --- a/content/project-structure.tex +++ b/content/project-structure.tex @@ -1,26 +1,25 @@ \chapter{Project structure} \label{sec:project-structure} -In the previous chapters, we have only seen very short \LaTeX{} examples. \LaTeX{} can of course also be used to create larger documents and projects, such as a thesis. -In order not to lose the overview in the source code and to avoid that source files become too long, a reasonable structuring of a larger \LaTeX{} project is advisable. For this purpose, the source code is divided into different files, which will be discussed in more detail in the following sections. +In the previous chapters, we have only seen very short \LaTeX{} examples. +\LaTeX{} can of course also be used to create larger documents and projects, such as a thesis. +In order not to lose the overview in the source code and to avoid that source files become too long, a reasonable structuring of a larger \LaTeX{} project is advisable. +For this purpose, the source code is divided into different files, which will be discussed in more detail in the following sections. \section{Main file} -In large projects, we typically use one main file, which is often called \file{main.tex}. It is, in a sense, the structural skeleton of the project, as it contains the basic structure including the preamble. The title, table of contents, as well as the individual chapters of a work are integrated in this main file (cf.\ \cref{lst:main-file}). The inclusion of the individual sections can be done either by \code{latex}{\textbackslash input\{...\}} or \code{latex}{\textbackslash include\{\textellipsis\}}. Both require the path to the file to be included as an argument. We will discuss the differences between the two commands later (see \cref{sec:input-vs-include}). +In large projects, we typically use one main file, which is often called \file{main.tex}. +It is, in a sense, the structural skeleton of the project, as it contains the basic structure including the preamble. +The title, table of contents, as well as the individual chapters of a work are integrated in this main file (cf.\ \cref{lst:main-file}). +The inclusion of the individual sections is typically done by the \code{latex}{\textbackslash input\{...\}} command +\footnote{There exists another command called \code{latex}{\textbackslash include\{\textellipsis\}} that works slightly differently. It requires you to specify the file to be included without a file extension. Besides this, a line break is added before the content of the partial file. Lastly, you cannot nest \code{latex}{\textbackslash include\{\textellipsis\}} statements. When you try to include a file that also includes a file, a compiler error will be thrown. \code{latex}{\textbackslash input\{\textellipsis\}} on the other hand is capable of such nested imports. In this script, we will present the \code{latex}{\textbackslash input\{\textellipsis\}} command only.} +with the file to be included as an argument. \example{lst:main-file}{project-structure/main-file}{Typical structure in a main file \LaTeX{}} -\section{Section files} -Section files are files that are included within the main file. In a thesis, for example, these can be individual chapters. You are free to decide how granular the division of the content into individual files should be. -The files that are included by the main file do not contain a preamble, since this is already present in the main file. Neither do the commands \code{latex}{\textbackslash begin\{document\}} and \code{latex}{\textbackslash end\{document\}} appear again. - -\section{Input or include?} -\label{sec:input-vs-include} - -Let us now turn to the differences between the two possible commands for including \LaTeX{} files. Briefly summarized, \code{latex}{\textbackslash include} and \code{latex}{\textbackslash input} have differences in the following three aspects: The way in which the path to the file to be included is specified, the possibility of nesting inclusions, and whether a new page is started for each section. - -If you use the command \code{latex}{\textbackslash input}, you can specify the file extension \mono{.tex}, but it is not mandatory. It is also possible to nest the inclusion of files: A file included with \code{latex}{\textbackslash input} can in turn include another file with the same command. The files that have been included are inserted in the finished document without starting a new page for the included section (cf. \cref{lst:main-file}). - -The command \code{latex}{\textbackslash include} behaves differently: Here, the file -extension \mono{.tex} \emph{must} be omitted. Nesting of embeddings is not -possible. Also, a new page is created for each included file. +\section{Partial files} +Partial files are files that are included within another file, most often the main file. +In a thesis, for example, these can represent individual chapters. +You are free to decide how granular the division of the content into individual files should be. +The files that are included by the main file do not contain a preamble, since this is already present in the main file. +Neither do the commands \code{latex}{\textbackslash begin\{document\}} and \code{latex}{\textbackslash end\{document\}} appear again. diff --git a/exercises/project-structure/main-with-preamble.done.tex b/exercises/project-structure/main-with-preamble.done.tex index 7978dc2..460ade1 100644 --- a/exercises/project-structure/main-with-preamble.done.tex +++ b/exercises/project-structure/main-with-preamble.done.tex @@ -9,8 +9,11 @@ \maketitle \tableofcontents -\include{section1} -\include{section2} -\include{section3} +\newpage +\input{section1} +\newpage +\input{section2} +\newpage +\input{section3} \end{document} \ No newline at end of file diff --git a/exercises/project-structure/main.done.tex b/exercises/project-structure/main.done.tex index 03310b9..5aea718 100644 --- a/exercises/project-structure/main.done.tex +++ b/exercises/project-structure/main.done.tex @@ -4,8 +4,11 @@ \maketitle \tableofcontents -\include{section1.done} -\include{section2.done} -\include{section3.done} +\newpage +\input{section1.done} +\newpage +\input{section2.done} +\newpage +\input{section3.done} \end{document} \ No newline at end of file diff --git a/exercises/project-structure/tasks.done.tex b/exercises/project-structure/tasks.done.tex index 0d51689..acff4d5 100644 --- a/exercises/project-structure/tasks.done.tex +++ b/exercises/project-structure/tasks.done.tex @@ -1,49 +1,24 @@ \begin{enumerate} \item \textbf{Put the sections of the file into separate files, named - \file{section1.tex}, \file{section2.tex}, and \file{section3.tex}. Include - them using the \code{latex}{\textbackslash include} command.} + \file{section1.tex}, \file{section2.tex}, and \file{section3.tex} and insert them using the} \code{latex}{\textbackslash input} \textbf{command. (In TeXstudio, make sure that you select the main file as the file to be compiled by right-clicking on it and selecting \enquote{Select as explicit root document.})} \begin{figure}[H] \codeblock{latex}{exercises/project-structure/main-with-preamble.done.tex} \caption{\file{main.tex}} \end{figure} + \begin{figure}[H] \codeblock{latex}{exercises/project-structure/section1.done.tex} \caption{\file{section1.tex} (analogous for the other sections)} \end{figure} - \item \textbf{Which command becomes superfluous when you use - \code{latex}{\textbackslash include}?} \\ - \code{latex}{\textbackslash include} makes every included file appear on a - new page. Hence the command \code{latex}{\textbackslash newpage} becomes - superfluous. - \item \textbf{Can the preamble also be excluded? If no, why? If yes, when - can outsourcing the preamble be useful?} + \item \textbf{Can the preamble also be excluded? If no, why? If yes, when can outsourcing the preamble be useful?} - The preamble can also be outsourced, like in task 1. In real-world - \LaTeX{} projects we often make use of numerous packages that need to be + The preamble can also be outsourced, like in task 1. In real-world \LaTeX{} projects, we often make use of numerous packages that need to be configured by additional commands within the preamble. Therefore, it is advisable to outsource the preamble. On top of that, this is useful because the file with the most-commonly used packages can be moved from one project to another without needing to rewrite the preamble every time. - - \item - \textbf{Add the command \code{latex}{\textbackslash - includeonly\{section2\}} to the preamble. Compile the document again, and - check what has changed. What does the command do and how can it be helpful - in a larger project? } - - The command \code{latex}{\textbackslash includeonly\{section2\}} does - exactly what the name already says. During compilation, only the - \code{latex}{\textbackslash include} statements that contain file names - that appear in \code{latex}{\textbackslash includeonly\{file1,file2, …\}} - are included. - - This can be useful for larger projects, when the compile time becomes - longer since by using the \code{latex}{\textbackslash includeonly} only the - files can be included which we are currently working in. Before the final - compilation we can delete the \code{latex}{\textbackslash includeonly} - command and end up with our complete \acro{PDF}. \end{enumerate} \ No newline at end of file diff --git a/exercises/project-structure/tasks.raw.tex b/exercises/project-structure/tasks.raw.tex index 9c3dd8c..5b4f819 100644 --- a/exercises/project-structure/tasks.raw.tex +++ b/exercises/project-structure/tasks.raw.tex @@ -1,13 +1,6 @@ \begin{enumerate} - \item \textbf{Put the sections of the file into separate files, named - \texttt{section1.tex}, \texttt{section2.tex}, and \texttt{section3.tex}. - Include them using the \code{\textbackslash include} command.} - \item \textbf{Which command becomes superfluous when you use - \code{\textbackslash include}} - \item \textbf{Can the preamble also be excluded? If no, why? If yes, why can - outsourcing the preamble be useful?} - \item \textbf{Add the command \code{\textbackslash includeonly\{section2\}} to - the - preamble. Compile the document again, and check what has changed. What does - the command do and why can it be helpful in a larger project? } + \item \textbf{Put the sections of the file into separate files, named} + \file{section1.tex}, \file{section2.tex}\textbf{, and} \file{section3.tex}. + \textbf{Include them using the} \code{latex}{\textbackslash input} \textbf{command. (In TeXstudio, make sure that you select the main file as the file to be compiled by right-clicking on it and selecting \enquote{Select as explicit root document.})} + \item \textbf{Can the preamble also live in its own file? If no, why? If yes, why can outsourcing the preamble be useful?} \end{enumerate}