Tilted Forum Project Discussion Community LaTeX help: code listings.

 Donate now! Members List Mark Forums Read

 04-12-2006, 12:11 PM #1 (permalink) Sky Piercer     Location: Ireland LaTeX help: code listings. Hi! I have just a few days ago started migrated from Microsoft Word to using LaTeX. So far I am quite impressed - but I am completely new to it, so I am still trying to find my way around it. One thing I want to do is include bits of source code listings into my document. Of course there are problems with that - I don't want to have to go through my entire source code and escape out all of the LaTeX 'reserved' symbols. So I have used the 'verbatim' environment, which works quite well, but there is one problem - it doesn't wrap lines! Can someone help me out here? __________________
 04-12-2006, 06:22 PM #2 (permalink) Addict Use the "listings" package instead. This gives the option of breaking long lines with an adjustable indent. "breaklines=true" sets the line break, and you can set specific symbols to put before and after breaks to indicate them using "prebreak" and "postbreak". This example comes out of "The LaTeX Companion, 2nd Ed." (Mittelbach and Goossens), page 173: Code: \usepackage{color,listings} \lset{breaklines=true,breakindent=0pt, prebreak=\mbox{\tiny$\searrow$}, postbreak=\mbox{{\color{blue}\tiny$\rightarrow$}}} \begin{lstlisting} SOURCE CODE GOES HERE \end{lstlistings} This package is also interesting because you can define what language you are coding in and it will do selective bolding, etc. In classic LaTeX style, it's a VERY customizable package. Oh, and I highly recommend that book I quoted. It's rather comprehensive. "A Guide To LaTeX" by Kopka and Daly is not bad either, but much more basic. Last edited by phukraut; 04-12-2006 at 06:29 PM..
 04-14-2006, 10:58 AM #3 (permalink) Sky Piercer     Location: Ireland Excellent! Thanks very much, that worked great. __________________
 04-15-2006, 11:45 AM #4 (permalink) Addict You're welcome. I learned something new too: I didn't know about the "listings" package until I looked it up. Cheers.

 Tags code, latex, listings