# Bug in xelatex + unicode-math + xits + \vphantom? [closed]

Compiling the file

\documentclass{article}
\usepackage{unicode-math}
\setmathfont[
Extension=.otf,
range={\smallblacktriangleright},
BoldFont = *bold
]{xits-math}
\begin{document}
$\vphantom{\smallblacktriangleright}^a\smallblacktriangleright^a$
\end{document}


produces the two copies of 'a' on the same height (which I expect) under lualatex, but lowers the first 'a' (which I consider wrong) under xelatex:

Any hints on how to place the first 'a' on the correct height when compiling with xelatex?

• See Why should the minimal class be avoided? for the reason I edited your example. – egreg Feb 26 '16 at 11:26
• You can try, with LuaLaTeX, \vphantom{\bigg|}^a and you'll see that the phantom has no influence on the placement of the superscript, because a box doesn't make a math atom. – egreg Feb 26 '16 at 16:14
• @egreg \mathord{\vphantom{..}} works with lualatex. But with xelatex the results are quite confusing. E.g. the order matter. In $\mathord{\vphantom{x}}^a x^a \mathord{\vphantom{x}}^a$ the first is wrong, the second ok. – Ulrike Fischer Feb 26 '16 at 18:58
• I'm voting to close this question as off-topic because the bug is fixed in TL2017. – Henri Menke Jun 11 '17 at 1:23

Looks as if xelatex is using cramped style in this case. You can avoid it by using an additional box:

\documentclass{article}
\usepackage{unicode-math}
\setmathfont[
Extension=.otf,
range={\smallblacktriangleright},
BoldFont = *bold
]{xits-math}

\begin{document}

$\mbox{\vphantom{\smallblacktriangleright}}^a \smallblacktriangleright^a$
\end{document}


• This defeats the purpose of \vphantom and the size would be the same independently of the current style. – egreg Feb 26 '16 at 14:30
• @egreg: Yes, it wouldn't work as a general solution. But perhaps it is enough. – Ulrike Fischer Feb 26 '16 at 15:09
• Works like a charm! – Frank Feuerstern Feb 26 '16 at 20:46
• @UlrikeFischer Try without the \mbox{$\vphantom{...}$} and you'll get the same. – egreg Feb 26 '16 at 20:54
• XITS is probably unrelated to the problem. See tex.stackexchange.com/questions/296177/… – Frank Feuerstern Feb 26 '16 at 20:59

I believe that there are several bugs involved.

First of all, doing \vphantom{something}^a in TeX should be exactly the same as saying {}^a, because \vphantom can never be the nucleus of a math atom. So when TeX scans ^, it adds an empty subformula as the nucleus of the math atom that should be superscripted.

I'll simplify the setting by using {>} instead of \smallblacktriangleright that's not relevant for the matter. Here's an example, first compiled with legacy pdflatex, then with LuaLaTeX and finally with XeLaTeX.

The \hrule is meant to show the top of the boxes, while the initial x marks the baseline. The fractions at the bottom will be explained later.

## Code for the example

\documentclass{article}
\usepackage{ifxetex,ifluatex}

\ifx\ifxetex\ifluatex
\else
\usepackage{unicode-math}
\setmathfont{latinmodern-math.otf}
\fi

\begin{document}

\hrule height 0.1pt
x$$\displaystyle{}^a{>}^a$$

\hrule height 0.1pt
x$$\displaystyle\vphantom{>}^a{>}^a$$

\hrule height 0.1pt
x$$\displaystyle{\vphantom{>}}^a{>}^a$$

\hrule height 0.1pt
x$$\displaystyle{}^a{\sum}^a$$

\hrule height 0.1pt
x$$\displaystyle\vphantom{{\sum}}^a{\sum}^a$$

\hrule height 0.1pt
x$$\displaystyle{\vphantom{{\sum}}}^a{\sum}^a$$

\hrule height 0.1pt
$$\displaystyle\frac{\scriptstyle a}{\scriptstyle b}\frac{a}{b}$$

\end{document}


## Output with pdflatex

As you can clearly see, there's no difference in the placement of the left superscript when {} or \vphantom{>} is used. Nor there is in the third line, where {\vphantom{>}} is the nucleus of the math atom that receives the superscript.

Similarly there's no difference in the first two lines when \sum is used instead of >, but the difference shows up in the third line.

## Output with LuaLaTeX

This is essentially the same as before.

## Output with XeLaTeX

A few differences show up. The top three lines are different from each other. For the first and third lines, this might have to do with how XeTeX processes the information from the OpenType font, in order to transform it into the appropriate \fontdimen parameters and should be fixed to match the legacy typesetting.

The second line is plainly wrong. It seems that when a \vphantom is concerned, which involves \mathchoice, the dimension used to set the superscript to the added empty nucleus is relative to the scriptscriptstyle font.

This might be connected with another known bug of XeTeX, that shows up with fractions. If you compare the fractions in the first two images, the fraction line is at the same level; in the XeLaTeX output, the fraction with scriptstyle numerator and denominator has a lower and thicker fraction line.

The connection seems quite likely, because fractions and \mathchoice (on which \vphantom is built) use a very similar mechanism.

## Solution?

None that can be deemed as general as one could hope. Use an appropriate

{\vphantom{?}}^a


where ? is some symbol whose height makes the height of the superscript to match the desired one.

• Would reporting the bug to XeLaTeX developers help? – Frank Feuerstern Feb 26 '16 at 22:27
• @FrankFeuerstern I'm not sure it's XeTeX or unicode-math. – egreg Feb 26 '16 at 22:29
• It looks like it’s not \mathchoice the culprit: see my last comment to tex.stackexchange.com/q/296177/69818 – GuM Feb 27 '16 at 0:17