I find unexpected behaviour in using mathtools in conjunction with unicode-math, which shows up if the 'range' command is used. Some incompatibilities have been noted before, so perhaps this is related. However, it only showed up for me in Texlive2016; previous versions worked as expected. In the following example I wish to draw calligraphic fonts from a different set than the main maths fonts, and some calligraphic symbols, and a regular italic bold face math, are missing.
\documentclass{article}
\usepackage{mathtools}
\usepackage{fontspec}
\usepackage{unicode-math}
\unimathsetup{math-style=ISO,bold-style=ISO,sans-style=italic}
\setmainfont{xits-regular.otf}
\setmathfont{xits-math.otf}
\setmathfont[range={\mathcal,\mathbfcal}]{latinmodern-math.otf}
%\setmathfont[range={}]{xits-math.otf} % Try with and without this line
%
\begin{document}
Test
$a+b = \mathcal{C H G}C \mathscr{D}$
$$-\frac{a}{b} \mathcal{O} . $$
\begin{equation}
\mathrm{d} = \mathcal G(\varphi,x,y,z,t) ,
\end{equation}
The symbol $\mathcal{G}$ is missing.
The following equation is wrong if I include the line ``setmathfont[range=\{\}] \{xits-math.otf\}''
\begin{equation}
\mathup{d} = \symbf{u}(\varphi,x,y,z,t) ,
\end{equation}
The glyph $\symbf{u}$ is missing.
\end{document}
If mmathtools is called after unicode-math the problem does not arise, but this ordering is not recommend by the unicode-math developers.
My specific question is, is this a bug or is it something I am doing wrong?
Best Answer
update:
The github issue related to this and opened by @UlrikeFischer was closed some time ago already at unicode-math
v0.8e
, and currently unicode-math is atv0.8m
. So don't use the hack below.Update. Here is an attempt at addressing the
\newfam
issue. We temporarily make innocent\newfam
duringunicode-math
loading (I checked it was used only once; as it is used during patching ofmathtools
,mathtools
must be loaded beforeunicode-math
). Then we patch ourselves the mathtools macro. For this, I use the math family number 255 rather than creating a new one. It is not very probable the document uses 256 math families. One could make this more intrinsic by using\e@mathgroup@top - 1
but I don't know how to subtract 1 in expl3 lingua. Caveat: barely tested.This addresses only one the two issues. The one of effect of empty range is not handled here.
code updated 2018/12/28 as per @egreg comment "
\box_use_clear:N
is deprecated as of 2018-12-31; the right function to use is\box_use_drop:N
"Part I
I have identified the source of the problem in file
unicode-math-xetex.sty
.Steps to reproduce:
Then your document compiles fine with the expected glyphs with both mathtools and your
\setmathfont[range={}]{xits-math.otf}
Note: the code of unicode-math looks strange with the
\AtEndOfPackageFile * { mathtools }
nested into another one... but I checked balancing of braces. Thus, lines 2038 and 2039 must remain non-commented.It could be that the important thing in the commented out code is that it does
\newfam \g__um_empty_fam
creating a new\mathgroup
. This may cause a problem of numbering ?Not being familiar with unicode-math I can't comment more. But it does look more like a problem in
unicode-math
than one inmathtools
(as far as I can tell.)extra info: I have checked that
\mv@normal
has exact same meaning in the two situations, confirming that there may be an offset in numbering of math families on theunicode-math
side.image showing it does work: (the math calligraphic are from XITS not Latin Modern, due to effect of
range={}
)Part II
Here is a minimal example to demonstrate the bug lies in
unicode-math
(see the various comments below this answer for more context).The use of
\newfam
before\setmainfont/\setmathfont
(the latter using thecal
not the deprecatedrange={\mathcal}
) is enough to create the problem: . Without the\newfam
we get .In case some doubt arises because Latin Modern is default use
I have opened a ticket at https://github.com/wspr/unicode-math/issues/368.
And the point is that the single (direct) use of
\newfam
in unicode-math code is in the linewhich is encountered at the start of its patch of
mathtools
which in Part I I advised to comment out. If this patch is executed too soon in the preamble a problem arises in using\math..
alphabet macros: the wrong font is used.This may have to do withI have not pursued further because the LaTeX code for math fonts is very complex and whenever I stay a few months without looking at it I forget it entirely and irrevocably, and it would take me quite some effort to re-immerse me into it, not to mention that I would need to readunicode-math
way of patching\use@mathgroup
butunicode-math
code as well.