
有沒有辦法使用擴展宏的值作為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}