7

The problem speaks for itself, here is the sample:

\documentclass[12pt]{article}

%% Language of the document
\usepackage{polyglossia}
\setmainlanguage{spanish}

\usepackage{unicode-math}

%% Text font of the document
\setmainfont{STIX2Text-Regular.otf}[
    BoldFont       = STIX2Text-Bold.otf , 
    ItalicFont     = STIX2Text-Italic.otf, 
    BoldItalicFont = STIX2Text-BoldItalic.otf
]

%% Math font of the document
\setmathfont{STIX2Math.otf}

\usepackage{mathtools}

\begin{document}    
    \[
    \underbrace{\text{A long equation}}_{\text{This is a long equation}}
    \]  
\end{document}

and when compiled, the underbrace it's just not there. Of course I'm missing something in the configuration.

enter image description here

Martín
  • 507

3 Answers3

10

One should load the mathtools package before the fontspec and/or unicode-math packages. Note: Since the polyglossia package loads fontspec automatically, you should also take care to load mathtools before polyglossia.

For sure, if you move the instruction \usepackage{mathtools} to before both \usepackage{polyglossia} and \usepackage{unicode-math}, the \underbrace stuff works fine, whether or not polyglossia is loaded.

Mico
  • 506,678
  • 1
    Nowadays there is no need to load amsmath before unicode-math; the present issue is due to mathtools, though. I think this has already appeared. – egreg Dec 22 '19 at 08:48
  • @egreg - Thanks. I've modified my answer to incorporate your comment. – Mico Dec 22 '19 at 12:41
7

The mathtools package contains a fix to \underbrace and \overbrace as defined in the LaTeX kernel.

If we compare the two definitions

%%% LaTeX kernel
\DeclareRobustCommand\underbrace[1]{\mathop{\vtop{\m@th\ialign{##\crcr
   $\hfil\displaystyle{#1}\hfil$\crcr
   \noalign{\kern3\p@\nointerlineskip}%
   \upbracefill\crcr\noalign{\kern3\p@}}}}\limits}

%%% mathtools.sty
\def\underbrace#1{\mathop{\vtop{\m@th\ialign{##\crcr
   $\hfil\displaystyle{#1}\hfil$\crcr
   \noalign{\kern.7\fontdimen5\textfont2\nointerlineskip}%
   \upbracefill\crcr\noalign{\kern.5\fontdimen5\textfont2}}}}\limits}

we see that they're almost identical, but mathtools improves the definition by not using a fixed length of 3pt and adjusting it with the current math font setup.

However, the definition of \underbrace in unicode-math is

\UnicodeMathSymbol{"023DF}{\underbrace}{\mathunder}{bottom curly bracket (mathematical use)}

that translates to more low level

\underbrace=\protected macro:
#1->\mathop {\Umathaccent bottom 7\symoperators "023DF\scan_stop: {{}#1}}\limits

What happens if you load mathtools after unicode-math is that the “Unicode” definition of \underbrace is overridden with the fix above done by mathtools. Note that you get no error: indeed \upbracefill uses math characters that in unicode-math don't correspond to the pieces of brace as in legacy LaTeX math fonts.

In conclusion: mathtools makes a good fix for legacy math fonts, but it shouldn't do it when unicode-math is loaded. Until mathtools is updated, the solution is to load it before unicode-math.

egreg
  • 1,121,712
0

Works after removing polyglossia--error usexelatex

enter image description here

\documentclass[12pt]{article}

\usepackage{mathtools}

\begin{document}    
    \[
    \underbrace{\text{A long equation}}_{\text{This is a long equation}}
    \]  
\end{document}
js bibra
  • 21,280