unicode-math superscripts don't line up (using XeLaTeX)

I experimented with LuaTeX, no XeTeX, but the problems are similar.

There are many position parameters read from Unicode math font. They are listed at pages 104--108 of LuaTeX manual. Main rules of vertical position of the exponent are controlled by two parameters:

  • \Umathsupshiftup minimal shifting up. (10pt typesetting, Latin Modern math, displaystyle, value: 3.63pt)

  • \Umathsupshiftdrop bottom of the exponent is shifted up to the height of the nucleus minus this value (10pt typesetting, Latin Modern math, displaystyle, value: 2.5pt)

Suppose, that we have "cos" in the nucleus and "2" in the exponent. First, the "2" is shifted up to the height of "cos" and then shifted down by \Umathsupshiftdrop. If the distance from baseline to bottom of such "2" is less than \Umathsupshiftup then forget previous calculation and shift up the "2" from baseline to \Umathsupshiftup. This second case is true when "cos" in in nucleus. But if "sin" is in the nucleus, then first case is true because "i" is higher than "cos". We can set

\Umathsupshiftdrop\displaystyle=3pt

then the second case will be true for both: "sin" and "cos" and the exponent will be in the same height.

The parameters mentioned here are read from Unicode math font table (MathConstants), so the different positions of the exponent in "sin" and "cos" can be considered as bug (or feature?) of Latin Modern fonts.

I don't know, why XeTeX gives much more difference in this positioning than LuaTeX. The \Umathsupshiftdrop is represented as \fontdimen24 in XeTeX. You can do experiments with this.


As wipet pointed out the placement depends on the height of the operator. You can see a similar effect (but much less pronounced) also with classical tex if you use large enough letters:

\documentclass{article}

\usepackage{amsmath}
\usepackage{tikz}

\def\sin{\qopname\relax o{SIN}}
\begin{document}
    \[\tikz[overlay]\draw[red](0,4.4pt)--++(5,0); \sin^{2}x+\cos^{2}x=1 \]
\end{document}

enter image description here

This basically means that the amsopn definitions of these operators assume that the height differences don't matter -- an assumption which is no longer true in the context of unicode-math.

You can correct the height for example like this. As can be seen such corrections would be needed for other operators too:

\documentclass{article}

\usepackage{unicode-math}
\usepackage{amsmath}
\usepackage{tikz}
\makeatletter
\def\sin{\qopname\relax o{\vphantom{\operator@font cos}\smash{\operator@font sin}}}
\begin{document}
    \[\tikz[overlay]\draw[red](0,4.4pt)--++(5,0); \cot^2 \tanh^2 \sin^{2}x+\cos^{2}x=1 \]
\end{document}

enter image description here