From 4073b4992b38795fde1d5b3aee7d405d6f6e3493 Mon Sep 17 00:00:00 2001 From: Christian Kremitzl Date: Sun, 22 May 2022 10:44:06 +0200 Subject: [PATCH] Move source code listings chapter after graphics and tables. --- onpoint | 2 +- slides/chapter-10.de.md | 312 +++++++------------------------ slides/chapter-10.en.md | 307 +++++++----------------------- slides/chapter-11.de.md | 236 +++++++++++++++++------ slides/chapter-11.en.md | 237 +++++++++++++++++------ slides/chapter-12.de.md | 402 ++++++++++++++++++++++----------------- slides/chapter-12.en.md | 404 +++++++++++++++++++++++----------------- 7 files changed, 950 insertions(+), 950 deletions(-) diff --git a/onpoint b/onpoint index 24119fc..34f46b2 160000 --- a/onpoint +++ b/onpoint @@ -1 +1 @@ -Subproject commit 24119fc714d85a572a09660a5a11953d96ea9a2d +Subproject commit 34f46b2328daf35dbff58bddda42657b70a9167b diff --git a/slides/chapter-10.de.md b/slides/chapter-10.de.md index ed2db74..c48593c 100644 --- a/slides/chapter-10.de.md +++ b/slides/chapter-10.de.md @@ -1,292 +1,110 @@ @slide(layout=chapter-slide) @title -Quelltext-Listings +Grafiken @slide(layout=content-only) @title -Unsere Optionen +Grafiken abbilden 🖼️ @content -Es gibt zwei verbreitete Wege, Quelltext in LaTeX-Dokumenten zu zeigen. - -* ++ **`minted`** erstellt **sehr hübsche** Quelltext-Listings, aber es benötigt **etwas mehr Konfiguration** und funktioniert nicht auf allen Betriebssystemen zuverlässig. -* ++ **`listings`** ist eine **einfach zu nutzende** (aber nicht so hübsche) Alternative für diejenigen, die Probleme mit `minted` haben. - -++ Die Befehle beider Pakete sind sehr ähnlich. - - -@slide(layout=content-and-preview) - -@title -Installation 🖥️ - -@content -`minted` benötigt die Programmiersprache Python. Nach der **[Installation von Python](https://www.python.org/)** kann das zugehörige Paket **[`Pygments`](http://pygments.org/)** in der Eingabeaufforderung installiert werden durch: - -``` {.lang-sh .hljs} -pip install Pygments -``` - -Anschließend muss das Paket `minted` (oder `listings`) nur noch eingebunden werden: +Um Grafiken darzustellen, muss das Paket `graphicx` eingebunden werden. ``` {.lang-tex .hljs} -\usepackage{minted} -\usepackage{listings} +\begin{figure} + \includegraphics{} + \caption[]{} +\end{figure} ``` -@preview -![](svg/chapter-10/minted-overview-crop.svg){ .thin-padding } +Bildgröße angeben: -@slide(layout=content-only) - -@title -Anpassungen beim Kompilieren - -@content -
- Um Dokumente mit Quelltext-Listings kompilieren zu können, muss die Flag `--shell-escape` an den Compiler übergeben werden.
- Dies ist nur bei vertrauenswürdigen Dokumenten empfehlenswert. -
- -In TeXstudio muss diese unter **`Optionen → TeXstudio konfigurieren → Befehle`** (`TeXstudio → Einstellungen` unter macOS) bei PdfLaTeX vor `%.tex` ergänzt werden: - -pdflatex -synctex=1 -interaction=nonstopmode **\-\-shell-escape** %.tex +``` {.lang-tex .hljs} +\includegraphics[width=0.5\textwidth, +height=5cm]{} +``` @slide(layout=content-only) @title -Ein Hinweis zu unserem Skript +Positionierung auf der Seite @content -Unsere Übungsmaterialien erlauben es, zwischen `minted` und `listings` zu wählen. -Von Haus aus nutzen wir `listings`. -Um `minted` zu aktivieren muss eine Datei namens `listings-mode.tex` mit dem folgenden Inhalt im Wurzelverzeichnis unseres Projekts erstellt werden: - -```{.lang-tex .hljs} -\newcommand\listingsmode{minted} -``` - -Kompiliert erneut und die Listings sollten durch `minted` erstellt worden sein. - - -@slide(layout=content-and-preview-with-category) - -@category -minted - -@title -Code im LaTeX-Quelltext - -@content -++ In einer eigenen Umgebung: - -``` {.lang-tex .hljs .fragment} -\section*{Haskell-Magie} -Quadrate aller geraden % … -\begin{minted}{haskell} -[x^2 | x <- [1..200], even x] -\end{minted} -``` - -++ Inline im Quelltext: - -``` {.lang-tex .hljs .fragment} -\section*{Ein HTML-Beispiel} -Eine Überschrift wird so ausgezeichnet: -\mint{html}|

LaTeX im Studium

|. -``` - -@preview -![](svg/chapter-10/minted-haskell-crop.svg) - - -@slide(layout=content-and-preview-with-category) - -@category -minted - -@title -Externer Code - -@content -Um Redundanz zu vermeiden, ist es manchmal praktisch, den Quelltext direkt aus der Quelldatei einzulesen. ``` {.lang-tex .hljs} -\section*{Einfache Java-Anwendung} -\inputminted{java}{Test.java} +\begin{figure}[] ``` -``` {.lang-java .hljs data-sourcefile="Test.java"} -public class Test { - public static void main(/*…*/) { - System.out.println(/*…*/); - } -} -``` - -@preview -![](svg/chapter-10/minted-java-crop.svg) +LaTeX positioniert Grafiken automatisch. Durch Kürzel können wir unsere Präferenzen (auch in Kombination) angeben. -@slide(layout=content-only-with-category) + + + + + + + + + + + + + + + + + + + + + + + + + +
KürzelPosition
hhier, wenn es dir recht ist
toberer Seitenrand (top)
bunterer Seitenrand (bottom)
pauf einer eigenen Seite (page)
HHier, verdammt noch mal!
(benötigt Paket `float`)
-@category -minted + +@slide(layout=content-only) @title -Themen und Stile +Zentrierte Anordnung @content -Durch optionale Parameter können Zeilennummerierung, Umbrüche und Farben ausgewählt werden. Außerdem sind zahlreiche Themes verfügbar. +``` {.lang-tex .hljs} +\begin{figure}[] + \begin{center} + \includegraphics{} + \end{center} +\end{figure} +``` + +Alternativ: ``` {.lang-tex .hljs} -\usemintedstyle{monokai} -\begin{minted}[ -linenos=true, -breaklines=true, -]{javascript} - % ... -\end{minted} +\begin{figure}[] + \centering + \includegraphics{} +\end{figure} ``` -🔗 **[Einführung](https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted)** und **[offizielle Dokumentation](https://ctan.kako-dev.de/macros/latex/contrib/minted/minted.pdf)** - - -@slide(layout=content-and-preview-with-category) - -@category -listings - -@title -Code im LaTeX-Quelltext - -@content -In einer eigenen Umgebung: - -``` {.lang-tex .hljs} -\section*{Haskell-Magie} -Quadrate aller geraden % … -\begin{lstlisting}[language=Haskell] -[x^2 | x <- [1..200], even x] -\end{lstlisting} -``` - -Das Paket `listings` stellt keinen Befehl für inline-Listings zur Verfügung. - -@preview -![](svg/chapter-10/listings-haskell-crop.svg) - - -@slide(layout=content-and-preview-with-category) - -@category -listings - -@title -Externer Code - -@content -Praktischerweise bietet auch `listings` einen Befehl zum Einfügen externen Codes: - -``` {.lang-tex .hljs} -\section*{Einfache Java-Anwendung} -\lstinputlisting[language=Java]{Test.java} -``` - -``` {.lang-java .hljs data-sourcefile="Test.java"} -public class Test { - public static void main(/*…*/) { - System.out.println(/*…*/); - } -} -``` - -@preview -![](svg/chapter-10/listings-java-crop.svg) - - -@slide(layout=content-only-with-category) - -@category -listings - -@title -Themen und Stile - -@content -`listings` stellt keine eigenen Themes zur Verfügung. Dies kann aber durch die vielen Konfigurationsoptionen ausgeglichen werden. - -``` {.lang-tex .hljs} -\begin{lstlisting}[ - language=Java, - basicstyle=\footnotesize\ttfamily, - breaklines=true, - keywordstyle=\color{ForestGreen}, - commentstyle=\color{DarkGray}, - literate={ö}{{\"o}}1 -] -% … -\end{lstlisting} -``` - -Für die Erstellung eigener Themes ist der Befehl `\lstset` nützlich. - - -@slide(layout=content-only-with-category) - -@category -listings - -@title -Weitere Materialien - -@content -* [Einführung](https://www.overleaf.com/learn/latex/Code_listing#Reference_guide) in das Paket -* offizielle [Dokumentation](https://www.overleaf.com/learn/latex/Code_listing#Reference_guide) -* das Paket [`xcolor`](https://www.overleaf.com/learn/latex/Using_colours_in_LaTeX) für Farben -* zwei [Themes](https://github.com/jez/latex-solarized) im solarized-Stil für `listings` - @slide(layout=task) @task-number -10 +11 @title -`minted` +Grafiken einfügen @content -* Im Ordner `exercises/source-code-listings` findet ihr eine Datei namens `Source.java`. -* **Bindet** den Java-Quelltext in der Datei `source-code-listings.tex` **ein**. (Beachtet, dass der Dateipfad relativ zu `main.tex` ist.) -* Aktiviert das **Syntax-Highlighting** durch Angabe der Sprache Java. -* **Nummeriert** die Zeilen und aktiviert **Umbrüche**. -* Nutzt das **Theme** `native`. -* Ändert die **Hintergrundfarbe** des Themes zu Dunkelblau. -* Bindet jetzt nur die **Zeilen 5 bis 7** ein. -* Entfernt die **Leerzeichen** am Anfang der Zeilen durch die passende Option (Tipp: Die Dokumentation spricht hier von `gobble`). - -Seht bei Fragen in der Dokumentation des Paketes `minted` nach. - - -@slide(layout=task) - -@task-number -10 - -@title -`listings` - -@content -* Im Ordner `exercises/source-code-listings` findet ihr eine Datei namens `Source.java`. -* **Bindet** den Java-Quelltext in der Datei `source-code-listings.tex` **ein**. (Beachtet, dass der Dateipfad relativ zu `main.tex` ist.) -* Aktiviert das **Syntax-Highlighting** durch Angabe der Sprache Java. -* **Nummeriert** die Zeilen und aktiviert **Umbrüche**. -* Setzt mit dem Parameter `basicstyle` eine dicktengleiche Schrift (`\ttfamily \small`). -* Ändert die Schlüsselwortfarbe zu Blau. -* Verbergt die Sonderzeichen, die **Leerzeichen in Zeichenketten** markieren. - -Seht bei Fragen in der Dokumentation des Paketes `listings` nach. +* Im Ordner `exercises/graphics` findet ihr eine Bilddatei namens `latex-logo.png`. +* Fügt sie **genau** unterhalb dieser Aufgabenstellung im Skript ein. +* Das Bild soll **zentriert** auf der Seite eingebunden werden. +* Fügt außerdem eine **Bildunterschrift** ein. +* Passt die **Größe** des Bildes an Breite der Seite (`\textwidth`) an. diff --git a/slides/chapter-10.en.md b/slides/chapter-10.en.md index ef62dc0..d78e893 100644 --- a/slides/chapter-10.en.md +++ b/slides/chapter-10.en.md @@ -1,289 +1,110 @@ @slide(layout=chapter-slide) @title -Source code listings - -@slide(layout=content-only) - -@title -Our options - -@content -There are two popular ways to display source code in a LaTeX document. - -* ++ **`minted`** renders **very pretty** source code listings, but it requires some **extra configuration** and might not work on every operating system. -* ++ **`listings`** is an **easy-to-use** (but not as pretty) option for those having troubles with `minted`. - -++ Their commands are very similar. - -@slide(layout=content-and-preview) - -@title -Installation 🖥️ - -@content -`minted` requires the Python programming language. As soon as **[Python is installed](https://www.python.org/)**, we can download the corresponding Python package **[`Pygments`](http://pygments.org/)** using a command prompt: - -``` {.lang-sh .hljs} -pip install Pygments -``` - -Add the LaTeX packages for `minted` or `listings` and we are good to go: - -``` {.lang-tex .hljs} -\usepackage{minted} -\usepackage{listings} -``` - -@preview -![](svg/chapter-10/minted-overview-english-crop.svg){ .thin-padding } - -@slide(layout=content-only) - -@title -Compiler settings - -@content -
- We need to pass the additional flag `--shell-escape` to our compiler in order to use `minted`.
- Do this only for documents you trust! -
- -In TeXstudio, go to **`Options → Configure TeXstudio → Commands`** (`TeXstudio → Settings` on macOS) and add the flag in the PdfLaTeX row before `%.tex`: - -pdflatex -synctex=1 -interaction=nonstopmode **\-\-shell-escape** %.tex +Graphics @slide(layout=content-only) @title -A note on our script +Including graphics 🖼️ @content -Our exercise material allows you to choose between `minted` and `listings`. -By default, we use `listings`. -To activate `minted`, create a file called `listings-mode.tex` in the project's root directory and add the following line: - -```{.lang-tex .hljs} -\newcommand\listingsmode{minted} -``` - -After compiling again, your listings should be rendered by `minted`. - - -@slide(layout=content-and-preview-with-category) - -@category -minted - -@title -In-situ listings - -@content -++ Within a dedicated environment: - -``` {.lang-tex .hljs .fragment} -\section*{Haskell Magic} -Squares of all even % … -\begin{minted}{haskell} -[x^2 | x <- [1..200], even x] -\end{minted} -``` - -++ Directly inline: - -``` {.lang-tex .hljs .fragment} -\section*{An HTML Example} -A headline is denoted the following way: -\mint{html}|

LaTeX at University

| -``` - -@preview -![](svg/chapter-10/minted-haskell-english-crop.svg) - - -@slide(layout=content-and-preview-with-category) - -@category -minted - -@title -External source code - -@content -We can avoid redundancy by including source code directly from its source file. +To display graphics, we need the `graphicx` package. ``` {.lang-tex .hljs} -\section*{Simple Java Application} -\inputminted{java}{Test.java} +\begin{figure} + \includegraphics{} + \caption[]{} +\end{figure} ``` -``` {.lang-java .hljs data-sourcefile="Test.java"} -public class Test { - public static void main(/*…*/) { - System.out.println(/*…*/); - } -} -``` - -@preview -![](svg/chapter-10/minted-java-english-crop.svg) - - -@slide(layout=content-only-with-category) - -@category -minted - -@title -Themes and styles - -@content -Optional parameters allow us to activate line numbers, automated line breaks, and syntax highlighting based on numerous color schemes. +Specifying the size: ``` {.lang-tex .hljs} -\usemintedstyle{monokai} -\begin{minted}[ -linenos=true, -breaklines=true, -]{javascript} - % ... -\end{minted} +\includegraphics[width=0.5\textwidth, +height=5cm]{} ``` -🔗 **[introduction](https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted)** and **[official documentation](https://ctan.kako-dev.de/macros/latex/contrib/minted/minted.pdf)** - -@slide(layout=content-and-preview-with-category) - -@category -listings +@slide(layout=content-only) @title -In-situ listings +Layout on the page @content -Within a dedicated environment: ``` {.lang-tex .hljs} -\section*{Haskell Magic} -Squares of all even % … -\begin{lstlisting}[language=Haskell] -[x^2 | x <- [1..200], even x] -\end{lstlisting} +\begin{figure}[] ``` -The `listings` package does not provide an inline command. - -@preview -![](svg/chapter-10/listings-haskell-english-crop.svg) +LaTeX places graphics automatically. With position codes, we can express our preferences (they can be combined as well). -@slide(layout=content-and-preview-with-category) + + + + + + + + + + + + + + + + + + + + + + + + + +
codeposition
hhere, if you don’t mind
ttop of the page
bbottom of the page
pon its own page
HHere, for God’s sake!
(`float` package required)
-@category -listings + +@slide(layout=content-only) @title -External source code +Centred alignment @content -Conveniently, also `listings` offers an import command: +``` {.lang-tex .hljs} +\begin{figure}[] + \begin{center} + \includegraphics{} + \end{center} +\end{figure} +``` + +Alternatively: ``` {.lang-tex .hljs} -\section*{Simple Java Application} -\lstinputlisting[language=Java]{Test.java} +\begin{figure}[] + \centering + \includegraphics{} +\end{figure} ``` -``` {.lang-java .hljs data-sourcefile="Test.java"} -public class Test { - public static void main(/*…*/) { - System.out.println(/*…*/); - } -} -``` - -@preview -![](svg/chapter-10/listings-java-english-crop.svg) - - -@slide(layout=content-only-with-category) - -@category -listings - -@title -Themes and styles - -@content -`listings` does not provide any themes by default, but can be configured extensively. - -``` {.lang-tex .hljs} -\begin{lstlisting}[ - language=Java, - basicstyle=\footnotesize\ttfamily, - breaklines=true, - keywordstyle=\color{ForestGreen}, - commentstyle=\color{DarkGray}, - literate={ö}{{\"o}}1 -] -% … -\end{lstlisting} -``` - -Have a look at the `\lstset` command for creating your own themes. - - -@slide(layout=content-only-with-category) - -@category -listings - -@title -Further resources - -@content -* [introduction](https://www.overleaf.com/learn/latex/Code_listing#Reference_guide) to the package -* official [documentation](https://www.overleaf.com/learn/latex/Code_listing#Reference_guide) -* [`xcolor` package](https://www.overleaf.com/learn/latex/Using_colours_in_LaTeX) for colors -* two [solarized themes](https://github.com/jez/latex-solarized) for `listings` - @slide(layout=task) @task-number -10 +11 @title -Listings with `minted` +Inserting graphics @content -* In the directory `exercises/source-code-listings` you can find a file named `Source.java`. -* **Include** it in the file `source-code-listings.tex`. (Keep in mind that the file path is relative to the main LaTeX document, i. e., to `main.tex`.) -* Activate **syntax highlighting** by stating the programming language Java. -* **Number** the code lines and add **line breaks**. -* Use the **theme** `native`. -* Change the **background colour** to dark blue. -* Now only include **lines 5 to 7**. -* Delete the **spaces** at the beginning of the lines. (Hint: The documentation speaks of `autogobble`). - -If you have questions, try to consult the documentation of the `minted` package. - -@slide(layout=task) - -@task-number -10 - -@title -Listings with `listings` - -@content -* In the directory `exercises/source-code-listings` you can find a file named `Source.java`. -* **Include** it in the file `source-code-listings.tex`. (Keep in mind that the file path is relative to the main LaTeX document, i. e., to `main.tex`.) -* Activate **syntax highlighting** by stating the programming language Java. -* **Number** the code lines. -* Set the `basicstyle` to a proper mono-spaced font (`\ttfamily \small`) -* Change the **keyword color** to blue. -* Don't show special characters for **spaces in strings**. - -If you have questions, try to consult the documentation of the `listings` package. +* In the directory `exercises/graphics` you can find an image file named `latex-logo.png`. +* **Include** the figure in `exercises/graphics/graphics.tex` and place it **exactly** where you include it. +* The image shall be **centered**. +* Additionally, add a **caption** for the figure. +* Adapt the **width** of the image to the width of the text (`\textwidth`). diff --git a/slides/chapter-11.de.md b/slides/chapter-11.de.md index c48593c..922fab2 100644 --- a/slides/chapter-11.de.md +++ b/slides/chapter-11.de.md @@ -1,110 +1,228 @@ @slide(layout=chapter-slide) @title -Grafiken +Tabellen @slide(layout=content-only) @title -Grafiken abbilden 🖼️ +Grundstruktur 🗒️ @content -Um Grafiken darzustellen, muss das Paket `graphicx` eingebunden werden. +Für typografisch schöne Tabellen nutzen wir das Paket `booktabs`. -``` {.lang-tex .hljs} -\begin{figure} - \includegraphics{} - \caption[]{} -\end{figure} +``` {.hljs .lang-tex} +\usepackage{booktabs} ``` -Bildgröße angeben: - -``` {.lang-tex .hljs} -\includegraphics[width=0.5\textwidth, -height=5cm]{} +``` {.hljs .lang-tex} +\begin{table}[] + \begin{tabular}{} + % Tabelleninhalt + \end{tabular} + \caption{} +\end{table} ``` +Die Positionierung erfolgt analog zu Grafiken. -@slide(layout=content-only) + +@slide(layout=content-and-preview) @title -Positionierung auf der Seite +Spaltendefinitionen @content - -``` {.lang-tex .hljs} -\begin{figure}[] +``` {.hljs .lang-tex} +\begin{tabular}{lrcl} + % Tabelleninhalt +\end{tabular} ``` -LaTeX positioniert Grafiken automatisch. Durch Kürzel können wir unsere Präferenzen (auch in Kombination) angeben. - - - - + + - - + + - - + + - - - - - - - - - - + +
KürzelPositionKürzelBedeutung
hhier, wenn es dir recht istllinksbündige Spalte
toberer Seitenrand (top)czentrierte Spalte
bunterer Seitenrand (bottom)
pauf einer eigenen Seite (page)
HHier, verdammt noch mal!
(benötigt Paket `float`)
rrechtsbündige Spalte
+++ Vertikale Trennlinien und doppelte horizontale Linien sind unter Typograph\*innen nicht gern gesehen und sollten vermieden werden. + +@preview +![](svg/chapter-12/tabelle-beispiel-crop.svg){.thin-padding} + + +@slide(layout=content-and-preview) + +@title +Tabelleninhalt + +@content +``` {.hljs .lang-tex} +\begin{tabular}{lll} + \toprule + Spalte 1 & Spalte 2 & Spalte 3 \\ + \midrule + Inhalt a & Inhalt b & Inhalt c \\ + Inhalt e & Inhalt f & Inhalt g \\ + Inhalt i & Inhalt j & Inhalt k \\ + \bottomrule +\end{tabular} +``` +* ++ Zellen werden durch ›`&`‹ abgetrennt. +* ++ Reihen werden durch ›`\\`‹ beendet. +* ++ `\toprule`, `\midrule` und `\bottomrule` strukturieren die Tabelle. + +@preview +![](svg/chapter-12/tabelle-inhalt-beispiel-crop.svg){.thin-padding} + + +@slide(layout=wide-content) + +@title +Die gesamte Tabelle + +@content +``` {.hljs .lang-tex} +\begin{table}[h] + \begin{tabular}{lrcl} + \toprule + Sprache & Autor & Erscheinungsjahr & Aktuelle Version \\ + \midrule + C++ & Bjarne Stroustrup & 1985 & C++ 17 \\ + Java & James Gosling & 1998 & 13 \\ + Python & Guido van Rossum & 1991 & 3.8.0 \\ + \bottomrule + \end{tabular} + \caption{Bekannte Programmiersprachen} +\end{table} +``` + +

Mit `@{}` vor und nach einer Spaltendefinition wird der umgebende Weißraum unterdrückt.

+ +

`\begin{tabular}{@{}lrcl@{}}` beschränkt die Linien auf die Breite des Tabelleninhalts.

+ @slide(layout=content-only) @title -Zentrierte Anordnung +Besonders lange Tabellen @content -``` {.lang-tex .hljs} -\begin{figure}[] - \begin{center} - \includegraphics{} - \end{center} -\end{figure} +Tabellen, die über eine Seite hinaus gehen, werden von `tabular` einfach abgeschnitten. Die Lösung bietet hier das Paket `longtable`: + +``` {.hljs .lang-tex} +\usepackage{longtable} ``` -Alternativ: - -``` {.lang-tex .hljs} -\begin{figure}[] - \centering - \includegraphics{} -\end{figure} +``` {.hljs .lang-tex} +\begin{longtable}{} + % Tabelleninhalt + \caption{} + \label{