I found this snippet on the internet which is used to produce a text area inside a greybox.
\newcommand\greybox[1]{%
\vskip\baselineskip%
\par\noindent\colorbox{lightgray}{%
\begin{minipage}{\textwidth}#1\end{minipage}%
}%
\vskip\baselineskip%
}
I use it like this:
Normal text.
\greybox{Surrounded text.
Even on multiple lines}
to produce output like this:
Now, I need to put some source code inside this grey box, and I was planning to use verbatim
to do so. Problem is: verbatim
escapes %
-like characters, but when it is inside a \greybox
(as defined above) it doesn't behave correctly.
Percent signs are interpreted as comments.
\greybox{
\begin{verbatim}
code with a % inside
\end{verbatim}
}
Obviously if I do the opposite, that is placing \greybox
inside verbatim, everything gets escaped and \greybox
is not interpreted.
Any solutions to the problem? I don't mind using listings
or other packages if necessary.
\%
?mdframed
where you'd have an environment. There verbatim would work.