Is there way to expand the body passed to NewDocumentCommand
at the point of definition? Ideally, just expanded the once.
Here is my (minimalised) scenario.
\documentclass{minimal}
\newcommand*{\baz}{\foo}
\newcommand*{\expandme}{good}
\ExplSyntaxOn
\exp_args:NV \NewDocumentCommand \baz { s D<>{} } {
\expandme% Should get expanded once at definition time.
}
\ExplSyntaxOff
\renewcommand*{\expandme}{bad}
\begin{document}
\foo<bar>% Prints "bad", but I want it to print "good".
\end{document}
Making the following modification yields an Undefined control sequence
error, presumably because \exp_args
is having a hard time with the { s D<>{} }
argument.
\exp_args:NVNo \NewDocumentCommand \baz { s D<>{} } {
\expandme% Should get expanded once at definition time.
}
Finally, note that the following solution, which works in the simplest case, but is problematic when \bar
can take a number of values, and this code is repeated for each (as is my real scenario).
\exp_args:NNV \cs_set:Npn \tmp \expandme
% alternatively to the above line, I think: \edef\tmp\expandme
\exp_args:NV \NewDocumentCommand \baz { s D<>{} } {
\tmp
}
{ s D<>{} }
needs to be n not N