13

Recently I inherited some LaTeX code for a CV that contained an e-mail address typed with \verb}john.smith@uni.org}. This snippet was in the middle of an multicol environment (so it was within several nested curly brackets) and it took me some time to figure out why this would compile but \verb{john.smith@uni.org} wouldn't. I've since learned how \verb works (and that one should use other symbols as delimiters), but I am baffled about a LaTeX function that doesn't follow the syntax \name[...]{...}. So my question is as follows:

Are there other LaTeX commands that have surprisingly (sic) inconsistent syntax compared to the more often used commands? And, was \verb originally contained in TeX or was it added later on?

EDIT: Thank you for your answers, I'd select both of your answers as an accepted answer if I could. I liked the comparison with the TeX primitives, and for me the fact that \verb|...| is usually used for displaying LaTeX source code is a good explanation why it differs from the syntax most other functions use.

3
  • 4
    Welcome to TeX.SX! The syntax of \verb is very consistent: the material to be rendered verbatim must be enclosed between two identical characters (not appearing inside, of course).
    – egreg
    Feb 6, 2015 at 14:53
  • 11
    Which is why a more common (but not necessary) syntax is \verb|...|, since there is no left/right sense to | as opposed to { and }. Feb 6, 2015 at 14:54
  • Appendix E of the TeXBook explains in detail how Knuth defined a verbatim environment for typesetting his books.
    – Thruston
    Feb 6, 2015 at 15:10

2 Answers 2

18

In all languages the syntax of the command that breaks out of the normal syntax is different. If the syntax was \verb{...} you would not be able to have an argument of }{

Compare the CDATA construct in XML and (sometimes) HTML which has use very close to verb and very different from normal element syntax.

<![CDATA[  <  * <bad xml ]]>

\verb is defined in LaTeX and one of the few commands not to follow the usual argument syntax. This could be compared with the TeX primitives that have wildly different syntax in each case:

{a \over b } not \frac{a}{b}

\input file not \input{file}

\hskip 3pt plus 2pt minus 1pt not \hspace{3pt}

\def\zz#1#2#3#4#5{..} not \newcommand[5]{....}

etc.

5
  • 1
    your \hspace argument isn't parallel to the \hskip one. would be less confusing if they were parallel since all the others are. Feb 6, 2015 at 16:03
  • @barbarabeeton but latex doesn't offer a sane syntax for plus and minus, so it is what it is, don't shoot the messenger:-) Feb 6, 2015 at 16:08
  • oh, grumble! i guess that's why i usually ignore \hspace and use \hskip instead. (i must have learned that sometime, but forgotten it. and just put up with the vilification i get for using plain syntax instead of what's latex-approved. hmmmmph.) Feb 6, 2015 at 16:11
  • @barbarabeeton you can do \hspace{3pt plus 2pt minus 1pt} but I'm not sure that counts as consistent syntax form:-) Feb 6, 2015 at 16:19
  • 1
    well, i think that's what i meant when i asked for parallel. oh, hang mindlessly consistent syntax! (the "inconsistency" here is actually in the requirement for braces. my view on braces is succinctly expressed in the title page (mis)quote of tugboat 5:1; sorry the title page isn't posted separately.) Feb 6, 2015 at 16:28
21

You start from the assumption that the syntax of \verb is inconsistent, but this is not true:

\verb<char><material><char>

where <char> is pretty much any character not appearing in the <material> to be typeset verbatim. Not really any, but quite; for instance * is not allowed unless one uses the \verb* variant. So \verb**foo* is legal, but \verb*foo* isn't.

The “inconsistency” is with the syntax is of the other commands, but this is necessary, at least if you think that \verb is mainly used for explaining TeX commands and so braces, even unmatched ones, should be allowed in the <material>.

The main reason for doing in this way is that special characters in the <material> must lose their meaning to be typeset. So \ { } # % & are not interpreted in any way. However this means we can't use {} for absorbing the <material>, because it would be too late. In case braces don't appear or are in matching pairs, it would be somewhat possible, but this would limit disallow cases such as

\verb|\command{|\meta{arg}\verb|}|

(define \meta as you please).

There is no “verbatim” mode defined in Plain TeX.

You must log in to answer this question.

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