Consider the following example. The code is trying to append something after \mytest. Strangely, when there is an extra group, the \hook_gput_code:nnn does not work. There is no error message, just that the compilation process never stops. Why would this happen and what should one do to make the hook work?


% \def\mytest{\normalfont\bfseries Text} % works
\def\mytest{{\normalfont\bfseries Text}} % does not work

\hook_gput_code:nnn { cmd/mytest/after } { mymodule }
    Some code



  • Smells like a bug... I'll investigate in a bit. Though I get an error ! Undefined control sequence. \@nnil ->\@nil (bug either way) Commented Mar 18, 2022 at 15:47
  • This should fix the issue: github.com/latex3/latex2e/commit/8f99cdeb. If you want a temporary patch: pastebin.com/raw/rhFLYRuN Commented Mar 18, 2022 at 20:30
  • 1
    ...or two hours... Try this one: pastebin.com/raw/NbYr715A Commented Mar 18, 2022 at 23:17
  • 1
    It will be fixed in the next LaTeX release (2022-06-01). I already opened a PR for it: github.com/latex3/latex2e/pull/796. Please don't add that to a package :) Commented Mar 19, 2022 at 9:32
  • 1
    Sorry for the delay (I forgot about this). The whole issue is that the code takes the first item in the macro definition (in this case the tokens inside the brace), and does \string on the first token, and expands the rest. You can work around the issue by making the first item in the macro be a single token, for example \def\mytest{\relax{\normalfont\bfseries Text}}. Since it seems to be a typesetting command, the \relax shouldn't be a problem, but you can use something else, like \@empty. Depends on what exactly the command does Commented Mar 24, 2022 at 16:32

1 Answer 1


This was caused by a bug in an internal function that detects the type of a command (how it was defined; this information is used to determine how to add the cmd hook). The bug would cause a premature expansion of the code which could cause trouble depending on how it was defined. This has been fixed for the 2022-06-01 release.

Here's the relevant pull request for whom it may be of interest: https://github.com/latex3/latex2e/pull/796

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .