I am trying to create an expandable command that accepts a single argument that may contain control sequences, and expands to that same argument with all control sequences and braces removed. That is:
\StripControlSequences{John Q. Author, \textit{Book Title}}
should expand to merely:
John Q. Author, Book Title
Alternatively, if I could designate the control sequences that get stripped out, such as \textit
, \textbf
, etc. that would be reasonable, as well.
If I didn't care about expandability, this would be easy. I have a macro using xstring that strips out arbitrary control characters. If I just wanted to get rid of the formatting from \textit
during execution, I could do something like this:
\def\StripControlSequences#1{{%
\let\textit=\relax%
#1%
}}
Unfortunately, this is not expandable; from my understanding, any macro that itself uses assignments (including \let
and \def
) can never be expanded. In this case, I need to use the output of \StripControlSequences
in something like the following:
\def\Def#1#2{\expandafter\def\csname\StripControlSequences{#1}\endcsname{#2}}
such that the command sequence could later be called, without the control sequences, like the following:
\Def{John Q. Author, \textit{Book Title}}{full citation string}
\begin{document}
\csname John Q. Author, Book Title\endcsname
\end{document}
which would produce a document with only:
full citation string
(of course, users of my macro package wouldn't call \csname ... \endcsname
directly, but you get the point). In case anyone is wondering about the context, I have a macro package for producing automated legal citations, and given that my target audience is non-technical, I need to try to make the interface as simple as possible. (I'm happy to explain more about the broader context, if necessary).
I've hunted for a while for any good answers to this without luck; but I apologize if this has been asked before! I basically understand the problems with fragile/robust commands, but it seems to me that no combination of \protect
, etc. will be applicable here, because \protect
merely delays expansion until later execution, so as to allow its argument to be moved. On the other hand, here I basically want execution at all times.
So perhaps another way to ask this question is: is it possible to force execution, like an \edef
that fully executes its argument, instead of merely expanding it?