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 minimum working example (MWE).
\documentclass{article}
\usepackage{etoolbox}
\usepackage{xcolor}
\begin{document}
\newcommand{\wordlist}{cat dog parrot goldfish hamster}
\newcommand\selectpet[1]{%
\bgroup
\patchcmd{\wordlist}{#1}{\textcolor{red}{#1}}{}{}
\wordlist
\egroup
}
\selectpet{dog} %% This works
\def\mychoice{dog}
\selectpet{\mychoice} %% This doesn't
\end{document}
\expandafter\selectpet\expandafter{\mychoice}
expl3
sequences code instead of patching?expl3
-fu is not up to scratch at all. :-/