diff --git a/.gitignore b/.gitignore index c3c875c..820577f 100644 --- a/.gitignore +++ b/.gitignore @@ -80,3 +80,6 @@ _minted* *.swo main.pdf +exercise-mode.tex +public + diff --git a/Makefile b/Makefile index 4b05ec2..e3f5140 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,60 @@ -default: all +SHELL=/bin/bash -all: listings main.tex +default: preview + +# Remove builds and LaTeX output. +clean: + @echo Cleaning up temporary files. + @rm -rf public/* + @rm -f {main,script-only}.{aux,loc,log,out,pdf,soc,toc} + +# Compile listings (only needed when listings have changed) +listings: listings/**/* ./compile_listings - pdflatex --shell-escape main.tex - -latex: main.tex - pdflatex --shell-escape main.tex +# Compile a preview PDF containing all contents +preview: main.tex + echo "\newcommand\exercisemode{any}" > exercise-mode.tex + pdflatex -shell-escape main.tex + @echo + @echo + @echo Run \'make publication\' a few times to generate PDF and ZIP file for publication. + +# Build all PDF and ZIP variants +publication: publication-pdf-without-exercises publication-pdf-with-exercises publication-pdf-with-solutions publication-zip-with-exercises publication-zip-with-solutions + +# +# Building blocks from here on: +# + +# Directory for files to be published +publication-dir: + mkdir -p public/ + +# Compile a printable PDF without exercises +publication-pdf-without-exercises: publication-dir main.tex + echo "\newcommand\exercisemode{none}" > exercise-mode.tex + pdflatex -shell-escape -jobname=script-only main.tex + mv script-only.pdf public/ + +# Compile a printable PDF with exercises and without solutions +publication-pdf-with-exercises: publication-dir main.tex + echo "\newcommand\exercisemode{exercises}" > exercise-mode.tex + pdflatex -shell-escape -jobname=script-with-exercises main.tex + mv script-with-exercises.pdf public/ + +# Compile a printable PDF with exercises and solutions +publication-pdf-with-solutions: publication-dir main.tex + echo "\newcommand\exercisemode{solutions}" > exercise-mode.tex + pdflatex -shell-escape -jobname=script-with-solutions main.tex + mv script-with-solutions.pdf public/ + +# Build a ZIP file with tasks and without solutions +publication-zip-with-exercises: publication-dir main.tex + zip public/project-with-exercises main.tex praeamble.tex commands.tex literature.bib content/* graphics/* listings/**/*.{tex,pdf} exercises/**/{task.tex,*.raw.tex} + +# Build a ZIP file with tasks and solutions +publication-zip-with-solutions: publication-dir main.tex + zip public/project-with-solutions main.tex praeamble.tex commands.tex literature.bib content/* graphics/* listings/**/*.{tex,pdf} exercises/**/{task.tex,*.done.tex} + + diff --git a/commands.tex b/commands.tex index d15ea5f..0a49084 100644 --- a/commands.tex +++ b/commands.tex @@ -95,4 +95,64 @@ \caption{#4} \label{#1} \end{figure} -} \ No newline at end of file +} + +% Exercise mode +% ============= +% The exercise mode can be chosen by writing one of the following to the exercise-mode.tex file before compilation: +% \newcommand\exercisemode{none} % for a blank script without exercises +% \newcommand\exercisemode{exercises} % for a script with exercises only +% \newcommand\exercisemode{solutions} % for a script with solutions only +% \newcommand\exercisemode{any} % for a script containing all available material +% The following lines include that file or make \exercisemode default to 'any' so that any derivatives of this project will work even without the file. +\IfFileExists{exercise-mode.tex}{ + \input{exercise-mode.tex} +}{ + \newcommand\exercisemode{any} +} + +% Exercises +% ========= +% Includes the task.tex file within the given subfolder of exercises and adds a heading. +\newcommand\exercise[1]{ + \ifthenelse{\equal{\exercisemode}{none}}{ + % Exercises disabled. + }{ + \subsection*{Übung} + \input{exercises/#1/task.tex} + } +} + +% Exercise Material +% ================= +% Takes a project-relative path, and inserts matching exercise material and/or solutions, depending on the exercise mode. +\newcommand\exercisematerial[1]{ + % Mode 'exercises': raw material only + \ifthenelse{\equal{\exercisemode}{exercises}}{ + \IfFileExists{#1.raw.tex}{ + \input{#1.raw.tex} + }{} + }{} + % Mode 'solutions': completed material only + \ifthenelse{\equal{\exercisemode}{solutions}}{ + \IfFileExists{#1.done.tex}{ + \input{#1.done.tex} + }{} + }{} + % Mode 'any': all existing material. If both raw and completed material exist, headings are added for each. + \ifthenelse{\equal{\exercisemode}{any}}{ + \IfFileExists{#1.raw.tex}{ + \IfFileExists{#1.done.tex}{ + \subsubsection*{Vorschau des ungelösten Materials} + }{} + \input{#1.raw.tex} + }{} + \IfFileExists{#1.done.tex}{ + \IfFileExists{#1.raw.tex}{ + \subsubsection*{Vorschau des gelösten Materials} + }{} + \input{#1.done.tex} + }{} + }{} +} + diff --git a/exercises/text-markup/bar.raw.tex b/exercises/text-markup/bar.raw.tex new file mode 100644 index 0000000..d4d023b --- /dev/null +++ b/exercises/text-markup/bar.raw.tex @@ -0,0 +1 @@ +Nonsense. diff --git a/exercises/text-markup/foo.done.tex b/exercises/text-markup/foo.done.tex new file mode 100644 index 0000000..2a8b90f --- /dev/null +++ b/exercises/text-markup/foo.done.tex @@ -0,0 +1,2 @@ +\emph{Lorem ipsum} dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. \emph{Excepteur} sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + diff --git a/exercises/text-markup/foo.raw.tex b/exercises/text-markup/foo.raw.tex new file mode 100644 index 0000000..e7ef7d1 --- /dev/null +++ b/exercises/text-markup/foo.raw.tex @@ -0,0 +1,2 @@ +Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. + diff --git a/exercises/text-markup/task.tex b/exercises/text-markup/task.tex new file mode 100644 index 0000000..ddaf92f --- /dev/null +++ b/exercises/text-markup/task.tex @@ -0,0 +1,6 @@ +\begin{enumerate} + \item Erste Aufgabe, lorem ipsum + \item Zweite Aufgabe, dolor sit amet +\end{enumerate} +\exercisematerial{exercises/text-markup/foo} +\exercisematerial{exercises/text-markup/bar} diff --git a/main.tex b/main.tex index 6377ed1..dcf8a2d 100644 --- a/main.tex +++ b/main.tex @@ -25,6 +25,7 @@ \input{content/project-structure.tex} \input{content/special-characters.tex} \input{content/text-markup.tex} +\exercise{text-markup} \input{content/formatting-paragraphs.tex} \input{content/lists.tex} \input{content/maths.tex}