I am confused, although I admit this is the first time I am using lstlisting
. I want to insert some python code in my thesis appendices.
Some lines may be quite long. But the document doesn't seem to be able to break the lines and keep the document's margins. Is there a way to set linebreaks when the code reaches the page margin?
Currently I have something like this (sorry, my preamble has 200 lines, I won't insert it all here).
\documentclass[a4paper,12pt,twoside,openright, english]{book}
\usepackage{listings}
\section{Python code}
The following sections include the functions and scripts.
\begin{lstlisting}[language=Python]
import numpy as np
import pandas as pd
import os
dir = # insert here path where the data are saved
files = []
for f in os.listdir(dir):
if (f.startswith('Temp'))&(f.endswith('matched.csv')): # find matched logs
files.append(f)
# some MANUAL INPUT for plotting
interval=(0,-1) ## for slicing of relevant logs
polyOrder = 6
# etc.
\end{lstlisting}
Can I modify the setting somehow, so that the code doesn't just "walk off" the page?
Best Answer
This should probably work.
Output:
If you don't want the red arrows,