# Differences in vertical positioning of superscripts and subscripts depending on grouping ({ }): Why? Caveats? Workarounds?

This question about {(x+y)}^2 vs (x+y)^2 drew my attention to the slightly different vertical positioning of super- and subscripts for such expressions. Compare (x+y)^8_8 (left) and {(x+y)}^8_8 (right) [all expressions in math mode]:

\documentclass{article}
\begin{document} $$(x+y)^8_8$$, $${(x+y)}^8_8$$ \end{document}

(This minimal example code is barely worth posting.)

This raises some questions for me:

• Why is the vertical positioning different in the two expressions?
• Is there anything the LaTeX user should pay attention to to get such vertical positioning "right" (this is assuming that there is deeper rationale behind the difference)?
• Is there an easy way of getting such expressions to always have identical positioning of super- and subscripts?

The answers to the linked question above advise against the version with { }, so I assume that any rationale for the difference in vertical positioning will require a different example term.

• You can find some explanation in this answer of mine. Commented Apr 23, 2013 at 10:31
• Great info for a partial answer ;-) Commented Apr 23, 2013 at 10:42

### Why is the vertical positioning different in the two expressions?

Because in the first case you're adding subscripts and superscripts to the parenthesis, while in the second case the whole subformula is the nucleus of the math atom to which the superscript and subscript fields are added.

### Is there anything the LaTeX user should pay attention to to get such vertical positioning "right" (this is assuming that there is deeper rationale behind the difference)?

It is better to not brace a subexpression in parentheses; to brace it would usually be wrong. Adding the exponent to the parenthesis is the traditional way to denote exponentiation of the parenthesized expression.

### Is there an easy way of getting such expressions to always have identical positioning of super- and subscripts?

No. They are inherently different, because the latter uses all of the braced subformula to determine the superscript's baseline.

Just $)^2$ and ${)}^2$ show the difference. In the former case the atom has nucleus ), in the latter the nucleus is {)} and rules of Appendix G applies differently: in the second case the math list is converted to a box, which hasn't the same information as a single symbol. This is a visual demonstration:

$bb^2 {bb}^2 bb_2^2 {bb}_2^2$

produces

It has also to be mentioned another issue: when you write ${(a+b)}$ (with sub/superscripts or not) the space around the + is frozen at its natural width, so it won't participate in the space stretching or shrinking when the line is justified. This could create bad appearance in cases such as ${(a+b)}+c$ where the spaces around the + signs might end up to be different.

• While what you say is true, I suspect the result is moderately surprising in this case as the parenthesis is visually the deepest and highest item in the braced subterm. It's easier to see why there is an effect if the subterm has items that are bigger than the ). Commented Apr 23, 2013 at 11:08
• In the first part of the answer, it may be worth mentioning explicitly that the reason the subscripts/superscripts are set differently, even though the immediately preceding material has exactly the same height and depth in both expressions, is that ) is an atom of type "math-close" whereas {(x+y)} is of type "math-ord". It is this difference that triggers the difference in subscript and superscript positioning.
– Mico
Commented Apr 23, 2013 at 19:57
• @Mico With $\mathord)^2 )^2$ you get the same position. Commented Apr 23, 2013 at 20:05
• @egreg - Thanks for pointing this out. I guess this means that the argument in my answer will need to be revised too.
– Mico
Commented Apr 23, 2013 at 20:37

I interpret your questions being mainly about the purpose (or purposes) of having different rules for the typesetting of superscripts and subscripts depending on whether the immediately preceding material is (a) a right-parenthesis -- which happens to be, in TeX jargon, an "atom" of type "math-close" -- or (b) a right-hand curly brace that ends a math "group". (As @egreg has notes in his answer, the direct answer to the why is given in Appendix G of the TeXbook: TeX uses different rules depending on whether or not it can "inspect" the material that immediately precedes the sub/superscript material. Math material in curly braces creates a new "nucleus" or box; once the material is placed in the box, TeX knows the width, height, and depth of the box, but nothing further.)

To understand the purpose of having these differing rules, it's important to recall that TeX was designed in large part to typeset mathematical expressions beautifully, in both display style (i.e., offset equations) and text style, i.e., running text. For running text, a commonly used criterion for typographical beauty is uniform color (grayness, if you prefer) of the text block. To achieve this objective, it really helps if

• different paragraphs within a page and across pages have approximately the same amount of color regardless of what's in the paragraphs, as well as if
• individual lines of text within one and the same paragraph are evenly spaced.

For many Roman fonts (in German, I believe they're called "Antiqua" fonts) that are suitable for running text, the distance between consecutive "single-spaced" lines is generally set to be 20 percent larger than the nominal font size. E.g., a 10pt font is given an interline spacing of 12pt -- 10/12 for short -- in single-spaced text. (Blackletter fonts, in contrast, can generally be set "solid", e.g., 10/10.) For this setting of interline spacing to have a chance to produce the desired outcome in terms of color, it's important that nothing be allowed to protrude too much into the interline whitespace.

What, you may ask, does all this have to do with your question, i.e., with reasons for having different algorithms for positioning sub- and superscripts?

Consider the following two paragraphs, which are both set 10/12. The first paragraph features a combination of lipsum filler text and expressions of the form $(x+y)^8_8$; the second paragraph has the same filler sentences plus expressions of the form ${(x+y)}^8_8$:

All lines in the first paragraph are evenly spaced, whereas this isn't the case in the second paragraph. The difference between the paragraphs, by construction, is the positioning of the superscripts and subscripts of the math expressions. Without the curly braces around the (x+y) terms, TeX notices that the term that precedes the subscript and superscript is ); in such a case, TeX uses a specialized algorithm to position the subscript and superscript quite tightly: notice that the subscripts do not fall below the ) symbol and that the superscripts barely rise above the parentheses. The consequence of the tight positioning of the sub- and superscripts for the appearance of the paragraph as a whole is that no adjustments are necessary to the default interline spacing, resulting in a nice even color.

In contrast, if curly braces are used, TeX doesn't "know" that the expression encased by braces ends with a parenthesis and therefore chooses a different, more generic algorithm for placing the subscript and superscript terms. This, it turns out, leads to a more pronounced protrusion of the terms into the interline whitespace, forcing TeX to enlarge the interline whitespace slightly. The result is non-uniform line spacing within one and the same paragraph -- ugly!!

In sum, there is indeed a very good reason for not using { and } unnecessarily: doing so might interfere with TeX's ability to typeset paragraphs beautifully. :-)

\documentclass{article}
\newcommand\lipsi{Lorem ipsum dolor sit amet, consectetuer adipiscing elit. }
\newcommand\lipsii{Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. }
\newcommand\lipsiii{Curabitur~dictum gravida mauris. }
\newcommand\lipsiv{Nam libero, nonummy eget, consectetuer id, vulputate a, magna. }
\newcommand\withoutbraces{$(x+y)^8_8$ }
\newcommand\withbraces{${(x+y)}^8_8$ }
\hyphenation{purus dictum vulputate}
\begin{document}
\lipsi \withoutbraces \lipsii \withoutbraces \lipsiii \withoutbraces \lipsiv \lipsi \lipsii \lipsiii \lipsiii

\medskip
\lipsi \withbraces \lipsii \withbraces \lipsiii \withbraces \lipsiv \lipsi \lipsii \lipsiii \lipsiii
\end{document}

Addendum: It's possible to restore uniform line-spacing for the second paragraph by setting it at 10/13, i.e., with one more point of "lead". That still doesn't lead to an entirely satisfactory outcome, though, as now lines that contain no material with subscripts and/or superscripts start to look isolated from their adjacent lines. In short, if 10/12 is deemed to be OK for typesetting running text, the typesetting engine should be enabled to typeset any math objects -- assuming, of course, that they're not so large as to deserve being typeset offset on a line by themselves! -- in such a way as not to interfere of keeping the text at 10/12.