3

In an existing document which is not to be modified (except for the preamble), all instances of \begin{verbatim}...\end{verbatim} should have their contents rendered not only in a monospaced font but also on a grey background.

How can this be done?

6

enter image description here

\documentclass{article}

\usepackage{color}

\let\oldv\verbatim
\let\oldendv\endverbatim

\def\verbatim{\par\setbox0\vbox\bgroup\oldv}
\def\endverbatim{\oldendv\egroup\fboxsep0pt \noindent\colorbox[gray]{0.8}{\usebox0}\par}

\begin{document}

text text text text text 
text text text text text 
text text text text text 
text text text text text 
text text text text text 
\begin{verbatim}
1
12
123\foo{\ $ &
}
\end{verbatim}
text text text text text 
text text text text text 
text text text text text 
text text text text text 
text text text text text 

\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.