[Tex/LaTex] Nicely typesetting verbatim text

pdftexverbatim

I want an environment in which LaTeX typesets the text just like it otherwise would, but without accepting any commands whatsoever while within this environment. None of the answers to this question solves the problem. Neither does fancyvrb, nor the verbatim packages.

I need this functionality, as I'm composing a LaTeX document from several plain text sources, with text written by authors with no idea of TeX or LaTeX. So the environment should treat everything as normal text. It should break lines, hyphenate words and just do what LaTeX does to normal text.

Do anyone have an idea on how to solve this problem?

EDIT:

An example would be someone writing this, in the plain text input field:

Plain text input

That will result in the following PDF output:

enter image description here

All is still fine, but then someone comes up with the fine idea of writing "\textbf{}" somewhere in the text. It could really be anything, like "%" or "$" or "_", but I think you get the idea. The text input now looks like:

enter image description here

And the PDF output looks like:

enter image description here

But I want it to look like:

enter image description here

So, I'm looking for an environment like:

enter image description here

which still typesets the text like it would any other text, but ignores all special characters and commands. I really, really don't want to write a parser which does all of the magic if I can avoid it…

EDIT 2:

Using the method devised in the answer from David Carlisle:

enter image description here

results in this PDF:

enter image description here

So not quite there yet.

EDIT 3:

Mea culpa – We absolutely are there. I've forgotten to add the "\usepackage[T1]{fontenc}". I can't make it fail, so I'm happy. Thanks David!

Best Answer

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}

\setlength\textwidth{20em}


\begingroup
\makeatletter
\gdef\plaintext{\let\do\@makeother\dospecials\catcode32=10\relax\xplaintext}
\catcode`\!=0
!catcode`\\=12
!catcode`{=12
!catcode`}=12
!catcode`(=1
!catcode`)=2
!long!gdef!xplaintext#1\end{plaintext}(%
#1!end(plaintext))
!endgroup



\begin{document}


\begin{plaintext}

this % text has ^ & _ but seems to work alright, hyphenation 
or extremely longish words seems to work OK.

Blank lines do form a paragraph but \this is not an undefined
command and \includegraphics{this is not a picture}

\end{plaintext}

\end{document}