[Tex/LaTex] Verbatim environment that can break long lines

line-breakingverbatim

I want to generate a PDF of user-submitted text using LaTeX. To handle crazy user input, I first thought about using the verbatim package, but of course it doesn't break up too long lines. Is there some package that works similar to verbatim (i.e., accept any input) but formats the text nicely?

Best Answer

The listings package provides you with a verbatim environment which can break lines:

\begin{lstlisting}[breaklines]
  Long user text
\end{lstlisting}

If the user text is in an external file you can also use:

\lstinputlisting[breaklines]{filename}