Skip to content

Loading error Illegal parameter number if amsmath is not loaded yet #26

@muzimuzhi

Description

@muzimuzhi

(first reported in latex3/mathtools#55 (comment))

Loading lualatex-math before amsmath throws error

! Illegal parameter number in definition of \__hook package/amsmath/after.
% !TeX program = lualatex
\documentclass{article}
\usepackage{lualatex-math}

\begin{document}
content
\end{document}

The problem is caused by two LuaTeX primitive \alignmark used in

\__lltxmath_after_package_or_now:nn { amsmath } {
  ...
  \@ifpackagelater { amsmath } { 2020/09/23 } { } {
    \__lltxmath_patch:NNnnn \subarray \cs_set:Npn { #1 } {
      ...
      $ \m@th \scriptstyle ## $
      \hfil
      \crcr
    } {
      ...
      \Ustartmath
      \m@th
      \scriptstyle
      \alignmark \alignmark
      \Ustopmath
      \hfil
      \crcr
    }
    ...
  }
}

\alignmark \alignmark

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.

% !TeX program = lualatex
\begin{filecontents}[force]{x-math.sty}
\AddToHook{package/amsmath/after}{%
  \def\y{\alignmark\alignmark}%
}
\end{filecontents}

\documentclass{article}
\AddToHook{package/amsmath/after}{%
  \def\x{\alignmark\alignmark}%
}

\input x-math.sty % errors

\usepackage{x-math} % errors

\begin{document}
content
\end{document}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions