# Alternative commandchars in fancyvrb

In my Verbatim I need to specify colour for my code.

In this answer (fancyvrb alternate commandchars and \textcolor) the solution is to put this code in the preamble:

\newcommand*{\fvtextcolor}[1]{\textcolor{#1}{#2}}


and then use

\begin{Verbatim}[commandchars=&]
&fvtextcolor[blue][function]
\end{Verbatim}


My problem is the commandchars. \textcolor needs a pair of braces, but in my code I use all the pair of braces that is: () [] {}.

So is it possible to specify another pair of commandchars? Something like &fvtextcolor'blue''function' or &fvtextcolor"blue""function"?

• Yes, but you need two different characters: [commandchars=\&\\'] would use the backtick for the opening brace and the apostrophe for the closing brace. Any unused character is good. – egreg May 19 '14 at 12:06
• So this should work &fvtextcolorred'test' ? – Karsten Jancker May 19 '14 at 12:08
• Sorry, almost any unused character. :(; I tried with " and ! and it seems to work. – egreg May 19 '14 at 12:15
• Thank you so much, it worked! Can you post it as an answer, so I can mark the question as solved? – Karsten Jancker May 19 '14 at 12:17

In theory, any unused characters would do, but unfortunately for certain characters this conflicts with other parts of verbatim typesetting.

I've found out that

[commandchars=\&\"\!]


gives the expected result.

The characters that are likely not to work are

 < > , ' -


If you really need some of them, a workaround can be devised.