TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from stackoverflow.com Mar 27 '11 at 9:45

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

Did you find the solution¿? – nowf Sep 20 '10 at 9:08
I didn't find a way to use the verbatim package - instead I tried to cover all special cases by unrolling all LaTeX commands and all "special" characters. – kotlinski Sep 20 '10 at 14:02

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

  Long user text

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

share|improve this answer
See also the answer at <tex.stackexchange.com/questions/11973/…; for an example of adjusting the formatting of the lstlisting environment. – Scott Morrison Feb 26 '13 at 23:05

This is a very long line.1


The spverbatim package enables LaTEX to break lines at spaces within verbatim text.

share|improve this answer
@MartinScharrer I am trying to create my own environments with this package. See tex.stackexchange.com/questions/309042/… – macmadness86 May 11 at 13:36

Depending on what you exactly need, this might be sufficient: we reset all special characters to catcode other, in particular \, { and } lose their meaning. This will make it pretty hard to inject LaTeX code.



  \dospecials\catcode`\ 10

And to show it, we input ourselves: \saferead{test.tex}
share|improve this answer

You can use \def\@xobeysp{ } in the preamble of your document to make all spaces regular (breaking) spaces. This will not hyphenate or break ultra-long words, though.

To format the text nicely, you can use the Verbatim environment, in the fancyvrb package:

  Hello world hello world hello world

Will print the text in a Sans-seriF font family.

Though (I'm sorry!) the \def\@xobeysp{ } won't work with the Verbatim environment... So you must choose between the two.

share|improve this answer

Your Answer


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