# Problem between unicode-math and babel option frenchb in LuaLaTeX

I've got a strange problem in LuaLaTeX with both babel, option frenchb, and unicode-math. My TeX Distribution is TeX Live 2013 (installed with MacTeX on a OS X.8.5 system). If I run the following program:

\documentclass{minimal}
\usepackage{unicode-math}
\setmathfont{XITS Math} % or any other math font
\usepackage[frenchb]{babel}
\begin{document}
\relax
\end{document}


I obtain this error message:

(/usr/local/texlive/2013/texmf-dist/tex/luatex/hyph-utf8/luatex-hyphen.lua)))
! Extended mathchar used as mathchar (6300214).
=
l.244   \initiate@active@char{:}
%
? h
A mathchar number must be between 0 and "8000.
I changed this one to zero.
?


However, it works flawlessly either if I use XeLaTeX, or if I don't use the \setmathfont command, or if I load babel option frenchb before unicode-math:

\documentclass{minimal}
\usepackage[frenchb]{babel}
\usepackage{unicode-math}
\setmathfont{XITS Math} % or any other math font
\begin{document}
\relax
\end{document}


Any idea of what is going wrong?

-
It compiles with XeLaTeX, but not with LuaLaTeX – egreg Feb 2 '14 at 22:07
Indeed, as I noticed… But why this difference? I don't understand. – Franck Pastor Feb 2 '14 at 22:16

Load babel before unicode-math:

\documentclass{minimal}

\usepackage[frenchb]{babel}
\usepackage{unicode-math}
\setmathfont{XITS Math}

\begin{document}

a: ba : b

$a:b$

\end{document}


The difference lies in the fact that XeLaTeX and LuaLaTeX use different methods for typesetting the colon French style, that is with equal spaces on either side.

If you add \the\catcode: after \begin{document}, you'll get 13 if compiling with LuaLaTeX, but 12 if compiling with XeLaTeX. With the latter engine the shorthand features of babel aren't needed, while they are with LuaLaTeX.

So the only solution is to always load babel before unicode-math, so the activation of the shorthand characters can be acknowledged by unicode-math.

More precisely, LuaLaTeX uses an active colon, just like the traditional way. In XeLaTeX, the colon, semicolon, question mark and exclamation mark are placed in special \XeTeXcharclass arrays and rules when passing from a character in class 0 (all normal characters) or 255 (the space, although this would require many explanations) and these special classes are established. For instance, when a normal character is followed by a character in the class named \FB@punctthick (the colon), the code

\ifhmode\penalty 10000 \space\fi


is executed, while after a space the code inserted is

\ifhmode\unskip\penalty 10000 \space\fi


So, a possible space preceding the colon is removed (users can type a space before the colon), a penalty inhibiting a line break is inserted and a normal interword space is added.

-
You're right but I had already noticed that (see the last part of my question). I wanted to understand why it doesn't work if I load frenchb after unicode-math. Thanks to Herbert I see that it is (once again) a problem with the characters activated by frenchb. But how comes it works with XeLaTeX then?? – Franck Pastor Feb 2 '14 at 22:14
@fpast Yes, I didn't notice the last part. Now you know the reason for the difference. – egreg Feb 2 '14 at 22:33
Great, now I understand after your answer's editing. :-) – Franck Pastor Feb 2 '14 at 22:33
Would using polyglossia instead of babel` help? – Martin Schröder Feb 3 '14 at 8:51
@MartinSchröder Polyglossia doesn't work with LuaLaTeX – egreg Feb 3 '14 at 8:55