From 5f9a41bc40e35da5ac2f7b1d1abca52c9054cfec Mon Sep 17 00:00:00 2001 From: Dominik Becker Date: Thu, 26 Apr 2018 20:26:36 +0200 Subject: [PATCH] #8 migrated code listings to minted --- .gitlab-ci.yml | 2 +- .latexmkrc | 2 ++ README.md | 14 ++++++---- config/config.tex | 66 +++++++---------------------------------------- 4 files changed, 22 insertions(+), 62 deletions(-) create mode 100644 .latexmkrc diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3ce5e9d..bbb7079 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -11,7 +11,7 @@ latexmk: - main.pdf expire_in: 2d script: - - latexmk -xelatex main.tex + - latexmk main.tex hunspell: stage: test diff --git a/.latexmkrc b/.latexmkrc new file mode 100644 index 0000000..8c0c7e1 --- /dev/null +++ b/.latexmkrc @@ -0,0 +1,2 @@ +$pdf_mode = 1; +$pdflatex = 'xelatex --shell-escape'; \ No newline at end of file diff --git a/README.md b/README.md index 2ffbd36..45fa5df 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/config/config.tex b/config/config.tex index bbe7ca3..5167fea 100644 --- a/config/config.tex +++ b/config/config.tex @@ -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}