4

I am using the fancyvrb package to be able to have formatting (e.g., bold, color, etc.) in my verbatim environments.

This is easy enough to do by giving the commandchars option as seen in this MWE:

\documentclass{scrartcl}
\usepackage{fancyvrb}
\usepackage{xcolor}

\fvset{
  commandchars=\\\{\}
}

\begin{document}

\begin{Verbatim}[frame=single]
  Here is some \textbf{bold} and {\color{red} red} text in a Verbatim environment.
\end{Verbatim}

\begin{Verbatim}
  Here is some text that breaks \
  because it is expecting a command
\end{Verbatim}

\end{document}

In most of my environments I want this formatting which is why I have

\fvset{
  commandchars=\\\{\},
}

However, there are a few of my Verbatim environments that I don't want commandchars set. (There is no formatting and the verbatim text contains \, which makes it look like the beginning of a command.)

So how can I "unset" the commandchars option so that it returns to the default? I've tried doing simply commandchars=, but then I get the error:

`commandchars' undefined
  • @ChristianHupfer Sorry, I thought it was enough. I guess I was wrong. – jlconlin Feb 23 '17 at 18:31
  • 1
    Does this help \begin{Verbatim}[commandchars=none] ...? – Arash Esbati Feb 23 '17 at 19:50
  • @ArashEsbati Well, it did help for my MWE, but I couldn't get it to work with my non-MWE. Something else must be changing it elsewhere. – jlconlin Feb 23 '17 at 20:15
  • @ArashEsbati Okay, now that I've played with my full example, I've gotten your answer to work. If you make it into an answer, I'll accept it! – jlconlin Feb 23 '17 at 20:29
3

fancyvrb defines the commandchars key like this:

\define@key{FV}{commandchars}[\\\{\}]%
  {\def\@tempa{#1}%
    \ifx\@tempa\FV@None
      \let\FV@CommandChars\relax
    \else
      \FV@DefineCommandChars#1\relax\relax\relax
    \fi}

It checks if the value given is equal to \FV@none, which expands to none. If true, it unsets the key, otherwise it defines it with the given value. Hence, you can unset this key for a single environment by doing something like this:

\documentclass{scrartcl}
\usepackage{fancyvrb}
\usepackage{xcolor}

\fvset{
  commandchars=\\\{\}
}

\begin{document}

\begin{Verbatim}[frame=single]
  Here is some \textbf{bold} and {\color{red} red} text in a Verbatim environment.
\end{Verbatim}

\begin{Verbatim}[commandchars=none]
  Here is some text that breaks \
  because it is expecting a command
\end{Verbatim}

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