TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In this document:

  \foo x-z;

The use of \foo in AVerb produces an error:

! Argument of \foo has an extra }.
<inserted text>
l.11   \foo x-z;

The catcode for - in the AVerb environment is 13 (active), but in normal text it is 12 (other).

I tried setting the catcode for - to 12 using fancyvrb's codes option but that didn't help. I believe this is because - can be a ligature and fancyvrb overrides my setting.

Is there a way to make this work?

share|improve this question
up vote 2 down vote accepted

Yes, the problem is exactly that: your delimiter has category code 12 and TeX can't find it in verbatim text where it's active exactly for the reason you're mentioning. The code

  \lowercase{\endgroup\def\foo #1~#2;}{}

will define \foo with the first argument delimited by an active -.

If you need \foo also in other places, then define it as you did and say also

  \lowercase{\endgroup\def\vfoo #1~#2;}{}

Then, with the help of the mighty \usepackage{etoolbox}, say


(after having defined the AVerb environment).

How does the trick work? We set, in a group, the lowercase equivalent of ~ equal to -; the operation \lowercase acts only on characters (not on control sequences), not changing category codes. It does not expand or execute commands, but simply does the conversion and puts back the token list for examination by the input processor. Only after this conversion \endgroup is executed, so the equivalence is forgotten, but ~ has already been transformed into an active hyphen.

share|improve this answer
Defining vfoo works as advertised, though it took me awhile to figure out that the active status of ~ also played a role (in making - active). However, \let\foo\vfoo does not work -- I get the same error. But that's ok, I can use \vfoo. – Justin Bailey Nov 15 '11 at 18:03
@JustinBailey I've added a trick and also some comments. – egreg Nov 15 '11 at 18:26
Cool, thanks for the updated text. I haven't seen etoolbox before. Very nice! – Justin Bailey Nov 15 '11 at 20:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.