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

I'm trying to make a verbatim environment called "my-environ"



\DefineVerbatimEnvironment{myenviron}{Verbatim}{numbers=left,frame=lines,label=My Environ,labelposition=topline}






If you uncomment the code, you'll see that it doesn't compile. I don't have to use fancyvrb, but I would like similar functionality.

share|improve this question
Because dashes are not allowed in control words (control sequences consisting of an escape character and followed by one or more letters), dashes are not allowed in environment names either. Suggestion: use myEnviron instead. – Jubobs Apr 20 '14 at 19:40
Thanks - good to know. – Bart Snapp Apr 20 '14 at 20:13
up vote 10 down vote accepted

In his answer egreg has already explained that the hyphen - has a different catcode inside the verbatim environment. Package fancyvrb saves the environment name from \begin{my-environ} in \FV@EnvironName. - has the catcode before the catcode changes of the verbatim environment, usually 12 (other). Then inside the environment fancyvrb looks for \end{...} and checks if ... matches \FV@EnvironName. But - has now catcode 13 (active) and the strings my-environ does not match because of the different catcode of - and fancyvrb fails to see the end of the environment.

The example hacks the macros of fancyvrb to define \FV@EnvironCheckName that stores my-environ with the catcodes of the verbatim environment. The hack requires e-TeX because of \scantokens, \everyeof, and \unexpanded to get the unexpanded environment name with the catcodes, which are active after the catcode settings of the verbatim environment.




      \endlinechar=-1 %
  \ifx\@tempa\FV@EnvironCheckName%            % True if end is found





share|improve this answer

The problem is quite subtle. In general, a hyphen is allowed to be in an environment name, just like any other non special character (and also some special ones, actually). However, it's not possible to use some of them in a verbatim environment, because the verbatim mode makes them active; in latex.ltx you find


and the characters in the list, that is `<,'- are made active in order (La)TeX not make the usual ligatures

?` !` << >> ,, `` '' -- ---

However, the end of your verbatim environment is delimited by a string


which fancyvrb builds before setting the active characters above. A string in the sense that all characters have category code 12; fancyvrb loads a line at the time and compares it to the ending string. However, if the name of the environment contains one of the characters above, the ending string can't be found.

It's maybe possible to hack the macros so that those characters are allowed, but the best is to use only letters.

share|improve this answer
This is good to know! (I realize the question seems crazy) – Bart Snapp Apr 20 '14 at 20:13

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.