Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am using the listings package to include sample Perl source code in LaTeX. I included the package with \usepackage{listings}, and used the following code:

\lstset{language=Perl}
\lstset{commentstyle=\textit}
\lstset{frame=shadowbox}
\begin{lstlisting}[numbers=left]
$subject = "<owamp:subject xmlns:owamp=\"http://ggf.org/ns/nmwg/tools/owamp/2.0/\" id=\"subject\">\n";
\end{lstlisting}

The resulting output is:

Screenshot of the output

The line doesn't seem to breaking, but I read that lines break automatically when using the listings package. This line is the entire PDF snapshot of the code.

Am I doing anything wrong as far as the code is concerned?

share|improve this question
add comment

migrated from stackoverflow.com May 13 '12 at 20:33

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 8 down vote accepted

Use breaklines=true:

enter image description here

\documentclass{article}

\usepackage{listings} 
\lstset{language=Perl}
\lstset{commentstyle=\textit}
\lstset{frame=shadowbox}

\begin{document}
\begin{lstlisting}[numbers=left, breaklines=true]
$subject = "<owamp:subject xmlns:owamp=\"http://ggf.org/ns/nmwg/tools/owamp/2.0/\" id=\"subject\">\n";
\end{lstlisting}\end{document}
share|improve this answer
    
Thanks! I thought line breaks are true by default... –  user840546 May 13 '12 at 17:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.