Consider the following example of a patch using etoolbox
and a dummy macro \abc
:
\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\newcommand{\abc}[2]{#1\ #2}% Magic macro
\begin{document}
\abc{A}{B}
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\abc}{#1}{#2}{}{}%
\abc{A}{B}
\end{document}
If I want to maintain good programming practice, I'm encouraged to put \patchcmd
in the document preamble (separating structure from content) and only trigger it with a different macro, say \patchabc
:
\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\newcommand{\abc}[2]{#1\ #2}% Magic macro
\newcommand{\patchabc}{%
% \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>}
\patchcmd{\abc}{#1}{#2}{}{}%
}
\begin{document}
\abc{A}{B}
\patchabc% Patch \abc
\abc{A}{B}
\end{document}
However, the above does not work since #1
and #2
inside \patchabc
is assumed to reference its arguments while \patchabc
has none. How can I write a macro that acts like a switch (and is cleaner in terms of the programming) that patches another macro's use of its own arguments?