Is there any way to use the value of an expanded macro as the search pattern for etoolbox's \patchcmd (or xpatch's \xpatchcmd, etc), so that one can have some sort of a "dynamic" patch, by way of change catcodes?

Here's a MWE.




\newcommand{\wordlist}{cat dog parrot goldfish hamster}


\selectpet{dog}  %% This works

\selectpet{\mychoice}  %% This doesn't

  • 2
    Full expansion or once? – percusse Feb 5 '16 at 10:00
  • 1
    \expandafter\selectpet\expandafter{\mychoice} – David Carlisle Feb 5 '16 at 10:08
  • Perhaps this is easier with expl3 sequences code instead of patching? – user31729 Feb 5 '16 at 10:51
  • Thanks @percusse, you pointed me in the right direction, and @David hit it on the head! @Christian Unfortunately my expl3-fu is not up to scratch at all. :-/ – LianTze Lim Feb 5 '16 at 13:24
  • @DavidCarlisle Ahem... an answer maybe ? – percusse Feb 5 '16 at 13:30

You want to expand mychoice before calling \selectpet so:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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