# Vanishing math font styles in unicode-math due to a mess of mathtools, mathtt and using math fonts with ranges

I’m using TeXLive 2015.

Okay, so I have some sort of poltergeist in the following code. I compile it with either XeLaTeX or LuaLaTeX.

\documentclass{article}
\usepackage{
fontspec,
%   mathtools,
unicode-math,
}

\setmathfont[
%   range = \mathcal,
]{xits-math.otf}

\begin{document}

%   $\mathtt L$
$\mathcal L$

\end{document}


The desired output – when uncommenting all lines – should be:

However, when uncommenting all lines and compiling with xelatex the script ‘L’ is missing. I found out that (re-)commenting out any of the three lines mathtools, range = \mathcal and $\mathtt L$ will restore the script ‘L’. Unfortunately, I have a scenario in which I need all three lines.

Also, compiling with lualatex doesn’t seem to yield any problems.

A similar question is this one, where this bug report for the unicode-math package has come up. Is that stemming from the same issue or is there something else going on here?

• Curiously enough, if you add \setmathfont[range=\mathscr]{xits-math.otf}, the script glyph reappears. – egreg Jun 16 '16 at 8:01

It's a misfeature, but a workaround is to load again the main math font for the \mathscr range; you also have to declare anew the main math font.

\documentclass{article}
\usepackage{mathtools}
\usepackage{
fontspec,
unicode-math,
}

\setmathfont{Latin Modern Math}
\setmathfont{XITS Math}[
range = \mathcal,
]
\setmathfont{Latin Modern Math}[
range = \mathscr
]

\begin{document}

$A$
$\symtt{L}$
$\mathcal{L}$

\end{document}


Note that the correct call for a typewriter type variable is \symtt, or \mathtt would load the text monospaced font.

This is the pdffonts report:

BRCTEL+LatinModernMath-Regular-Identity-H CID Type 0C       yes yes yes      5  0
HSKWQU+XITSMath-Identity-H           CID Type 0C       yes yes yes      7  0

• Thanks for the workaround! Actually, I want the text monospaced font to load (that is to match the text monospace font). Is there any reason why one wants to use \symtt instead? If the letters were used for mathematics only or something? (What font will be loaded with \symtt?) – k.stm Jun 16 '16 at 22:35
• @k.stm I suspected your preference for the monospaced document font. With \symtt you choose the “monospaced math letters” in the designated Unicode math font. – egreg Jun 16 '16 at 22:44

This is the same issue which was mentioned in XeLaTeX: mathtools, unicode-math and \text spoil \mathtt and again more recently in Incompatibility with mathtools and unicode-math in xelatex?.

There is a patch proposed in my answer to the more recent question.

And yes, the bug report you cite is about this issue. A pull request has been made to incorporate the fix into unicode-math.