I’ve been using \let\oldsomething\something\renewcommand*something{\oldsomething ...} in a couple places, but it’s tedious and I guess prone to errors if I were to try to redefine again with the same auxiliary macro.
After learning about \g@addto@macro I was happy for a while. Then arose the need to append to a command which has arguments:
\newcommand*{\hello}[1]{Hello #1}
\g@addto@macro{\hello}{!}
\show\hello
That sequence prints:
> \hello=macro:
Hello !.
So, the argument seems to disappear. The result I was attempting is:
> \hello=macro:
->Hello #1!.
Is there some easy way to change the middle line to obtain this, or is it back to the old way for macros with arguments?
etoolbox's\patchcmdis probably what you're looking for… – cgnieder Sep 28 '17 at 08:37xpatchif the command is defined with optional arguments or with\DeclareDocumentCommand– egreg Sep 28 '17 at 08:42