Different position of indices after parentheses of the same height

Let us look at the following code:

\documentclass{article}

\usepackage{amsmath}
\begin{document}

$\frac{\partial^2u}{\partial x^2} = \frac{\left(y-y_0\right)^2-(x-x_0)^2}{\left((x-x_0)^2+\left(y-y_0\right)^2\right)\displaystyle\mathstrut^2}.$

\end{document}


and its result:

The parentheses made by (...) and \left(...\right) are of the same height, but the position of 2 is different. Why? Moreover, \mathstrut should have the same height as parenthesis, but the position of 2 is yet another. Why?

• Have you tried using \Bigl ? Jan 2, 2022 at 7:54
• @Sebastiano I can obtain different sizes of parentheses. The problem is: why the same size gives 3 different heights of indices? Jan 2, 2022 at 7:57
• I think that the problem Is the fraction. My upvoted there Is ☺️ Jan 2, 2022 at 8:00
• @Sebastiano: But the problem occurs also in the numerator. Jan 2, 2022 at 8:43
• Use \left( and \right) throughout, to see the effect: $\frac{\partial^2u}{\partial x^2} = \frac{\left( y - y_0 \right)^2 - \left( x - x_0 \right)^2}{\left( \left(x - x_0 \right)^2 + \left( y - y_0 \right)^2 \right)^2}.$. And remove the strut and display command, for the moment. It's introducing height. Jan 2, 2022 at 10:30

\mathstrut has the same height as a normal size parenthesis and you're basically setting the last exponent to an empty subformula, because \vphantom{...} doesn't make a math atom.

You get the same output with

$\Bigg)\vphantom)^2$\par
$\Bigg)\vphantom{\Bigg)})^2$


namely

In order to set a superscript to a \right delimiter, you need to have nothing between the delimiter and the exponent.

This almost settles the denominator. What about the numerator? The construction \left<delimiter>...\right<delimiter> builds a subformula, so TeX takes into account the full height when deciding for the placement of the superscript.

More simply,

$\left(y_0\right)^2\ne (y_0)^2$
$\left(y_0\right)_2\ne (y_0)_2$


This also explains why the denominator has oversized parentheses.

So you have discovered a rather good example why \left and \right should be used with great care. Choose among the following two examples.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

$\frac{\partial^2u}{\partial x^2} = \frac{(y-y_0)^2-(x-x_0)^2} {\bigl((x-x_0)^2+(y-y_0)^2\bigr)^2}.$

$\frac{\partial^2u}{\partial x^2} = \frac{(y-y_0)^2-(x-x_0)^2} {((x-x_0)^2+(y-y_0)^2)^2}.$

\end{document}


I have little doubts about the second one being better and clearer.

\left\right has spacing effects even when it doesn't select a larger delimiter.

\documentclass{article}

\usepackage{amsmath}
\begin{document}

$\frac{\partial^2u}{\partial x^2} = \frac{(y-y_0)^2-(x-x_0)^2} {\bigl((x-x_0)^2+(y-y_0)^2\bigr)^2}.$

\end{document}


If you add \showoutput to your original and look at the ) in the numerator the first ) using \right is

.........\hbox(7.5+2.5)x3.8889
..........\OT1/cmr/m/n/10 )


The second one does not have the surrounding box

........\OT1/cmr/m/n/10 )