I have seen \verb's argument delimited by many characters. I started out with " ", then I saw it done with # # and verified it worked, and I just saw it done with | | right here in egreg's answer. So I was wondering: what other characters can be used? Is there any difference in using one delimiter or another? In fact, seeing this makes me wonder: is there any symbol I can't use with \verb?

  • * is the only one (apart from a space, of course). But sticking to | or ! or " is better. – egreg Sep 28 '14 at 13:41
  • Is there any reason to choose a specific delimiter except for "aesthetic" reasons (which are reasons of taste alone) and needing a character inside the \verb as in the case of the linked question? – MickG Sep 28 '14 at 13:44
  • @egreg = is also quite common – Joseph Wright Sep 28 '14 at 13:44
  • And characters with \catcode 11 (letter) can't be used, can they? What \catcodes allow characters to delimit \verb's argument? – MickG Sep 28 '14 at 13:47
  • 2
    @MickG Getting a letter delimiter is a bit tricky but doable: we need to tokenize \verb without tokenizing what follows. For example \makeatletter\@firstofone{\verb}a#%a – Joseph Wright Sep 28 '14 at 15:08

* makes \verb* so can't be used for the non-star form without hacking internals, but apart from that any character may be used, the reason is that you need to choose a character that is not in the string that is being set verbatim.

Note that latex doesn't make all symbols safe in verbatim (or for the verb delimiter) If you try to use an ascii null (byte 0) as the delimiter you get

! Text line contains an invalid character.
l.6 \verb^^@
  • Which means if I change " to the \catcode of ^^@ (ASCII null) it will give the same error if I use " for the \verb delimiter, right? – MickG Sep 28 '14 at 14:36
  • @MickG yes the error is nothing to do with verb: latex sets \catcode0=15 so 0 is an illegal character pretty much anywhere and its verbatim code doesn't (but could) change that – David Carlisle Sep 28 '14 at 14:40

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.