# Double subscript error with \newcommand?

Disclaimer: I know of Defining a newcommand with sub- or superscript and avoiding "double subscript" error but this only gives a work-around, but no explanation to my question.

Here's a summary of the problem. This code:

\documentclass{article}

\newcommand*{\one}{a_1}   %no explicit brackets
\newcommand*{\two}{{a_1}} %explicit brackets

\begin{document}
$b_\one$ % error: Double subscript
$b_\two$ % no error
\end{document}


Gives me the error Double subscript on b_\one. Why? When do I need the "scope" brackets and when do I not need them? I always thought a command defined by \newcommand is "automatically" a single "object" on its own that does not need to be put inside brackets.

The question is not why one needs brackets at all (this is clear), but the question is why one needs them in the defintion when using \newcommand?

By the way, what is the correct "vocabulary" for the "scope" and "object" in LaTeX?

-
The braces in the definition part of \newcommand do not form a group. In your example, you need to explicitly group. – Gonzalo Medina Apr 18 '13 at 14:40
$b_{\one}$ will work as your 2nd definition does – Herbert Apr 18 '13 at 14:42
@GonzaloMedina Apropos "correct vocubulary": A subformula is needed, e.g. via explicit curly braces or \bgroup and \egroup. A group alone (\begingroup and \endgbroup) will not work. Subscripts and superscripts do not expect macro arguments but math atoms. – Heiko Oberdiek Apr 18 '13 at 14:57
@HeikoOberdiek yes. I should have been more precise. – Gonzalo Medina Apr 18 '13 at 14:59

The extent to which a "command defined by \newcommand is 'automatically' a single "object" on its own" varies by context.

• Certainly such a command is a token, which is an atomic object in TeX's parser. When TeX is reading input, it receives any token as a whole, regardless of its expansion (if any).

• It is also an expandable token, which means that it is not an atomic object in TeX's interpreter. In various situations, the input is subject to expansion, in which all expandable tokens are (successively left-to-right) replaced by their meanings.

• It is not, as David explains, a "brace group", which is often treated as a single object, particularly when taken as an "argument" to a macro or function-like primitive operator (such as the subscript symbol).

One of the situations in which tokens are expanded is when a subscript symbol is looking for its operand; it expects either a brace group or a single character (or control sequence equivalent to a character). Thus, most \newcommand macros can't be used openly as subscripts, if they expand to more than one token that aren't braced.

-

Braces in TeX are used for (at least) two distinct purposes. They are used for delimiting macro arguments and macro definitions, and they are used for making local groups, these two uses are distinct.

If you go

\def\mybold{\bfseries}


then the {} just delimit the extent of the definition it does not form a group that limits the scope of the \bfseries (otherwise the command would do nothing useful at all)

Similarly if you define

\def\zz#1{xxx#1yyy}


and use it as

\zz{abc}


The {} around abc do not form a group and are discarded as soon as the macro argument has been collected. You can see this if you de

\zz{ab\bfseries c}


this expands to

xxxab\bfseries cyyy


with no brace group and the yyy go bold.

-