latex3 use function by name

It depends on what you want to do when the composed function does not exist.

The function \cs_if_exist_use:c is essentially the same as \use:c: they're wrappers around \csname...\endcsname. The former, however does a check that the latter doesn't.

What's the reason for \cs_if_exist_use:c, then? It is part of the series

\cs_if_exist_use:c \cs_if_exist_use:cT \cs_if_exist_use:cF \cs_if_exist_use:cTF

If you do

\test{a}{abc}
\test{b}{abc}
\test{c}{abc}

you get

*abc* +abc+ abc

but probably you want to be warned about the third case or maybe to output nothing. With

\NewDocumentCommand { \test } { m m }
  {
    \cs_if_exist_use:cF { my_test_#1:n } { \use_none:n } { #2 }
  }

the output would be

*abc* +abc+

because \my_test_c:n doesn't exist, so TeX is instructed to put \use_none:n in the input stream, which gobbles the following n argument. You may add a suitable warning or error message in front of \use_none:n.


The \use:c is from the very early days of expl3 and it is precisely for this task (without any check in situations where you know your name is valid). Arguably it could have been given the name \cs_use:c as an alias but it can be equally well useable for token list variables and so it was put into the \use_...family of names.

Tags:

Expl3