# clash between mathtools and unicode-math

Lately I started looking into LuaTeX and I must say I’m growing fond of it with every feature I discover. So I decided to transfer my pdfTeX preamble to LuaTex checking which packages still work and which ones need to be replaced.

I use the mathtools package with pdfTeX for its centercolon and \smashoperator features. Unfortunately it seems to clash with the unicode-math package under LuaTeX. It boils down to:

\documentclass{minimal}
\usepackage{mathtools}
\usepackage{unicode-math}
\setmathfont{Latin Modern Math}
\mathtoolsset{centercolon}
\begin{document}
$:=\coloneq\coloneqq\eqcolon\eqqcolon:=$
\end{document}


results in

! Invalid math code.
\let
l.5 \mathtoolsset{centercolon}


with LuaTex beta-0.70.1 under MiKTeX 2.9. It seems that unicode-math is aware of the mathtools package as it warns in the log file that some commands were redefined.

EDIT: As mentioned above as I’m not working on a true document just doing preamble conversion work. Thus the random choice of Latin Modern Math was a poor one as pointed out by egreg. The partial answer is that the new OpenMath OpenType Fonts make the centercolon feature of the mathtools package obsolete. I wasn’t aware of that. Of the handfull available OpenMath compliant fonts Neo Euler seems to be the only one where := is not symmetric. I can’t check Minion Math yet. Taking egregs answer into account and avoiding coloneq while trying to use mathtools to adjust Neo Euler’s := gives however the same error as above:

\documentclass{minimal}
\usepackage{mathtools}
\usepackage{unicode-math}
\setmathfont[version=Asana]{Asana-Math.otf}% Asana Math
\setmathfont[version=Cambria]{Cambria Math}
\setmathfont[version=LatinModern]{Latin Modern Math}
%\setmathfont[version=Minion]{Minion Math}
\setmathfont[version=XITS]{xits-math.otf}% XITS Math
\setmathfont[version=NeoEuler]{Neo Euler}
\begin{document}
\mathversion{Asana} Asana $$:=:=$$
\mathversion{Cambria} Cambria $$:=:=$$
\mathversion{LatinModern} LatinModern $$:=:=$$
\mathversion{XITS} XITS $$:=:=$$
\mathtoolsset{centercolon}
\mathversion{NeoEuler} Neo Euler $$:=:=$$
\end{document}

-

The main problem is that the \coloneq character is missing in Latin Modern Math:

Missing character: There is no ≔ (U+2254) in font name:LatinModernMath:mode=base;script=math;language=DFLT;!
Missing character: There is no ≔ (U+2254) in font name:LatinModernMath:mode=base;script=math;language=DFLT;!
Missing character: There is no ≕ (U+2255) in font name:LatinModernMath:mode=base;script=math;language=DFLT;!
Missing character: There is no ≕ (U+2255) in font name:LatinModernMath:mode=base;script=math;language=DFLT;!


The fact that the messages are repeated is due to unicode-math redefining \coloneqq to \coloneq and \eqqcolon to \eqcolon.

However, there should be no need to do anything special, since the math mode colon in Latin Modern Math and most other math OpenType fonts is symmetrical with respect to the equals sign, so := works as you wish. If you really want to use the control sequences, then

\AtBeginDocument{%
\renewcommand{\coloneq}{:=}%
\renewcommand{\eqcolon}{=:}%
}


is what you need.

For the NeoEuler font, where the colon is not symmetric with respect to =, you can emulate the behavior of mathtools by writing this code in the preamble:

\newcommand{\centercolon}{\mathcode:="8000 }
\begingroup\catcode\~=\active \lccode~=:
\lowercase{\endgroup\def~}{\mathrel{\mathop\normalcolonchar}}
\AtBeginDocument{
\edef\normalcolonchar{\Umathcharnum\the\Umathcodenum: }
\edef\normalcolon{\Umathcodenum:=\the\Umathcodenum: }
}


Then the declaration \centercolon will center the colon with respect to the math axis, from that point on; the declaration \normalcolon is the opposite (so \centercolon is similar to \mathtoolsset{centercolon}).

-
I’d like to know where the “missing character” log entries are from? If I look into LuaTeX’s Transcript written on test.log. I cannot find them there. If I remove \coloneq and the other macros from the MWE and just use $:=:=$ I still get the same errors. As I’m only working on the preamble and not on a true document Latin Modern Math was just an unfortunated random pick it seems. From the few available OpenMath OpenType Fonts Neo Euler seems to be the only one to have a non-symmetrical :=. – uli Jan 28 '12 at 14:25
I find those entries in the log file. My version of Latin Modern Math is 0.903. Please, update your question to reflect the real problem. – egreg Jan 28 '12 at 14:33
I have the same version here. Is there something like loglevel=debug that makes the log more verbose? – uli Jan 28 '12 at 14:46
Try adding \tracinglostchars=2 after \begin{document} – egreg Jan 28 '12 at 14:47
\tracinglostchars` has no effect, probably due to this bug – uli Jan 28 '12 at 15:20