5

The following code compiles and generates the pdf properly:

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\zero}{\overline{0}}

\begin{document}

Writing $V_\alpha$ does not give problems.

\end{document}

However, the following code does give problems:

\documentclass{article}
\usepackage{amsmath}

\DeclareMathOperator{\zero}{\overline{0}}

\begin{document}

Writing $V_\zero$ gives problems.

\end{document}

Why is that? Is there any way to make \zero work like \alpha?

3
  • Even with \zero defined by \def\zero{} (which is the way to define a macro in raw TeX), you can't write V_\zero. It's more V_\alpha which seems an exception (the standard definition of \alpha is \mathchar"010B). Commented Apr 26, 2023 at 19:18
  • @F.Pantigny You could expand that comment into an answer.
    – Zero
    Commented Apr 26, 2023 at 19:26
  • 1
    the latex syntax is always to brace, precisely to avoid exposing the internal definition of each command to determine when it is possible to omit the braces. Commented Apr 26, 2023 at 19:58

2 Answers 2

4

In the TeXBook, p. 128, it's said : Notice that ^ and _ apply only to the next single character.

Therefore, the fact that V_\alpha works should probably be considered as an exception. Remark that the standard definition of \alpha is \mathchar"010B.

With a macro, defined in raw TeX by \def, it does not work (at least, it does not always work) since, with \def\zero{}, you can't write V_\zero.

Remark also that what follows ^ of _ is not treated by TeX as the argument of a macro. The characters ^ and _ are very special (as special, let's say, as { or #). The catcode of ^ is 7 and the catcode of _ is 8 (whereas, for example, the catcode of { is 1, etc.). That means that you should not expect ^ and { to have the behaviour of a macro (even a character with catcode 13 which behaves as a macro).

Many people would probably recommend writing V_{\alpha} (as they recommend writing \frac{1}{2} instead of \frac12 — which works...).

0
6

While it is “almost correct” to say that TeX regards what comes after ^ or _ like the argument to a macro, it's actually skipping a fundamental fact about them.

And this is where things go wrong with your V_\zero.

The fundamental difference with argument to macros is that when you have a macro taking an argument (an undelimited one, to be precise), say \foo, then TeX will look for the argument without doing any expansion: if an open brace follows, then the entire content up to the matching closing brace will be taken as the argument; otherwise the next token will be taken as the argument.

To the contrary, upon seeing ^ or _, TeX will expand tokens in order to see whether an open brace (possibly implicit) follows; in the process, \relax and space tokens are ignored. Such expansion process terminates as soon as an unexpandable token (other than \relax or a space) is found; if it is an open brace, then the argument will be grabbed up to the matching closing brace (that can be implicit as well).

Thus you can do

V_\bgroup 10\egroup

and this will take 10 as the subscript. Note that if \foo is a macro taking an argument, then \foo\bgroup 10\egroup will take \bgroup as the argument (probably with bad side effects).

You can test it with simple plain TeX code.

\def\foo#1{(#1)}
\def\x{\bgroup}
\def\void{}

\foo{10}

\foo\bgroup 10\egroup

$V_{10} = V_\bgroup 10\egroup=V_\x 10}$

$V_\void x$

\bye

enter image description here

With \foo\bgroup 10\egroup, the token \bgroup is taken as the argument so the input stream will become

(\bgroup)10\egroup

(second line). The third line shows that all those (bizarre) inputs lead to the same result.

The fourth line shows that \void is expanded; the expansion is empty, so TeX keeps looking for an unexpandable token (with macro expansion); it finds x, so it takes it as the subscript.

Why does V_\alpha work? Because \alpha is an unexpandable token. It is not defined as

\def\alpha{\mathchar"010B }

but with

\mathchardef\alpha="010B

which is very different. So the look up for an unexpandable token ends when \alpha is scanned.

If you ask LaTeX to show how your \zero is actually defined with \show\zero, you will see

> \zero=macro:
->\protect \zero  .

(there's a space in the name of the final command, but this is not important). The rules explained above have the consequence that \zero is expanded to \protect\zero• (the bullet denotes the space in the name). Since \protect is equivalent to \relax, in this context, it is ignored, so TeX expands \zero•.

If you do \ShowCommand\zero you get

> \zero=robust macro:
->\protect \zero  .

> \zero =\long macro:
->\qopname \newmcodes@ o{\overline {0}}.

so the first token remaining in the input stream is \qopname. Now \ShowCommand\qopname produces

> \qopname=robust macro:
->\protect \qopname  .

> \qopname =\long macro:
#1#2#3->\mathop {#1\kern \z@ \operator@font #3}\csname n#2limits@\endcsname .

The situation is similar: \protect is ignored and \qopname• is expanded; now the error appears, because \mathop is unexpandable, so it is taken to be the whole subscript, but it is illegal to do

V_\mathop

for easy to understand reasons.

Conclusion: it's OK to write something like V_\alpha or V_1, but avoid omitting braces when you're not sure. Better yet, always brace subscripts and superscripts.

You must log in to answer this question.

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