In Pass a command as argument for another command, a notion of invoking TeX macros as methods was described. In my case, I'm attempting to use arguments within the call structure. My example below uses two passes of \StrSubstitute
to replace characters that I want to modify:
\usepackage{xstring} % for StrSubstitute
\newcommand*{\changeslash}[1] {%
\StrSubstitute{#1}{/}{5c}%
}
\newcommand*{\changedollars}[1] {%
\StrSubstitute{#1}{\$}{24}%
}
\newcommand*{\changeboth}[1] {%
\changeslash{\changedollars{#1}}%
}
I've experimented with adding \expandafter
in different places, but this problem has me stumped.
Best Answer
xstring
replacements do not work by expansion, but they need the input string to be expanded, thus adding\expandafter
doesn't really help. You need to use the optional argument so that the string with the replacement is stored in a temporary macro, then you can use\expandafter
to expand that macro to pass to the second call. In addition as it fully expands its input in a way not entirely consistent with LaTeX\protect
mechanism I needed to make\$
e-tex protected.