Suppose we have

\newcommand{\foo}[2][optional]{#1 #2}

defined somewhere (e.g. some package) and want to redefine it and re-use the original definition. This usually works with \let like described in https://en.wikibooks.org/wiki/TeX/let:

\renewcommand{\foo}[2][optional]{\originalfoo[#1]{modified #2}}

However, this leads to an infinite loop, as \let does not handle the optional argument.

How to handle the optional argument defined by \newcommand with \let?

  • FYI, I have a hack/workaround for it, but I would find it nicer, if copying by \let would workout somehow. – Daniel Krenn Mar 25 '18 at 11:35
  • Thank you for the link to tex.stackexchange.com/questions/88001/when-to-use-letltxmacro This other question is somehow the other way round and hard to find if you have the problem explained (the problem here is one case of an answer in the link; the answer here is the problem stated.) – Daniel Krenn Mar 26 '18 at 13:09

The usual \let does not work with macros having optional arguments. You need \LetLtxMacro from letltxmacro package in order to achieve this.



\newcommand{\foo}[2][optional]{#1 #2}


\renewcommand{\foo}[2][optional]{\originalfoo[#1]{modified #2}}



Not the answer you're looking for? Browse other questions tagged or ask your own question.