# XeLaTeX: mathtools, unicode-math and \text spoil \mathtt

I work on a big XeLaTeX document and encountered a rendering bug(?) with my MiKTeX installation (all packages are updated as per April 10, 2016). Here is a minimal example:

\documentclass{article}
\usepackage{mathtools}
\usepackage{unicode-math}
\DeclareSymbolFont{somemeaninglessname}{\encodingdefault}{\familydefault}{m}{it}

\begin{document}
$\mathtt{z}$
$\text{z}$
$\mathtt{z}$
\end{document}


I'd expect first and third line to be the same. However, it's not the case:

I asked my friend to render same file on Linux with TeXLive-2014, and here is what he got:

However, if I move \usepackage{mathtools} right after \DeclareSymbolFont's line, everything works on my system as expected:

Moving it in between \usepackage{unicode-math} and \DeclareSymbolFont does nothing.

I'm not sure whether it's a bug or incorrect usage of either package. Unfortunately, I do not really understand what \DeclareSymbolFont does - it was written by another person. What is going on here?

UPD: looks like it's not MiKTeX-specific problem and happens on TeXLie 15 as well.

• \usepackage{unicode-math} should go after all other math packages, as recommended in it's documentation. – Lapshin Dmitry Apr 10 '16 at 16:26
• It is not a problem specific to miktex. I see it with texlive 15 too. The problem is that when mathtools is detected unicode-math issues a \newfam \g__um_empty_fam and disturbs the family detection, but I can't look deeper now. – Ulrike Fischer Apr 10 '16 at 16:49
• imho it is a bug github.com/wspr/unicode-math/issues/345 – Ulrike Fischer Apr 10 '16 at 21:34

\documentclass{article}