I have some programming language code examples in a fancyvrb \Verb!...! expression. This includes the modulus operator which happens to be a percent sign, e.g.

\Verb!(1..100) select: { arg i; i % 7 == 0 }!

This causes two problems. First, TeXShop thinks there is a line comment beginning after the % (just as this stackexchange display gets it wrong). This is a purely aesthetic problem.

But more severely, while the document gets properly set with LaTeX, the texcount and texcountfull programmes jump off the rails, and produce an error which makes the word count stop at that point till the end of the .tex file:

!!! Warning: END group without type while waiting to end tabular. !!!

!!! Warning: END group without type while waiting to end sidewaystable. !!!

(The \Verb appears within a table within a rotate figure).

I guess I must find some workaround by escaping the % characters. But how?

  • you are doing something different. Using a minimal example with only loading fancyvrb will not create such warning. So create a complete example which shows your behaviour! And is there any reason why you do not use \verb (lowercase v)
    – user2478
    Jan 10, 2013 at 16:51
  • @Herbert the warning is emitted by the texcount macro. As I said, the text is set correctly, but the wordcount chokes. I'll try to create a full document to post here. I am using fancyvrb all over, because of easier font customisation, I don't want to switch to \verb.
    – Emit Taste
    Jan 10, 2013 at 16:53
  • I don't think texcount is aware of \Verb; it knows \verb and verbatim. I don't know if one can extend it to treat also \Verb.
    – egreg
    Jan 10, 2013 at 16:54
  • 1
    what is texcount? A package?
    – user2478
    Jan 10, 2013 at 16:54
  • It's a utility to generate a word count of latex files (words in main text, headers, footnotes, etc., per chapter). It's a standard CTAN package I think.
    – Emit Taste
    Jan 10, 2013 at 16:59

4 Answers 4


The easiest way to deal with this is probably a simple patch to texcount.pl. Search the script for \verb to find this block:

  } elsif ($next eq '\verb') {

Then simply add a copy of this block with \Verb instead of \verb:

  } elsif ($next eq '\Verb') {

This should get rid of the errors.

It seems that texcount doesn't know about sidewaystable, so the count of floats may be off unless you figure out how to add it.

  • @Emit_Taste Also, based on this answer, could you simply add \let\verb=\Verb in your preamble, and then use \verb instead of \Verb in the rest of your document? If this works, that would avoid the patch to texcount.pl.
    – JLDiaz
    Jan 10, 2013 at 17:29
  • Thanks, I will take this as an answer if nothing else shows up. @JLDiaz - unfortunately the alias doesn't help.
    – Emit Taste
    Jan 10, 2013 at 17:47

I could get as far as this:


\Verb[commandchars=\\<>]!(1..100) select: { arg i; i \escapepercent 7 == 0 }!

This makes everything in the system happy. The only two things I don't like is (a) there is always a space character after the inserted percent. This is fine for the examples I have right now, but I would like to control this explicitly. (b) I can't get to use other grouping characters with commandchars, which is nasty because < and > may also appear in the source. For example, \Verb[commandchars=\\äö] would always print the group closing character (in this case ö) for some reason...

Finally if I could define an alias for the above \Verb so that I don't have to type the commandchars in every occurrence, that would help.

If you help me on these ones, I'm happy to check your answer :)

  • Spaces in \Verb are not normal spaces, so they aren't ignored at the end of control sequences. If you use UTF-8, ä is two tokens, as far as TeX is concerned, which become the delimiters. The following ö is then printed, because it remains in the input stream. However, if you use commandchars, I guess that \% will work without the need for \escapepercent.
    – egreg
    Jan 10, 2013 at 17:38
  • Ok. The problem is that basically all 7-bit ASCII characters occur in the language that I'm using, so I was hoping for some other characters. I use [utf8]{inputenc}, but that doesn't seem to help. I'm getting away now mostly with commandchars=\\!! although I might need to switch occasionally when the bang ! is used in the source. All a bit hackish...
    – Emit Taste
    Jan 10, 2013 at 17:42
  • @EmitTaste Remove inputenc package and try to compile with lualatex or xelatex, which have native utf8 support.
    – JLDiaz
    Jan 10, 2013 at 17:43
  • @JLDiaz this is not possible anymore. I have a 40K word text body, I already had a hard time when I updated the TeX version at some point during my work. I don't want to touch the packages any more if possible. Anyway, thanks for your comments!
    – Emit Taste
    Jan 10, 2013 at 17:46
  • @EmitTaste You can give it a try anyway and compile with lualatex. Perhaps the only change required is to remove inputenc.
    – JLDiaz
    Jan 10, 2013 at 17:47

For typesetting program fragments, look at the listings package. It knows of many languages, and does a good job at typesetting program fragments and even complete source files.

  • listings also works together with fancyvrb, not in all details, though.
    – Speravir
    Jan 10, 2013 at 23:55

Normally to escape a sign in LaTeX, you use \. So \%, not sure if this will work here, but it can't hurt to try. :)

  • Yes, I tried that. texcount then works, but fancyvrb prints also the backslash which it shouldn't of course.
    – Emit Taste
    Jan 10, 2013 at 16:49
  • This would obviously be a hack, but could you add a line break after % without changing the layout?
    – myrtille
    Jan 10, 2013 at 17:06
  • No :-( This gives "Forbidden control sequence found while scanning use of \FancyVerbGetVerb."
    – Emit Taste
    Jan 10, 2013 at 17:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .