Skip to content
Snippets Groups Projects
Commit 43b37c1a authored by Jannik Dunkelau's avatar Jannik Dunkelau
Browse files

Extend LaTeX examples and improve support of listings/algorithms

parent f113f981
No related branches found
No related tags found
No related merge requests found
......@@ -110,6 +110,145 @@ ganz leicht Graphen erstellen:
\label{fig:the-plot}
\end{figure}
\section{Formeln und Algorithmen}
\subsection{Formeln}
\Cref{eq:example1} gibt eine referenzierbare Formel an,
während \cref{eq:example2} eine Formel darstellt, die länger ist als die
Zeile zulässt.
\begin{equation}
\label{eq:example1}
2 = 1 + 1
\end{equation}
\begin{multline}
\label{eq:example2}
30 = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 \\
+ 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
\end{multline}
\subsubsection{Mehrzeilige Formeln}
In der zweizeiligen Gleichung
\begin{equation}
\label{eq:mlp-stacking}
\begin{split}
\hat{y} & = f_2(f_1(x; W); V) \\
& = f(x; W, V)
\end{split}
\end{equation}
wurden die Gleichheitszeichen in beiden Zeilen direkt untereinander ausgerichtet
(mittels \texttt{\&} im Quelltext und der \texttt{split}-Umgebung).
Teilen wir \cref{eq:mlp-stacking}, welche den Forward Pass eines Neuronalen
Netzes darstellt,
in mehrere Schritte auf, so erhalten wir
\begin{align}
a & = W^\mathsf{T} x \label{eq:fp-act} \\
h & = g_1(a) \label{eq:fp-hidden} \\
o & = V^\mathsf{T} h \label{eq:fp-out} \\
\hat{y} & = g_2(o) \label{eq:fp-pred}
\,\text{,}
\end{align}
wobei \cref{eq:fp-act,eq:fp-hidden,eq:fp-out,eq:fp-pred} jeweils eine eigene
Referenznummer erhalten.
\subsection{Algorithmen}
Für Algorithmen kann das bereits inkludierte Paket \texttt{algoritihmicx}
genutzt werden.
In \cref{alg:minimax} wird exemplarisch eine Implementierung des
Minimax-Algorithmus aufgeführt.
\begin{algorithm}
\caption{Determining the next action by Minimax}%
\label{alg:minimax}
\begin{algorithmic}[1]
\Function{Minimax}{Game State Tree: $G^n$}
\State bestValue \(\gets -\infty\)
\State \(bestAction \gets \) NIL
\ForAll{\(G^n_a \in S(G^n)\)}
\State \(value = \) \Call{MinimaxValue}{\(G^n_a\), true}
\If{\(value > bestValue\)} \Comment{Aktualisiere besten Wert}
\State \(bestValue \gets value\)
\State \(bestAction \gets a\)
\EndIf
\EndFor
\State \Return \(bestAction\)
\EndFunction
\Statex
\Function{MinimaxValue}{Game State Tree: $G^n$ Boolean: $ourTurn$}
\If{\(D(G^n)=0\)}
\State \Return \Call{Heuristic}{root(\(G^n\))}
\ElsIf{\(ourTurn\)}
\State \(maxValue \gets -\infty \)
\ForAll{\(S \in S(G^n)\)}
\State \(newValue \gets \) \Call{MinimaxValue}{\(S\), false}
\State \(maxValue \gets max(newValue, maxValue)\)
\EndFor
\State \Return \(maxValue\)
\Else
\State \(minValue \gets +\infty \)
\ForAll{\(S \in S(G^n)\)}
\State \(newValue \gets \) \Call{MinimaxValue}{\(S\), true}
\State \(minValue \gets \min(newValue, minValue)\)
\EndFor
\State \Return \(minValue\)
\EndIf
\EndFunction
\end{algorithmic}
\end{algorithm}
\subsection{Source Code Listings}
\Cref{lst:hello-c,lst:hello-python} zeigen ein `Hello World'-Programm,
je in C und Python.
\Cref{lst:hello-prolog} zeigt ein Prolog-Prädikat, welches eine Liste in zwei
teile teilen kann.
\begin{lstlisting}[
float, caption={Hello World in C.}, label={lst:hello-c}, language=C
]
#include <stdio.h>
int main(int argc, char[] *args){
printf("Hello World!\n");
// And done!
}
\end{lstlisting}
\begin{lstlisting}[
float, caption={Totally minimal Hello World in Python.},
label={lst:hello-python}, language=Python
]
def hello_world():
print("Hello World"!)
if __name__ == "__main__":
hello_world()
\end{lstlisting}
\begin{lstlisting}[
float, caption={Prolog implementation of \texttt{split/4}},
label={lst:hello-prolog}, language=Prolog
]
% Split list into two parts (length of first list given).
%
% ?- split([a,b,c,d,e,f,g,h,i,k], 3, L1, L2).
% L1 = [a,b,c]
% L2 = [d,e,f,g,h,i,k]
%
split(L, N, L1, L2) :-
length(L1, N),
append(L1, L2, L).
\end{lstlisting}
\section{Conclusion}
Am Ende der Arbeit werden noch einmal die erreichten Ergebnisse
......
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{hhuthesis}[2020/02/11 HHU Thesis LaTeX document class v1.10]
\ProvidesClass{hhuthesis}[2020/02/11 HHU Thesis LaTeX document class v1.11]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}} % Options fallback.
\ProcessOptions\relax
......@@ -96,6 +96,7 @@
%% Corporate Design says to use Arial, but TeXLive only provides helvet
\RequirePackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\RequirePackage[scaled=0.85]{beramono}
\pagestyle{headings}
......@@ -175,6 +176,27 @@
}
}
%% Adapt lstlisting display
\newcommand{\lstkeyword}[1]{%
\ifprintblackwhite\color{black}\else\color{hhublue}\fi\bfseries#1}
\newcommand{\lststring}[1]{%
\ifprintblackwhite\color{black}\else\color{hhudarkblue}\fi#1}
\newcommand{\setlstlistingstyle}{
\lstset{
basicstyle=\small\ttfamily,
numbers=left, numberstyle=\footnotesize,
keywordstyle=\lstkeyword,
commentstyle=\color{gray}\itshape,
stringstyle=\lststring,
showstringspaces=false,
frame=tb,
}
\renewcommand*\thelstnumber{{\the\value{lstnumber}}:}
}
%% Adapt algorithmicx font
\newcommand{\algsmallfont}{\algrenewcommand\ALG@beginalgorithmic{\small}}
%%% Setup of title page
\RequirePackage{graphicx}
......@@ -446,4 +468,10 @@
\input{abstract.tex}
\end{abstract}
\cleardoublepage
% Ensure cleverref knows how to talk about listings.
\iflanguage{ngerman}{
\crefname{listing}{Quellcode}{Quellcodes}
\Crefname{listing}{Quellcode}{Quellcodes}
}{}
}
......@@ -73,8 +73,6 @@
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{listings} % Einbindung von Code
\usepackage{algorithmicx} % Angabe von Algorithmen in Pseudocode
\usepackage{siunitx} % \num Befehl zum einfacheren Formatieren von Zahlen.
\usepackage{enumitem} % Leichter konfigurierbare enumerate-Umgebungen.
\usepackage{subcaption} % Unterteilung von Figures in Subfigures.
......@@ -91,6 +89,20 @@
\usepackage{multicol}
\usepackage{longtable} % Große Tabellen gehen über mehrere Seiten.
%% Quellcode
\usepackage{listings} % Einbindung von Code.
\setlstlistingstyle{} % Kosmetische Einstellungen
% Sprachabhängige Bezeichnung.
\iflanguage{ngerman}{\renewcommand{\lstlistingname}{Quellcode}}{}
%% Algorithmen in Pseudocode
\usepackage{algorithm} % Float-Umgebung für angegebene Algorithmen.
\usepackage{algorithmicx} % Angabe von Algorithmen in Pseudocode.
\usepackage{algpseudocode} % Standart Pseudocode-Elemente für Algorithmen.
\algsmallfont{}
% Sprachabhängige Bezeichnung.
\iflanguage{ngerman}{\floatname{algorithm}{Algorithmus}}{}
%% Intelligenteres Referenzieren mittels \cref.
%% \languagename um dynamisch zwischen ngerman oder english zu wechseln.
\usepackage[\languagename,capitalize,noabbrev]{cleveref}
......@@ -147,9 +159,25 @@
\backmatter
%% Listings of figures, tables, etc. Delete what is not needed.
\listoffigures
\listoftables
% Algorithms
\iflanguage{ngerman}%
{\renewcommand{\listalgorithmname}{Algorithmenverzeichnis}}{}
\addcontentsline{toc}{section}{\listalgorithmname}
\listofalgorithms
% Code Listings
\iflanguage{ngerman}%
{\renewcommand{\lstlistlistingname}{Quellcodeverzeichnis}}%
{\renewcommand{\lstlistlistingname}{List of Listings}}
\addcontentsline{toc}{section}{\lstlistlistingname}
\lstlistoflistings
\clearpage
\bibliography{references}
%% Depending on Language, use german alphadin or original alpha
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment