8

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?

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

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

16

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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