14

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?

7
  • * is the only one (apart from a space, of course). But sticking to | or ! or " is better.
    – egreg
    Commented Sep 28, 2014 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
    Commented Sep 28, 2014 at 13:44
  • @egreg = is also quite common
    – Joseph Wright
    Commented Sep 28, 2014 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
    Commented Sep 28, 2014 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
    Commented Sep 28, 2014 at 15:08

1 Answer 1

13

* 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^^@
2
  • 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
    Commented Sep 28, 2014 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 Commented Sep 28, 2014 at 14:40

You must log in to answer this question.

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