0

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?

  • Package etoolbox's \patchcmd is probably what you're looking for… – cgnieder Sep 28 '17 at 8:37
  • 1
    And xpatch if the command is defined with optional arguments or with \DeclareDocumentCommand – egreg Sep 28 '17 at 8:42

Browse other questions tagged or ask your own question.