Skip to content
Johannes Schackniß edited this page May 11, 2021 · 5 revisions

The package listings is used to display code in the paper. Package xcolor is used for code highlightung and to make it look fancy.

Package documentation

listings

Short documentation
Long documentation

xcolor

Short documentation
Long documentation

Inline listing

Input:

\lstinline$var myValue$

You can write normal text and inbetween \lstinline$comes the inline listing aka code snippet$. Afterwards you can just continue writing normal text.

Output:

WIP

Code snippet

Input:

\begin{lstlisting}[caption={My caption}, label={lst:my-label-1}]
import numpy as np
\end{lstlisting}

Output:

WIP

Importing code from a file

Input:

\lstinputlisting[caption={Here comes the caption},
                label={lst:my-label-2}]
                {resources/code/placeholder.py}

Output:

WIP

Caption

WIP

Highlighting

Highlighting settings can be edited in config/packages.tex

Parameters

Parameter usage
language Enables code highlighting for this particular programming language (e.g. C++, Python, etc)
morekeywords Add aditional keywords for highlighting (seperated by ,)
captionpos Position of the caption (t = caption is displayed on top, b = caption is displayed on bottom)
breaklines Automatic line-breaking (true/false)

Example

\definecolor{comment}{HTML}{0A943F}
\definecolor{linenumber}{HTML}{424445}
\definecolor{keyword}{HTML}{184FDB}
\definecolor{background}{HTML}{F2F2F2}
\definecolor{string}{HTML}{DB9418}

\lstdefinestyle{code}{
    backgroundcolor=\color{background},   
    commentstyle=\color{comment},
    keywordstyle=\color{keyword},
    numberstyle=\tiny\color{linenumber},
    stringstyle=\color{string},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2,
    morekeywords={
    	var
    }
}

Clone this wiki locally