Why do people use braces around the control sequence in \newcommand?

The official latex syntax, as described by the LaTeX book only ever uses the braced form, and similarly always uses x^{2} rather than x^2.

However the unbraced form works fine and for arguments that are necessarily a single token such as the first argument of \newcommand. That is effectively also supported syntax and you will find many examples from the LaTeX Project team using that style.

Of course dropping braces technically also works even when the argument isn't necessarily a single token, people go \frac12 instead of \frac{1}{2} or even, x^\frac12 instead of x^{\frac{1}{2}} but really, they shouldn't....


There is no difference between those two commands. It is a matter of taste, I guess. I prefer the braced version. It looks more consistent to me, it is offered to me by the auto-completion of my IDE, and the starred version \newcommand*{\mycmd}[1]{Hello #1} which I would use for this very case, appears easier to read to me. I used "to me" three times in the last sentence... makes it clear that you might choose whatever you like.

I have done some tests on both commands and I am not able to spot any difference. As the rules for command-naming are quite strict, there should be no possibility to create any issue by leaving the braces apart.


When (La)TeX is "grabbing" an undelimited argument, leading space tokens will be discarded and the outermost level of braces [a pair consisting of a category-code-1-character-token and a matching category-code-2-character-token] will be removed if present. In case an undelimited argument is to consist of more than one token, these tokens must be nested into an additional level of braces which in turn will be considered the outermost level of braces that will be removed.

E.g., the following code-sequences yield the same result (\processtwo is defined in a way where the control-sequence is delimited by a dot while the arguments are undelimited—this way a space in front of the first argument will not be skipped by TeX' reading apparatus but will be tokenized as space token):

\def\processtwo.#1#2{%
  \def\tempa{FirstArg:|#1| SecondArg:|#2|}%
  \par{\tt\meaning\tempa}%
}
\processtwo.AB
\processtwo. AB
\processtwo.A B
\processtwo. A B
\processtwo.{A}B
\processtwo. {A}B
\processtwo.{A} B
\processtwo. {A} B
\processtwo.A{B}
\processtwo. A{B}
\processtwo.A {B}
\processtwo. A {B}
\processtwo.{A}{B}
\processtwo. {A}{B}
\processtwo.{A} {B}
\processtwo. {A} {B}
\bye

When (La)TeX is "grabbing" a delimited argument, leading space tokens will not be removed. In case the entire argument is wrapped into braces [into a pair consisting of a category-code-1-character-token and a matching category-code-2-character-token], this outermost level of braces will be removed.

E.g., the following code-sequences do not all lead to the same result (\processtwo is defined in a way where the control-sequence and the arguments are delimited by dots. By delimiting the control sequence also it is ensured that a space in front of the first argument will not be skipped by TeX' reading apparatus but will be tokenized as space token):

\def\processtwo.#1.#2.{%
  \def\tempa{FirstArg:|#1| SecondArg:|#2|}%
  \par{\tt\meaning\tempa}%
}
\processtwo.A.B.
\processtwo.{A}.{B}.
\processtwo.{A}.B.
\processtwo.A.{B}.
\medskip
\processtwo.A. B.
\processtwo.{A}. B.
\medskip
\processtwo. A.B.
\processtwo. A.{B}.
\medskip
\processtwo. {A}.B.
\processtwo. {A}.{B}.
\medskip
\processtwo.{A}. {B}.
\processtwo.A. {B}.
\medskip
\processtwo. A. B.
\medskip
\processtwo. {A}. B.
\medskip
\processtwo. A. {B}.
\medskip
\processtwo. {A}. {B}.
\bye

\newcommand itself is a macro. The first argument (after an optional * ) denotes the control sequence token that is to be defined. That argument by LaTeX is taken for an undelimited argument consisting of a single token (a single control sequence token). Therefore it makes no difference whether that argument/token is nested in braces or not.

But when it comes to processing brace delimited arguments (→ parameter text with #{-notation), braces do matter. Often from the syntax described in the user manual it is not obvious whether an argument of a user level macro is processed as an undelimited argument or as brace delimited argument. E.g., the color-package does a lot of processing by means of brace delimited arguments. In order to know about this subtlety, you need to look at the .sty-file or at the commented sources.

Tags:

Macros