[Tex/LaTex] \sqrt[x]{y} Breaks With unicode-math

unicode-mathxetex

I’m having trouble with XeLaTeX (0.9998) and unicode-math (0.7a). If I use \setmathfont more than twice, the \sqrt command breaks when a superscript is specified.

\documentclass{minmal}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}
\setmathfont[range=\mathup/{num,latin,Latin}]{Linux Libertine O}
\setmathfont[range=\mathup/{greek,Greek}]{Symbola}
\begin{document}
\[ \sqrt[5]{2} \]
\end{document}

If I typeset this code, XeLaTeX will produce the following error

Font \l_tmpb_font has only 8 fontdimen parameters.

If I remove the superscript from \sqrt or remove the last \setmathfont command, the document compiles correctly. I’ve tested this code with several OTF files, and they all produced the same result. (I know the resulting superscript is improperly positioned, but I can work on this once I know the document can be typeset.)

I filed a bug for this issue on GitHub because I believe it’s a problem with the package, but I should have checked here before doing so, and I will gladly close the bug if I find I was doing something stupid.

Best Answer

Tracing through the code, the issue is that unicode-math redefines \r@@t, which is used by LaTeX when it typesets a root with an index. The redefinition is different for LuaTeX and XeTeX, so you only see the issue with XeTeX. In that case, it is

\cs_set_nopar:Npn \r@@t #1 #2 {
  \hbox_set:Nn \l_tmpa_box {
    \c_math_toggle_token
    \m@th
    #1
    \sqrtsign { #2 }
    \c_math_toggle_token
  }
  \um_mathstyle_scale:Nnn #1 { \kern } {
    \fontdimen 63 \l_um_font
  }
  \box_move_up:nn {
    (\box_ht:N \l_tmpa_box - \box_dp:N \l_tmpa_box)
    * \number \fontdimen 65 \l_um_font / 100
  } {
    \box_use:N \rootbox
  }
  \um_mathstyle_scale:Nnn #1 { \kern } {
    \fontdimen 64 \l_um_font
  }
  \box_use_drop:N \l_tmpa_box
}

The key here is the \fontdimen business: these are 'high number' font dimensions which are not available in traditional TeX. As such, these are not defined for text fonts: they are only available for 'proper' Unicode math fonts. You therefore see the error only if you set up some symbols to be taken from a text font.