Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force line wrapping in listings package?

Tags:

latex

I have a problem concerning the listings package in latex. I need to embed a source code of the following XML document http://www.sparxsystems.com.au/downloads/profiles/EP_Extensions.xml in my master thesis' appendix. The problem is, no matter what options I pass to the package, I don't seem to be able to fit it on the page. The lines in the listing are too long, and the listings package doesn't wrap them, which seems odd... What combination of options will do the trick?

At the moment I use the following lstset instruction:

\lstset{ breakindent=0em, language=XML, basicstyle=\footnotesize, numbers=left, numberstyle=\footnotesize, stepnumber=2, numbersep=5pt, backgroundcolor=\color{white}, showspaces=false, showstringspaces=false, showtabs=false, frame=single, tabsize=2, captionpos=b, breaklines=true, breakatwhitespace=true, breakautoindent=true, escapeinside={\%*}{*)}, linewidth=\textwidth } 

Which, with no other options set, and combined with the following command:

\lstinputlisting{EP_Extensions.xml} 

Lists the given file's source to the following output: alt text

like image 991
Adam Avatar asked Jun 11 '09 13:06

Adam


1 Answers

I just had this problem...

breaklines worked for me, though you do need to set it to true - the default is false:

\lstinputlisting[style=Python,     caption=My Class,     label={mine.py},     breaklines=true,   ]{../python/mine.py} 

is pretty much what I used

like image 114
PeterJCLaw Avatar answered Oct 05 '22 07:10

PeterJCLaw