TeX - LaTeX Asked by apriori on July 18, 2021
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.
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.
Correct answer by wipet on July 18, 2021
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} ]
:
In the second version, the exponent is attributed to sum
and is interpreted as upper limit. The result of [ sum^{a}qquad {}^{a} ]
:
Answered by gernot on July 18, 2021
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:
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.
Answered by egreg on July 18, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP