# Why various syntaxes for various commands?

I understand that the standard syntax of commands in TeX is

\name[optional-1]…[optional-n]{argument-1}…{argument-n}


The tabular environment, however, apparently takes its optional arguments after the required arguments, while item and hskip/vskip have their arguments after a space and not grouped in any way.

Why the inconsistency? Are there any more commands like tabular, item,a and the skip’s?

-
The optional argument to tabular goes just after \begin{tabular}, not after the mandatory argument. – egreg Sep 12 '13 at 10:23

Your initial understanding is incorrect. The [] convention for optional arguments is a LaTeX convention. One of the aims of LaTeX is to give a consistent command interface over the TeX primitives which have wildly inconsistent syntax.

For primitives:

\over is infix {a \over b} so LaTeX provides \frac{a}{b}

hskip is weird with the argument not delimited at all other than by the grammar for a length \hskip 0pt plus 3pt xxx LaTeX provides \hspace{0pt plus 3pt}xxx

However it is best to avoid having multiple optional arguments adjacent to each other. If the command is

\name[opt1][opt2]{main}


Then you can not supply the second option without supplying the first, but if the syntax is

\name[opt1]{main}[opt2]


Both optional arguments may be independently omitted.

See for example \newcounter or \newtheorem which have multiple options.

This soon gets out of hand so most modern packages if they want more options switch to a keyval system

\name[opt1=aaa,opt2=bbb]{main}


The standard LaTeX \newcommand only allows defining one optional argument, which must be the first argument, to avoid such problems.

-
Thank you for this answer, it explains a lot. I so wish TeX were more consistent that I must have forced my own wish on the actual state of things. Good to have it cleared up! – Kamil S. Sep 12 '13 at 19:59

You're making wrong assumptions, I'm afraid.

TeX has no notion of optional arguments in brackets and its syntax is, to say the least, not standardized. Some examples of TeX primitives:

• \hbox has optional arguments that specify the width of the box or how much spaces in the box should be spread out; so the cases are

\hbox{<material>}
\hbox to <dimen>{<material>}

• the argument to \hbox, \vbox, \vtop, \halign and \valign can be enclosed by \bgroup and \egroup; this is not allowed for the argument to \uppercase, \lowercase, where the left delimiter can be \bgroup, but the right delimiter has to be }

• \vrule has optional arguments specifying the width, height and depth; these are introduced by the keywords width, height and depth and there can be any number of them, the last specified win

• \hskip has optional arguments specifying the stretchability and shrinkability, introduced by the keywords plus and minus; but plus <dimen>, if present, must go before a minus <dimen> specification. It's not allowed to have multiple instances of the keywords.

• \over applies to everything preceding and following it in the (sub)formula it appears in, taking what precedes as the numerator and what follows as the denominator

Apart from the last case (which is a wrong decision made by Knuth), the way arguments are specified has its logic, though understanding it requires a rather deep knowledge of the TeXbook. In some cases the argument is delimited by braces, in others it isn't. The idea is that primitive commands are not supposed to be used in documents and so their syntax is peculiar for greater efficiency.

Plain TeX also sports a non standard syntax:

• for the cubic root of 27 you have to say $\root 3\of{27}$

• the argument to \beginsection is everything up to the first blank line (or explicit \par)

• the first argument to \proclaim is whatever precedes the first period and the second argument is everything from there up to the first blank line

LaTeX tries to set up conventions that are as uniform as possible. For instance, \makebox has two optional arguments and a mandatory one; the order is

\makebox[<dimen>][<alignment>]{<material>}


where the second optional argument doesn't make sense if the first is absent. Instead, \newtheorem has two optional arguments and two mandatory ones:

\newtheorem{<envname>}[<counter>]{<name>}[<counter>]


where only one optional argument can appear. If the first appears, it tells what counter should be used for the numbering of <envname>; the final optional argument specifies instead a “parent counter”. This is similar to the syntax for \newcounter:

\newcounter{<name>}[<counter>]


where the presence of the optional argument means that the newly defined counter should be reset when is stepped and numbered within it; an example is \newcounter{subsection}[section]. So

\newtheorem{thm}{Theorem}[section]
\newtheorem{prop}[thm]{Proposition}


means that thm and prop share the same counter, which is reset any time section is stepped and will have the representation <section number><thm number>.

You mention \item, which has an optional argument and no mandatory argument; the text following it is not passed to \item as an argument. Environments follow the same conventions, but the arguments follow \begin{<env>}; for instance

\begin{tabular}[<alignment>]{<columns>}


has, as usual, the optional argument before the mandatory one. In LaTeX only a handful of primitives have their use and are documented in the manual; none of them takes arguments (\par, \hfil, \hfill, \vfil and \vfill, IIRC).

-
Thank you for the elaborate answer! I didn't realize just how inconsistent TeX was. It's such a shame it's so mingled. Oh well, I guess every rose must have its thorns. – Kamil S. Sep 12 '13 at 20:04
@KamilS. It's not really inconsistent; but you have to guess the rules yourself, the TeXbook only show the syntax. But it's a rewarding job. – egreg Sep 12 '13 at 20:25