I have a command defined using xparse
syntax:
\DeclareDocumentCommand \foo { O{} m } {}
Inside some other command (say, \bar
), I want to call this command. The calling command (\bar
) has to construct the arguments to feed to \foo
. So the call is something like:
\foo [\tl_use:N \l_my_temporary_tl] {}
I want to make sure that when \foo
is called, it is the actual token list and not the command that gets passed.
If \foo
took two mandatory arguments then it would appear that I could just do
\exp_args:No \foo {\tl_use:N \l_my_temporary_tl} {}
(I realise that the number of expansions here might be incorrect, but that's not the point.)
Is there a similar syntax for optional arguments?
If not, how would the following look:
\cs_new:Npn \exp_opt_args:No #1[#2] { \exp_after:wN #1 \exp_after:wN [#2] }
and similar ...
xparse
is for document commands. Could you add a concrete example of where this is needed at a document level? (Usually, a function defined byxparse
should simply pass the input to a well-defined code-level function with a fixed number of mandatory arguments.)