# # Including Code with 'listings'

→ Included in the report/thesis template by default. Add \usepackage{listings} to the preamble of the article template to use it there. See below for the additional settings used.

In order to easily add source code to LaTeX documents, listings or minted are often used. As the latter has some prerequisites and requires access to the shell to function, the package listings is used in the report/thesis template.

Adding displayed code can be done by creating a lstlisting environment and adding the source code to that environment. An example with Python as the programming language can be found below:

\begin{lstlisting}[language=Python]
# Impressive sample code

someText = "Hello World"

for i in range(5):
print(someText)
\end{lstlisting}


Stand-alone files can also be inserted directly:

\lstinputlisting[language=Python]{filename.py}


## # Package Options

One way to define the formatting of the source code is by using the \lstset{} command. The following settings are used in the report/thesis template:

\lstset{
basicstyle=\ttfamily\footnotesize,  % Style of the font that is used for the code
backgroundcolor=\color{gray!10},    % Background color
keywordstyle=\color{red!75!black},  % Keyword style
stringstyle=\color{green!40!black}, % String style