拡張マクロを \patchcmd の検索パターンとして使用する

拡張マクロを \patchcmd の検索パターンとして使用する

etoolbox拡張マクロの値を's \patchcmd(またはxpatch's\xpatchcmdなど) の検索パターンとして使用して、catcodes を変更することで、ある種の「動的」パッチを作成する方法はありますか?

以下に最小限の動作例 (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}

答え1

mychoice呼び出す前に展開したいので\selectpet、次のようになります。

\expandafter\selectpet\expandafter{\mychoice}

関連情報