Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Here is a small code.

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

\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 ?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

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.

my keys

(standalone class used to produce cropped image)

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

\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}
share|improve this answer
    
Good. I will keep that in my recipes. Thanks a lot ! –  projetmbc Mar 15 at 11:38
1  
@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 at 12:21
    
The method only work for no-optional-argument macros ? –  projetmbc Mar 15 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 at 13:09
    
Cool. I will keep it in mind. –  projetmbc Mar 15 at 13:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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