3

I am using pandoc to convert Markdown documents containing code blocks to PDF, and the intermediate TeX surrounds the code with \begin{verbatim}...\end{verbatim}. How can I stylize and format these sections to have a background color or a frame around it? I've tried fancyvrb, but the background color does not extend behind the text itself.

I've tried using the verbatim package and after reading the manual was able to modify \verbatim@processline to change the font color or add text in front of each line: \def\verbatim@processline{\fbox{\$ \the\verbatim@line}\par}. I would like to this for the entire chunk and modify other properties (frame, centering, etc) in the future. I thought the best way to do this would be to add a \begin{shaded} into \verbatim and add \end{shaded} into endverbatim. However, I run into an error when I do that:

\makeatletter
\def\verbatim{{\begin\{shaded\}}\begingroup\@verbatim 
\frenchspacing\@vobeyspaces\verbatim@start}
\def\endverbatim{\endtrivlist\endgroup{\end\{shaded\}}}
\makeatother

And the error message:

! Missing \endcsname inserted.
<to be read again>
                   \protect
l.1 \begin{verbatim}
  1. Is there a way to insert enclose the verbatim text in an environment that I can stylize later?
  2. If not, is there a better way of stylizing the verbatim environment? I cannot change to listings or similar packages that use \begin{lstlisting} since pandoc automatically inserts \begin{verbatim}?

MWE:

\documentclass{beamer}
\usepackage{xcolor, framed}
\definecolor{shadecolor}{RGB}{255,0,0}

\begin{document}

\begin{frame}[fragile]

\begin{verbatim}
Shade this text block
Shade this too
\end{verbatim}

\begin{shaded}
\begin{verbatim}
Shaded text here
And also here
\end{verbatim}
\end{shaded}

\end{frame}

\end{document}
  • Do you truly need a verbatim environment? For example, are you using any particular characters that are otherwise disallowed? Or are you merely interested in a typewriter style formatting of the text? – Werner Mar 15 '18 at 23:30
  • pandoc automatically uses a verbatim environment when converting from Markdown – Chris Mar 15 '18 at 23:32
  • You can probably change what Pandoc does; it's worth looking into that. (In the worst case you can completely redefine the meaning of verbatim in the preamble that Pandoc lets you add.) – ShreevatsaR Mar 16 '18 at 0:34
  • Does this answer help? tex.stackexchange.com/questions/171702/… – Steven B. Segletes Mar 18 '18 at 1:58
  • Actually, I realized that I can specify a --listings argument while calling pandoc which uses the listings package instead of verbatim and that helped my issue a lot! – Chris Apr 18 '18 at 3:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.