# Hacking - Memorize a command before reimplement it

Here is a small code.

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}

\begin{document}

\keys{Ctrl+Alt+C}
\keys{BUG}
\keys{\return}

\end{document}


Let's supposed that I know for example that \keys{BUG} and \keys{\return} don't work well. So I would like to redefine the commands \keys so as to use a partial home made solution during that the package will be repaired.

To do that I need to keep the trace of the original \keys macro in a command \@@@@keys for example. Then I could define my macro \keys that will take care of the arguments BUG and \return, or just reuse the original macro \keys. How can I do that ?

-

Something like this, however I did not check how \keys processes its input, I notice that it is not defined as a one parameter macro initially, it could do things with catcodes which here will not be possible. Perhaps though this does not happen, hence the proposed solution could be viable.

(standalone class used to produce cropped image)

\documentclass[border=12pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\makeatletter
\let\originalkeys\keys
%\show\keys
\protected\def\keys #1{\in@{#1}{BUG,\return}%
\ifin@\expandafter\mykeys\else
\expandafter\originalkeys
\fi {#1}}
\makeatother
\newcommand{\mykeys}[1]{\fbox{\ttfamily\detokenize{#1}}}
\begin{document}
\keys{Ctrl+Alt+C}
\keys{BUG}
\keys{\return}
\end{document}

-
Good. I will keep that in my recipes. Thanks a lot ! – projetmbc Mar 15 '14 at 11:38
@projetmbc de rien. But in case \keys accepts an optional parameter, let me mention that the method here does not allow its use here with the patched version. – jfbu Mar 15 '14 at 12:21
The method only work for no-optional-argument macros ? – projetmbc Mar 15 '14 at 13:04
it works even for a macro with an optional argument as long as no use is made of an optional argument ... if you need to patch a macro with optional argument this can be done too. – jfbu Mar 15 '14 at 13:09
Cool. I will keep it in mind. – projetmbc Mar 15 '14 at 13:21