I'm trying to create a macro where the optional item emboldens an item in the list. I can process the list using the expl3/xparse package and can compare the two strings but I'm having trouble doing both simultaneously. Can one return compare as an encapsulated macro which accepts one argument or can one extend ProcessList to handle two arguments ? I have read other posts on here but can't seem to find anything that matches this use case.
\documentclass{article}
\ExplSyntaxOn
\newcommand{\compare}[2]{\ifthenelse{\equal{#1}{#2}}{\textbf{#1}}{\emph{#2}}}
\NewDocumentCommand\within{O{} >{\SplitList{,}}m}{%
\def\compari{\compare{#1}{##2}}
\ProcessList{#2}{\compari}%
}
\ExplSyntaxOff
\begin{document}
\compare{apples}{bananas}
\compare{apples}{apples}
\within{apples}{apples,bananas}
\end{document}
Expected output
bananas
apples
apples, bananas
\@forand\@tforare described in Kopka&Daly. Can't give exact references right now. Like all internal macros they might change, although that's quite unlikely in this case. There is no danger in using them but you better not redefine them ;-) – campa Aug 28 '15 at 18:52texdoc source2ewill open the pdf file containing the source code of the latex format.@forsource code is found in my copy on page 51, corresponding toFile f: ltcntrl.dtx Date: 2014/04/21 Version v1.0h. There is also\@tfor. – Aug 31 '15 at 15:24