Open muzimuzhi opened 9 months ago
Note the current test suite throws such error too. After running l3build check
,
$ grep -rn 'Illegal parameter number in definition' build/test/**/*.log
build/test/amsmath.log:130:! Illegal parameter number in definition of \__hook package/amsmath/after.
build/test/deprecation.log:96:! Illegal parameter number in definition of \__hook package/amsmath/after.
build/test/icomma.log:66:! Illegal parameter number in definition of \__hook package/amsmath/after.
build/test/kernel-style.log:64:! Illegal parameter number in definition of \__hook package/amsmath/after.
What surprised me is, using
\alignmark
in\AddToHook
directly in preamble won't throw such an error.
Nope. The condition to reproduce the problem is to add to a hook which already contains \alignmark\alignmark
, rather than ##
.
\documentclass{article}
\AddToHook{package/amsmath/after}{%
% \def\x{##}% works
\def\x{\alignmark\alignmark}% doesn't work
}
\AddToHook{package/amsmath/after}{}
\begin{document}
\end{document}
Now this looks like a hooks management issue.
Update: According to the LuaTeX Reference Manual (April 2023, v1.16), sec. 2.8.5 "\alignmark
and \aligntab
"
The primitive
\alignmark
duplicates the functionality of # inside alignment preambles, ...
Thus my simplified examples are not typical usages, but should still work.
It seems in LuaTeX, when appeared in replacement text of a macro, number of consecutive \alignmark
s is halved, just like number of #
s. For example, \def\x{\alignmark\alignmark}
defines \x
holding a single \alignmark
.
Since the code of a hook is stored in a macro, number of \alignmark
s is halved when first added to a hook, then halved twice when later some code is added to the same hook again.
(first reported in https://github.com/latex3/mathtools/issues/55#issuecomment-1717077850)
Loading
lualatex-math
beforeamsmath
throws errorThe problem is caused by two LuaTeX primitive
\alignmark
used inhttps://github.com/phst/lualatex-math/blob/c4c7e6323923970e52754da00d04cf0983f67b7c/lualatex-math.dtx#L564
Replacing
\alignmark \alignmark
with##
seems to solve the problem. I'm guessing that's because\alignmark
is not doubled by hook macros.What surprised me is, using
\alignmark
in\AddToHook
directly in preamble won't throw such an error.