9

It seems that the basic syntax

(x_{i})_{i\in I}

leads to a different index position than

\left(x_{i}\right)_{i\in I}

Specificically, the lower index in the last example has a bigger vertical offset. This seems independent of the content between the brackets, as the same effect shows up with the even simpler example

(x)_{i\in I}
\left(x\right)_{i\in I}

What is the cause or rationale of this behavior? Since I might accidentally mix both syntaxes in my document, what is the best practice to ensure a uniform alignment of indices?

shuhalo
  • 2,545
  • Please extend your code to a minimal working example (MWE) and add an image of the result. – dexteritas Aug 31 '23 at 13:21
  • 1
    Use \left(, \right) only if it makes a difference to (...), e.g. if you use \frac inside. – dexteritas Aug 31 '23 at 13:24
  • This is nice question. Please make MWE and an image, so to attract some answer. I do not know the rationale why the result is different, I just understand the mechanism. _ looks for the previous item, positions the index accordingly. In the second case, there is \right ) which measured the size of the parenthesised things and changed its own size to fit. This influences the position of index. In the first case, there is just char ) to set the position of index. Why the result is different in such a simple case, I do not know. – minorChaos Aug 31 '23 at 14:41
  • @minorChaos - Please see the answer I posted. – Mico Aug 31 '23 at 15:04
  • 1
    Well, after reading Mico's explaination, )_ seems to behave very reasonably and in fact, nice. This (probably) intentional behaviour is lost when \left..\right is used, because the material is sort of boxed and the dimensions of protruding ) will cause to change the positions of indexes. – minorChaos Aug 31 '23 at 21:32

4 Answers4

8

It's not actually due to \left and \right.

Look at the following plain TeX code:

$(x_{i})_{i\in I}$ $\left(x_{i}\right)_{i\in I}$ ${(x_{i})}_{i\in I}$

\bye

enter image description here

As you see, the last two samples typeset the same: the subscript is to the whole subformula, not just to the right parenthesis.

To the contrary with

$x_{x}$ $\left.x\right._{x}$

\bye

we get the same height (only spaces differ, but it's expected):

enter image description here

so you see that the problem is not with \left and \right.

What's the best practice? Not using \left and \right unless really necessary.

egreg
  • 1,121,712
  • Quick question: Is the TeXnical reason for why $x_{x}$ and $\left.x\right._{x}$ produce the same vertical offset the fact that the math atom to the left of the _ token has status mathord in both cases? – Mico Aug 31 '23 at 17:06
  • @Mico I don't think so; the subscript is to the whole subformula. – egreg Aug 31 '23 at 17:17
  • Thanks. Then why does $)_x$ produce a smaller vertical offset than do either ${)}_x$ or $\left.\right)_x$? To me, the only meaningful difference is that the first subformula has status math-close, whereas the other two subformulas have status math-ord. Is there maybe another difference -- which I appear to be missing? – Mico Aug 31 '23 at 17:29
  • @Mico There's no “mathclose” atom when \left and \right are involved. – egreg Aug 31 '23 at 17:37
  • But that's what I think I'm saying: the entire subformula $\left.\right)$ has status math-ord, no? Let's consider a hopefully more interesting case: $(u+v)^2$ vs. $\left(u+v\right)^2$. Here, the vertical offsets of the exponents differ noticeably even though the relevant subformulas -- ) and the entire left-right construct, resp. -- have the exact same height and depth. My question, then, is: why is the exponent lower in the first case, if it's not because of the difference in math-status? – Mico Aug 31 '23 at 17:50
  • @Mico and egreg: Indeed, what makes ) to behave different? --- It is not math-close because \mathclose{)}_I behaves just like {)}_I. – minorChaos Aug 31 '23 at 21:25
  • @Mico and egreg: I found something and posted below – minorChaos Aug 31 '23 at 22:28
6

You actually ask two separate questions.

What is the cause ... of this behavior?

Consider the following, slightly more elaborate examples that involve mathematical delimiters, such as ) and ], and adjacent subscript and superscript terms.

enter image description here

\documentclass{article}      
\begin{document} 
$()_I$   ${()}_I$ $\left(\right)_I$ ${\left(\right)}_I$

$()^2$ ${()}^2$ $\left(\right)^2$ ${\left(\right)}^2$

$[]_u^v$ ${[]}_u^v$ \end{document}

The two main things to note in this screenshot are:

  • In a given row, the round parentheses and square brackets all have the same heights and depths. Same for the subscript and superscript terms in a given row.

  • In a given row, the subscript and superscript terms are placed more compactly, i.e., with smaller vertical offsets, in the first case than in the subsequent case[s].

So, in a given row, what distinguishes the first case from the subsequent cases? Take, say, the second row.

  • In the first case, the "math atom" that immediately precedes the ^ token (TeX's superscript material initiator) is ), which has TeX status "math-close".

  • In the second through fourth cases, the "math atoms" -- or should that be "math molecules"? -- that precede the ^ tokens are {()}^2, \left(\right)^2, and {\left(\right)}^2, respectively. What do these math atoms have in common? It's that their TeX status is "math-ordinary". Aside: encasing any math atom in curly braces changes its status to math-ordinary. And, the entire \left(\right) math atom also has status math-ordinary.

Now, TeX's superscript and subscript placement rules differ importantly in terms of the vertical offsets that get applied, depending on whether the material that immediately precedes the ^ and _ tokens has status math-open/math-close or not. In particular, what you've (re)discovered is that the placement is tighter if the preceding math atom has status math-close than if its status is math-ordinary.

What is the ... rationale [for] this behavior?

My impression is that there are two separate reasons for TeX applying smaller offsets if the math atom that immediately precedes the _ and ^ tokens has status math-open/close.

  • Compare the outputs of $(a+b)^2 = a^2+2ab+b^2$ and $\left(a+b\right)^2 = a^2+2ab+b^2$.

    enter image description here

    In the former case, all three instances of 2 are placed at the same height, which I would argue looks natural and harmonious. In the latter case, the first instance of 2 is placed noticeably higher than the other two; to me, that seems artificial, unnecessary, and visually distracting. (Aside: Having worked with TeX and LaTeX for more than 30 years, my opinion in this matter may well be a tad biased...)

  • In an inline-math context, applying smaller vertical offsets to any subscript and superscript terms that may be present significantly raises the odds that that the entire paragraph can be typeset with even spacing between lines. In fine typesetting, having even line spacing in a paragraph is considered to be very desirable.

Finally, you asked,

Since I might accidentally mix both syntaxes in my document, what is the best practice to ensure a uniform alignment of indices?

It's quite simple, really: Don't use the \left and \right auto-sizing directives unless doing so serves a discernible valid purpose. Applying this stricture to some of the preceding material suggests that there is no valid reason for using \left and \right in $\left(a+b\right)^2=a^2+2ab+b^2$...

Mico
  • 506,678
  • 1
    I frequently use macro \newcommand\norm[1]{\left \|#1\right \|} . I hoped it takes care of horizontal spacing. If you say I should avoid \left..\right, should I use some sort of \mathopen\|....\mathclose\| (if anything like that exists?) – minorChaos Aug 31 '23 at 20:38
  • @minorChaos - I suggest you load the mathtools package (a superset of the amsmath package) and write \DeclarePairedDeliminiter{\norm}{\lVert}{\rVert} in the preamble. Then, write \norm*{x} in the body of the document to autosize the delimiters. In contrast, if you want a fixed-size delimiter, write \norm{x}, \norm[\big]{x}, \norm[\Big]{x}, etc. The main rule is: don't autosize the delimiters unless you know for sure you need this feature. – Mico Aug 31 '23 at 20:48
  • Mico, thanks that's exactly what I longed for. May I ask, is it compatible with past (15 year old installation, co-authors) and with other packages (journals)? – minorChaos Aug 31 '23 at 21:17
  • @minorChaos - The mathtools package has been around for well more than a decade, is very stable and well-debugged, and is in very widespread use. The only incompatibility I'm aware of that involves the mathtools package arises if one wishes to load both the cleveref cross-referencing package and the mathtools package with the option showonlyrefs. (I wouldn't recommend you try this combination.) – Mico Aug 31 '23 at 21:42
  • @minorChaos - Is your TeX distribution really 15 years old? If so, is there any chance you could update it to a more recent distribution, say, TeXLive or MikTeX? – Mico Aug 31 '23 at 21:43
  • Not everybody can update, and I do not think it is a good idea to update software every five years. (Of less importance is the fact that I have a fresh version today.) (Another fact of less importance is that I do not want to learn anything which will change next 10 years.) – minorChaos Aug 31 '23 at 22:26
  • 1
    Mico: typo correction: \DeclarePairedDelimiter, not \DeclarePairedDeliminiter :-) – minorChaos Aug 31 '23 at 22:43
  • @minorChaos - Good catch on the typo. (Sorry 'bout that...) Congratulations and felicitations on updating your TeX distribution today. – Mico Aug 31 '23 at 23:54
  • 1
    @Mico I added an answer to expand on this a bit, but basically math-ord does not directly trigger the deeper placement but placing everything in braces does: In braces it's no longer a single character, and single characters are treated in a special way. The rest of the answer still applies though. – Marcel Krüger Sep 01 '23 at 19:35
  • @MarcelKrüger - Thanks! Real quick: Does your answer shed light on why the exponent term is positioned at different heights for, say, $(u+v)^2$ and ${(}u+v{)}^2$? In the former case, ) has status math-close, whereas it has status math-ord in the latter. Is this distinction possibly entirely irrelevant, and some other factor (which I've failed to spot so far...) is responsible for the difference in where the exponents are placed? – Mico Sep 01 '23 at 20:12
  • 1
    @Mico Yes, the exponent is handled similar to the subscript: ) is a single character, so the height of the ) is ignored. But in {)} the braces build a math list containing a single character, but since it's a list it's not a single character and therefore the height is respected. Since ) is rather high the height of the list is similarly high and the exponent is placed higher. – Marcel Krüger Sep 01 '23 at 20:58
  • 1
    You can also see this by looking at \mathclose{)}^2. The exponent is higher since it applies to a list, even though it is a math close atom. – Marcel Krüger Sep 01 '23 at 21:01
1

Mico and egreg convinced me that it is best to avoid \left...\right unless there are reasons to use that.

Mico says "... applying smaller vertical offsets to any subscript and superscript terms that may be present significantly raises the odds that that the entire paragraph can be typeset with even spacing between lines. In fine typesetting, having even line spacing in a paragraph is considered to be very desirable."

So the behaviour of )_ is by design.

How is that done and why it happens that the behaviour changes in cases like \left(...\right)_I and {)}_I ? I think here is the answer:

UPDATE: There is a later answer below better explaining what happens.

Special behaviour is built into the font parameters of character ). In a math font each character has about 22 parameters some of which have something to do with indexes:

s13 sup1 (alternative superscript position)
s14 sup2 (alternative superscript position)
s15 sup3 (alternative superscript position)
s16 sub1 (alternative subscript position)
s17 sub2 (alternative subscript position)
s18 sup-drop (further control of superscript positioning)
s19 sub-drop (further control of subscript positioning)

With {(} or \left...\right this parameters are out of question because in front of _, no more a character of a font is sitting. UPDATE: Or quite the opposite as says the answer that I already mentioned.

minorChaos
  • 260
  • 6
  • 1
    Not quite, the font parameters are always used to place script, even for more complicated lists. Actually they are used more for more complicated lists. This is possible since the used parameters are not decided by the font of the previous paramter but always (for the script paramters) by mathfamily 2 ( aka. mathsy) – Marcel Krüger Sep 01 '23 at 19:39
1

While not quite answering the question a note about how the technical implementation for this is done which didn't fit into a comment:

The deciding factor is not so much the mathclass (except mathop which is special) but the question is the object which is accented.

Whenever a single character from a math font is accented, then it's height and depth are completely ignored and instead the scripts are set as if they attach to an empty list.

Take for example the following plain TeX document which attaches scripts to huge parens in different math classes:

$$
)_a
\mathchar"0321_a % This is a math ordinary
\mathchar"5321_a % This is a math close
{}_a % an empty list to compare
$$
\bye

You can see that they all attach the subscript at exactly the same height:

enter image description here

If the script attaches to anything else than a single character then this special case does not trigger and the height and depth of the character are taken into account. Generally this already happens when just surrounding some math atom with {}. But as a further exception adding {} around a single character which already is a math ordinary character is redundant and therefore optimized away in many situations, so the single character rules apply again:

$$
{)}_a % A math close character in braces
{x\mathchar"0321}_a % This are multiple math ordinary in braces
{\mathchar"0321}_a % This is one math ordinary character in braces so the braces are ignored
{\mathchar"5321}_a % This is a math close character in braces
{}_a % an empty list for comparision
$$
\bye

Here the subscripts move down to adjust for the depth of the characters except in the case where the braces are redundant and therefore removed: enter image description here

The reason why it is done like this is that single character usually all have roughly the same size (unless you intentionally use weird characters like the \mathchar I used for testing). So one height looks reasonable next to all characters and looks much more consistent than to have different script heights for every characters. Everything more complicated than a single character can not be relied upon to have usual sizes, so the more general placement has to be used.