[luatex] \mathchardef\foo=\mathcode`\x

David Carlisle d.p.carlisle at gmail.com
Fri Dec 18 22:27:57 CET 2015


The idiom

\mathchardef\foo=\mathcode`\x

is commonly used to  save a mathcode of some character while you
temporarily change it for some reason.

Notably it's used (4 times) during the loading of the AMS package
amsmath, the main math support in latex.

this breaks in 0.87 as \mathcode returns a number suitable for
\Umathcharnumdef which is too large for \mathchardef.

I'm not (necessarily) suggesting that the luatex behaviour change but
if anyone is wanting to test latex math support with the new engine
they may want to patch a local copy of amsmath.sty for testing as at
the end of this message.

Since \mathchardef is mainly for legacy use anyway, I wonder if luatex
could keep this working, specifically \mathchardef if given a number
bigger than hex 8000 could perhaps (instead of giving an error) act
like \Umathcharnumdef.. An alternative would be to try to do the same
test  via a macro redefinition of \mathchardef probably using the lua
token scanner to get the integer) but emulating all the primitive
behaviour in a compatible way might be hard.

The other alternative, as below, is to update the tex code to use
\Umath... but finding all such uses and getting authors to update
might be tricky, just a first scan shows the following (most of which
are affected by this)

$ grep -l mathchardef.*mathcode */*.???
amsmath/amsmath.sty
amsmath/amsopn.sty
bgteubner/bgteubner.cls
breqn/flexisym.sty
commath/commath.sty
dozenal/dozenal.sty
eulervm/eulervm.sty
fontinst/fontdoc.sty
ionumbers/ionumbers.sty
listings/lstlang3.sty
mandi/mandi.sty
mathastext/mathastext.sty
mathtools/mathtools.sty
mdsymbol/mdsymbol.sty
ncctools/ncccomma.sty
semantic/ligature.sty
stix/stix.sty
tudscr/mathswap.sty
unicode-math/unicode-math-xetex.sty
was/icomma.sty
zed-csp/zed-csp.sty


David

For people wanting to use amsmath, a fix would be to change line 741
of amsmath,sty  so it looks something like

\ifx\hyphenationmin\undefined
\mathchardef\std at minus\mathcode`\-\relax
\mathchardef\std at equal\mathcode`\=\relax
\AtBeginDocument{%
  \mathchardef\std at minus\mathcode`\-\relax
  \mathchardef\std at equal\mathcode`\=\relax
}
\else
\Umathcharnumdef\std at minus\Umathcodenum`\-\relax
\Umathcharnumdef\std at equal\Umathcodenum`\=\relax
\AtBeginDocument{%
  \Umathcharnumdef\std at minus\Umathcodenum`\-\relax
  \Umathcharnumdef\std at equal\Umathcodenum`\=\relax
}
\fi


More information about the luatex mailing list