#8 migrated code listings to minted

This commit is contained in:
Dominik Becker 2018-04-26 20:26:36 +02:00
parent 8bf9519b91
commit 5f9a41bc40
4 changed files with 22 additions and 62 deletions

View File

@ -11,7 +11,7 @@ latexmk:
- main.pdf
expire_in: 2d
script:
- latexmk -xelatex main.tex
- latexmk main.tex
hunspell:
stage: test

2
.latexmkrc Normal file
View File

@ -0,0 +1,2 @@
$pdf_mode = 1;
$pdflatex = 'xelatex --shell-escape';

View File

@ -144,13 +144,17 @@ If you introduce acronyms, add them to `config/abkuerzungen.tex` in the followin
**(i)** Please note: If you have acronyms that are longer than four characters, you may extend the parameter in brackets behind the `\begin{acronym}` statement.
### Code Listings
Listings (code snippets) are done using the `\lstlisting` environment.
It can have it's own caption, positioned with the parameter `captionpos` (see official docs):
Listings (code snippets) are done using the `minted` environment.
It provides syntax highlighting for several languages via an external Python library (*Pygments*) and has comprehensive layout capabilities.
Though, handling of captions is a bit complicated, which is why it's wrapped into a custom `code` environment:
```latex
\begin{lstlisting}[caption=caption goes here,captionpos=b]
// code goes here...
\end{lstlisting}
\begin{code}
\inputminted{bash}{resources/yoursource.sh}
\label{yourlabel}
\captionof{listing}{Some Caption goes here...}
\source{and you can tell people where you got the code from...}
\end{code}
```
Config for syntax highlighting is centrally provided in `config/config.tex` using the `\lstset` directive (defaulting to `C#` in this boilerplate).

View File

@ -135,62 +135,16 @@
\usepackage{scrhack}
% Sourcecode-Listings
\usepackage{listings}
\usepackage[chapter,newfloat]{minted}
\definecolor{bluekeywords}{rgb}{0.13,0.13,1}
\definecolor{lightbluekeywords}{rgb}{0.13,0.7,1}
\definecolor{greencomments}{rgb}{0,0.5,0}
\definecolor{redstrings}{rgb}{0.9,0,0}
\lstset{language=[Sharp]C,
showspaces=false,
showtabs=false,
breaklines=true,
showstringspaces=false,
escapeinside={(*@}{@*)},
commentstyle=\color{greencomments},
keywordstyle=[0]\color{bluekeywords}\bfseries,
keywordstyle=[1]\color{lightbluekeywords}\bfseries,
stringstyle=\color{redstrings},
basicstyle=\small\ttfamily,
fontadjust,
xrightmargin=1mm,
keywords=[0]{string, int, public, var, static, using, object, void},
keywords=[1]{File,UPFConfig,JsonConvert},
tabsize=2,
lineskip=-0.1em,
frame=tb,
numbers=left,
numberstyle=\tiny,
stepnumber=1,
numbersep=5pt,
escapeinside=||
\setminted{
linenos=true,
frame=lines,
baselinestretch=1,
breaklines=true,
breakautoindent=true,
fontsize=\small
}
%% http://tex.stackexchange.com/questions/126839/how-to-add-a-colon-after-listing-label
\makeatletter
\begingroup\let\newcounter\@gobble\let\setcounter\@gobbletwo
\globaldefs\@ne \let\c@loldepth\@ne
\newlistof{listings}{lol}{\lstlistlistingname}
\endgroup
\let\l@lstlisting\l@listings
\makeatother
\renewcommand*\cftfigpresnum{Abbildung~}
\renewcommand*\cfttabpresnum{Tabelle~}
\renewcommand*\cftlistingspresnum{Listing~}
\renewcommand{\cftfigaftersnum}{:}
\renewcommand{\cfttabaftersnum}{:}
\renewcommand{\cftlistingsaftersnum}{:}
\settowidth{\cftfignumwidth}{\cftfigpresnum 99~\cftfigaftersnum}
\settowidth{\cfttabnumwidth}{\cfttabpresnum 99~\cftfigaftersnum}
\settowidth{\cftlistingsnumwidth}{\cftlistingspresnum 99~\cftfigaftersnum}
\setlength{\cfttabindent}{1.5em}
\setlength{\cftfigindent}{1.5em}
\setlength{\cftlistingsindent}{1.5em}
\renewcommand\lstlistlistingname{Listingverzeichnis}
\makeatletter
\def\l@lstlisting#1#2{\@dottedtocline{1}{0em}{1.5em}{\lstlistingname\space{#1}}{#2}}
\makeatother
\newenvironment{code}{\captionsetup{type=listing}}{}
\SetupFloatingEnvironment{listing}{name=Listing,listname=Listingverzeichnis}