How to break lines with the listings package in LaTeX
2005-06-07
1 minute read

LaTeX is a really nice typesetting language and it has a nice tool called listings which handles program listings for you. By default, listings doesn’t break lines. Why it doesn’t do that is beyond me, but I’m sure the author has his reasons. It does however have support for breaking lines quite easily. The trick is using something along the lines of:

\lstset{
basicstyle=\small,
showstringspaces=false,
language={},
breaklines=true,
breakatwhitespace=true,
prebreak={\mbox{\hfill$\hookleftarrow$}}}

which renders into

A line of code with a break symbol at the end

Back to posts