add codeblock command and include it into some exercises

This commit is contained in:
Fradtschuk 2022-01-03 15:06:40 +01:00
parent f18ed4ab9c
commit 70e4227534
21 changed files with 236 additions and 159 deletions

View File

@ -98,6 +98,44 @@
\texttt{#2}%
}
% Code block
% ==========
% Pastes in a non-inline code block using minted or lstlistings
% first parameter: programming language
% path to code file
\lstdefinestyle{latex}{%
language=[LaTeX]TeX,
breaklines,
keywordstyle=\color{ForestGreen}
}
\newcommand\codeblock[2]{%
\ifthenelse{\equal{\listingsmode}{minted}}{%
\inputminted{#1}{#2}
}{%
\ifthenelse{\equal{#1}{latex}}{%
\lstset{language=[LaTeX]TeX,
basicstyle=\footnotesize,
breakatwhitespace=false,
keywordstyle=\color{ForestGreen}\bfseries,
emph={%
subsection, subsubsection, url, includegraphics, toprule,
midrule, bottomrule, cref%
},
emphstyle={\color{ForestGreen}\bfseries},
commentstyle=\color{darkgray}
}
\lstinputlisting{#2}%
}{%
\lstset{language=#1}
\lstinputlisting{#2}
}
}
}
% Simple code examples
% ====================
% Box for example code next to the rendered example.

View File

@ -0,0 +1,56 @@
% \documentclass{scrartcl}
% \usepackage[utf8]{inputenc}
% \usepackage[T1]{fontenc}
% \usepackage[english]{babel}
% \usepackage[hidelinks]{hyperref}
% \begin{document}
% \tableofcontents
\section{Beverages}
\subsection{Pink Lemonade}
We all know and love it in summer: a cold lemonade. The pink variant of our
favorite summer drink is traditionally achieved by adding food coloring to the
lemonade. However, we changed things up a little and decided to go for a
variant with berries instead of food coloring, which also makes the drink less
sour.
\subsubsection{Ingredients}
For making the lemonade we need 400\,g of berries. You can use either frozen or
fresh ones. You can, of course, adjust the choice of berries to your likings:
raspberries, blueberries, blackberries, or a mixture work excellently for
making the lemonade.
To make the drink sweeter we use 50\,ml of maple syrup. Needless to say, you
can also use less, if you want your lemonade to be more sour. By the way, other
sweeteners, such as agave syrup, or coconut sugar also work fine.
Additionally, we need the juice of four freshly-squeezed lemons, one litre
worth of cold water and 400\,g of ice cubes to keep the drink cold.
\subsubsection{Instructions}
Put the berries along with the maple syrup into a large bowl and cook them at
medium-high heat for around three to four minutes. When the berries start to
soften, reduce the heat a little. Now mash the berries with the end of a wooden
spoon until there are almost no big chunks anymore. The less chunks the better!
Place a sieve over the container that you want to store the lemonade in. Put
the berries into the sieve. With the end of the wooden spoon, try to press out
as much liquid of the berry mixture as possible. Let the juice sit until it is
completely cold.
When the liquid is cold, add the lemon juice, the cold water, and the ice cubes
and stir everything.
Your lemonade is now ready to enjoy!
\subsection{Hot Chocolate}
Coming soon!
\section{Breakfast}
\subsubsection{Buckwheat Overnight Oats}
Coming soon!
% \end{document}

View File

@ -1,41 +1 @@
\begin{minted}[breaklines]{latex}
% \documentclass{scrartcl}
% \usepackage[utf8]{inputenc}
% \usepackage[T1]{fontenc}
% \usepackage[english]{babel}
% \usepackage[hidelinks]{hyperref}
% \begin{document}
% \tableofcontents
\section{Beverages}
\subsection{Pink Lemonade}
We all know and love it in summer: a cold lemonade. The pink variant of our favorite summer drink is traditionally achieved by adding food coloring to the lemonade. However, we changed things up a little and decided to go for a variant with berries instead of food coloring, which also makes the drink less sour.
\subsubsection{Ingredients}
For making the lemonade we need 400\,g of berries. You can use either frozen or fresh ones. You can, of course, adjust the choice of berries to your likings: raspberries, blueberries, blackberries, or a mixture work excellently for making the lemonade.
To make the drink sweeter we use 50\,ml of maple syrup. Needless to say, you can also use less, if you want your lemonade to be more sour. By the way, other sweeteners, such as agave syrup, or coconut sugar also work fine.
Additionally, we need the juice of four freshly-squeezed lemons, one litre worth of cold water and 400\,g of ice cubes to keep the drink cold.
\subsubsection{Instructions}
Put the berries along with the maple syrup into a large bowl and cook them at medium-high heat for around three to four minutes. When the berries start to soften, reduce the heat a little. Now mash the berries with the end of a wooden spoon until there are almost no big chunks anymore. The less chunks the better!
Place a sieve over the container that you want to store the lemonade in. Put the berries into the sieve. With the end of the wooden spoon, try to press out as much liquid of the berry mixture as possible. Let the juice sit until it is completely cold.
When the liquid is cold, add the lemon juice, the cold water, and the ice cubes and stir everything.
Your lemonade is now ready to enjoy!
\subsection{Hot Chocolate}
Coming soon!
\section{Breakfast}
\subsubsection{Buckwheat Overnight Oats}
Coming soon!
% \end{document}
\end{minted}
\codeblock{latex}{./exercises/basic-document-structure/document-structure.code.tex}

View File

@ -0,0 +1,7 @@
Java is an object-oriented programming language, that appeared in 1995. The
most recent version of the programming language is version 16\footnote{March
2021}. In order to write Java programs, one needs to install the so-called
\emph{Java Development Kit
(JDK)}.\footnote{\url{https://www.oracle.com/java/technologies/javase-downloads.html}}
Java programs can be written independently from the operating system that one
uses.

View File

@ -1,5 +1 @@
\begin{minted}[breaklines,breakanywhere]{latex}
Java is an object-oriented programming language, that appeared in 1995. The most recent version of the programming language is version 16\footnote{March 2021}. In order to write Java programs, one needs to install the so-called \emph{Java Development Kit (JDK)}.\footnote{\url{https://www.oracle.com/java/technologies/javase-downloads.html}} Java programs can be written independently from the operating system that one uses.
\end{minted}
\codeblock{latex}{./exercises/footnotes/footnotes.code.tex}

View File

@ -0,0 +1,5 @@
\begin{figure}[H]
\centering
\includegraphics[width=\textwidth]{exercises/graphics/latex-logo.png}
\caption{The \LaTeX{} Project Logo}
\end{figure}

View File

@ -1,7 +1 @@
\begin{minted}[breaklines,breakanywhere]{latex}
\begin{figure}[H]
\centering
\includegraphics[width=\textwidth]{exercises/graphics/latex-logo.png}
\caption{The \LaTeX{} Project Logo}
\end{figure}
\end{minted}
\codeblock{latex}{./exercises/graphics/graphics.code.tex}

View File

@ -0,0 +1,26 @@
Ingredients:
400 g berries, 50 ml maple syrup, 4 lemons, 1 l cold water, 400 g ice cubes
\noindent Instructions: Boil and shred the berries, add maple syrup, squeeze
the lemons and add their juice, add the remaining ingredients, scramble
thoroughly
\begin{itemize}
\item Ingredients:
\begin{compactitem}
\item 400 g berries
\item 50 ml maple sirup
\item 4 lemons
\item 1 l cold water
\item 400 g ice cubes
\end{compactitem}
\item Instructions:
\begin{compactenum}
\item boil and shred the berries
\item add maple sirup
\item squeeze the lemons and add their juice
\item add the remaining ingredients
\item scramble thoroughly
\end{compactenum}
\end{itemize}

View File

@ -1,26 +1 @@
Ingredients:
400 g berries, 50 ml maple syrup, 4 lemons, 1 l cold water, 400 g ice cubes
\noindent Instructions: Boil and shred the berries, add maple sirup, squeeze the lemons and add their juice, add the remaining ingredients, scramble thoroughly
\begin{minted}{latex}
\begin{itemize}
\item Ingredients:
\begin{compactitem}
\item 400 g berries
\item 50 ml maple sirup
\item 4 lemons
\item 1 l cold water
\item 400 g ice cubes
\end{compactitem}
\item Instructions:
\begin{compactenum}
\item boil and shred the berries
\item add maple sirup
\item squeeze the lemons and add their juice
\item add the remaining ingredients
\item scramble thoroughly
\end{compactenum}
\end{itemize}
\end{minted}
\codeblock{latex}{./exercises/lists/lists.code.tex}

View File

@ -0,0 +1,22 @@
% Gravitational acceleration in Germany
$$9,81\,\frac{m}{s^2}$$
% pq formula
$$x_{1,2} = - \frac{p}{2} \pm \sqrt{\left(\frac{p}{2}\right)^2 - q}$$
% Quadratic formula
$$x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$
% Catalan numbers
\begin{equation*}
C_n = \frac{1}{n+1} {2n \choose n} = \frac{(2n)!}{(n+1)!n!}
\end{equation*}
% Definition of a factorial
$$n! = \prod_{i=1}^{n} i$$
% Set of all odd natural numbers
$$\{ x \mid x \in \mathds{N}, \mathrm{odd}(x) \}$$
% Elimination $\neg\exists x$
$$\neg\exists x . p(x) \Leftrightarrow \forall x . \neg p(x)$$

View File

@ -1,25 +1 @@
\begin{minted}{latex}
% Gravitational acceleration in Germany
$$9,81\,\frac{m}{s^2}$$
% pq formula
$$x_{1,2} = - \frac{p}{2} \pm \sqrt{\left(\frac{p}{2}\right)^2 - q}$$
% Quadratic formula
$$x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$
% Catalan numbers
\begin{equation*}
C_n = \frac{1}{n+1} {2n \choose n} = \frac{(2n)!}{(n+1)!n!}
\end{equation*}
% Definition of a factorial
$$n! = \prod_{i=1}^{n} i$$
% Set of all odd natural numbers
$$\{ x \mid x \in \mathds{N}, \mathrm{odd}(x) \}$$
% Elimination $\neg\exists x$
$$\neg\exists x . p(x) \Leftrightarrow \forall x . \neg p(x)$$
\end{minted}
\codeblock{latex}{./exercises/maths/math-formulas.code.tex}

View File

@ -1,6 +1,21 @@
\section{First section}
Jelly beans tiramisu chocolate bar chupa chups candy canes lollipop liquorice cheesecake tootsie roll. Marshmallow sugar plum cake tiramisu jelly cake bear claw. Croissant liquorice jelly lollipop carrot cake. Cheesecake danish chocolate halvah. Candy canes jujubes chupa chups jujubes candy canes tootsie roll toffee danish sesame snaps. Sugar plum gummi bears lollipop chocolate bar. Ice cream soufflé sweet lemon drops chocolate soufflé gingerbread cookie muffin.
Jelly beans tiramisu chocolate bar chupa chups candy canes lollipop liquorice
cheesecake tootsie roll. Marshmallow sugar plum cake tiramisu jelly cake bear
claw. Croissant liquorice jelly lollipop carrot cake. Cheesecake danish
chocolate halvah. Candy canes jujubes chupa chups jujubes candy canes tootsie
roll toffee danish sesame snaps. Sugar plum gummi bears lollipop chocolate bar.
Ice cream soufflé sweet lemon drops chocolate soufflé gingerbread cookie muffin.
Sugar plum danish halvah jujubes pastry donut carrot cake dessert donut. Sweet gingerbread gingerbread wafer gummi bears pastry. Tootsie roll donut powder cake. Brownie halvah lollipop gummi bears. Liquorice pie caramels jelly beans. Halvah danish brownie danish toffee cotton candy lemon drops.
Sugar plum danish halvah jujubes pastry donut carrot cake dessert donut. Sweet
gingerbread gingerbread wafer gummi bears pastry. Tootsie roll donut powder
cake. Brownie halvah lollipop gummi bears. Liquorice pie caramels jelly beans.
Halvah danish brownie danish toffee cotton candy lemon drops.
Donut jelly beans candy canes muffin lemon drops carrot cake sugar plum. Sesame snaps pie bonbon cotton candy cookie caramels. Chupa chups dessert tootsie roll carrot cake candy cookie sweet roll jelly beans. Oat cake halvah gingerbread bonbon sweet sesame snaps dragée carrot cake. Bonbon pastry chupa chups. Chocolate cake macaroon jelly-o. Pastry pastry sugar plum jujubes lemon drops gummi bears sugar plum cheesecake fruitcake. Chocolate cake chocolate candy. Wafer carrot cake chocolate cake jujubes cupcake soufflé gingerbread chocolate cake donut.
Donut jelly beans candy canes muffin lemon drops carrot cake sugar plum. Sesame
snaps pie bonbon cotton candy cookie caramels. Chupa chups dessert tootsie roll
carrot cake candy cookie sweet roll jelly beans. Oat cake halvah gingerbread
bonbon sweet sesame snaps dragée carrot cake. Bonbon pastry chupa chups.
Chocolate cake macaroon jelly-o. Pastry pastry sugar plum jujubes lemon drops
gummi bears sugar plum cheesecake fruitcake. Chocolate cake chocolate candy.
Wafer carrot cake chocolate cake jujubes cupcake soufflé gingerbread chocolate
cake donut.

View File

@ -0,0 +1,20 @@
C\# is an object-oriented programming language that was developed by Microsoft
in 2011. In \cref{fig:csharp} we can see the logo of the programming language.
\begin{figure}[H]
\caption{The logo of C\#}
\label{fig:csharp}
\centering
\includegraphics[width=2cm]{exercises/references/csharp.png}
\end{figure}
\cref{lst:csharphelloworld} shows a program that prints the text \enquote{Hello
LaTeX friends!} to the console. Like Java, C\# makes use of classes and main
methods to build executable applications.
\begin{listing}[H]
\caption{A simple C\# program}
\label{lst:csharphelloworld}
\inputminted[breaklines,
linenos=true]{csharp}{exercises/references/HelloLateXFriends.cs}
\end{listing}

View File

@ -1,18 +1 @@
\begin{minted}[breaklines]{latex}
C\# is an object-oriented programming language that was developed by Microsoft in 2011. In \cref{fig:csharp} we can see the logo of the programming language.
\begin{figure}[H]
\caption{The logo of C\#}
\label{fig:csharp}
\centering
\includegraphics[width=2cm]{exercises/references/csharp.png}
\end{figure}
\Cref{lst:csharphelloworld} shows a program that prints the text \enquote{Hello LaTeX friends!} to the console. Like Java, C\# makes use of classes and main methods to build executable applications.
\begin{listing}[H]
\caption{A simple C\# program}
\label{lst:csharphelloworld}
\inputminted[breaklines, linenos=true]{csharp}{exercises/references/HelloLateXFriends.cs}
\end{listing}
\end{minted}
\codeblock{latex}{./exercises/references/references.code.tex}

View File

@ -0,0 +1,11 @@
What is a semester ticket?
It is also known as \enquote{Studi-Ticket} or \enquote{Studi-Karte} and allows
you to use the local public transport around Bamberg for free.
In Bamberg, your student card (Studierenden\-ausweis) is used, i.\,a., as a
semester ticket.
To be able to use it, you should validate the student card in one of the
university buildings.
This is possible after you have paid the semester fees (101,50\,\euro).
A validation printers are located in multiple university buildings, e.\,g., in
the foyer of the Erba building, in front of the library.
This building is opened Monday\,--\,Friday, 7am\,--\,10pm.

View File

@ -1,10 +1 @@
\begin{minted}[breaklines]{latex}
What is a semester ticket?
It is also known as \enquote{Studi-Ticket} or \enquote{Studi-Karte} and allows you to use the local public transport around Bamberg for free.
In Bamberg, your student card (Studierenden\-ausweis) is used, i.\,a., as a semester ticket.
To be able to use it, you should validate the student card in one of the university buildings.
This is possible after you have paid the semester fees (101,50\,\euro).
A validation printers are located in multiple university buildings, e.\,g., in the foyer of the Erba building, in front of the library.
This building is opened Monday\,--\,Friday, 7am\,--\,10pm.
\end{minted}
\codeblock{latex}{./exercises/special-characters/special-characters.code.tex}

View File

@ -0,0 +1,13 @@
\begin{table}[h]
\centering
\begin{tabular}{clll}
\toprule
No. & Name & Abbreviation & Term \\
\midrule
1 & Foundations of Software Engineering & SWT-FSE-B & summer \\
2 & Information Retrieval & MI-IR-M & summer \\
3 & International Outsourcing Management & ISM-IOM-M & winter \\
\bottomrule
\end{tabular}
\caption{Overview over some courses}
\end{table}

View File

@ -1,18 +1,4 @@
\begin{minted}[breaklines]{latex}
\begin{table}[h]
\centering
\begin{tabular}{clll}
\toprule
No. & Name & Abbreviation & Term \\
\midrule
1 & Foundations of Software Engineering & SWT-FSE-B & summer \\
2 & Information Retrieval & MI-IR-M & summer \\
3 & International Outsourcing Management & ISM-IOM-M & winter \\
\bottomrule
\end{tabular}
\caption{Overview over some courses}
\end{table}
\end{minted}
\codeblock{latex}{./exercises/tables/tables.code.tex}
\begin{table}[h]
\centering

View File

@ -0,0 +1,9 @@
``\emph{Recursion} (adjective: \emph{recursive}) occurs when a thing is defined
in terms of itself or of its type.
\emph{Recursion} is used in a variety of disciplines ranging from linguistics
to logic.
The most common application of \emph{recursion} is in mathematics and computer
science,
where a function being defined is applied within its own definition.''
Source and more information: \url{https://en.wikipedia.org/wiki/Recursion}

View File

@ -1,8 +1 @@
\begin{minted}[breaklines]{latex}
``\emph{Recursion} (adjective: \emph{recursive}) occurs when a thing is defined in terms of itself or of its type.
\emph{Recursion} is used in a variety of disciplines ranging from linguistics to logic.
The most common application of \emph{recursion} is in mathematics and computer science,
where a function being defined is applied within its own definition.''
Source and more information: \url{https://en.wikipedia.org/wiki/Recursion}
\end{minted}
\codeblock{latex}{./exercises/text-markup/markup.code.tex}

View File

@ -20,7 +20,7 @@
\graphicspath{graphics/}
% Text color
\usepackage{xcolor}
\usepackage[usenames,dvipsnames]{xcolor}
% Multiple captions in one figure
\usepackage{subcaption}
@ -37,6 +37,7 @@
% Sourcecode listings
\usepackage{minted}
\usepackage{listings}
% Quotes (\enquote)
\usepackage[autostyle,autopunct=false]{csquotes}