8

Because space is a delimiter when parsing macro names, I got used to ending macros in running text with {} like in text \foobar{} text, because I find the escaped space in text \foobar\ text disturbing. Sometimes this habit spills over into math mode. Obviously

\[
    \sum{}^{...}
\]

does not work as intended when really

\[
    \sum^{...}
\]

was meant. How are they parsed and what are the differences?

Edit: I meant the \foo\ solution, not a double space.

4
  • 1
    Because sum takes no arg, it is just inperpreted as an empty atom and typeset accordingly.
    – daleif
    Nov 22, 2020 at 15:56
  • 1
    You shouldn't use {} to delimit commands in math mode. There is no problem with spaces. And {} after a command name is rarely needed anyway.
    – egreg
    Nov 22, 2020 at 15:57
  • BTW: typing a double space after \foobar in text mode is the same as a single space ;)
    – cgnieder
    Nov 22, 2020 at 16:37
  • I find it somehow more natural to use {\foobar} in text: you're isolating the command this way (but I use both in practice). Nov 23, 2020 at 7:54

3 Answers 3

11

TeX creates math list which is (roughly speaking) a sequence of atoms, each atom has nucleus+subscript+superscript. Each part of the atom can be empty. The sequence of atoms are converted to the definite \hboxes (raised or lowered) in the second pas of scanning math mode material.

First example \sum{}^a creates first atom with nucleus: sum character, subscript and superscript are empty. It is followed by second atom with empty nucleus, empty subscript and superscript is a.

Second example \sum^a creates only one atom with sum character in nucleus and a in superscript. The subscript is empty.

The differences in visible output is given by differences in interpreting the two atoms versus one atom in second pass over math material. The positioning of superscript depends on the size of the nucleus and on the type of the atom.

9

The technical reason is that, in math mode, {} is a math atom and is not something that gets discarded.

It's generally not a good idea to define macros to stand for text, because this reduces readability of the code, but in some occasions some macro that's not to be followed by arguments has to be used. The typical example is the command \LaTeX.

Anyway, if you have text commands that are not to be followed by a argument in braces, terminating it with {} is a good strategy for keeping a following space.

In math this is disastrous, as you witnessed. Just leave a space: if you want to type the sine of x, do \sin x. Never use {} to terminate a command name in math mode: compare

\sin(x+y)
\sin{}(x+y)

to see the reason:

enter image description here

In standard math typesetting there should be no space between “sin” and the parenthesis. The empty atom {} is of type “ordinary” and will trigger the space like in \sin x.

What happens with \sum{}_x^y? That the subscript and superscripts are to the (empty) atom represented by {}: the \sum atom has already gone its way.

1
  • @gernot Thanks for noting the inconsistency.
    – egreg
    Nov 22, 2020 at 20:44
5

In the first version, \sum and {}^{...} are independent of each other. The second is typeset the same way, independently of \sum. The result of \[ \sum{}^{a}\qquad {}^{a} \]:

enter image description here

In the second version, the exponent is attributed to sum and is interpreted as upper limit. The result of \[ \sum^{a}\qquad {}^{a} \]:

enter image description here

You must log in to answer this question.

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