I have several functions defined by similar way, and they will be used later by the name base + argument.

I do not find \cs_use:c, but there is \use:c and \cs_if_exist_use:c. Is this the correct way to do such thing or I should use something else like \str_case:nn?

\cs_new_protected:Nn \my_test_a:n
\cs_new_protected:Nn \my_test_b:n
\NewDocumentCommand { \test } { m m }
    \cs_if_exist_use:c { my_test_#1:n } { #2 }

  • 1
    There is also \cs_if_exist:cTF, which might help.
    – Alan Xiang
    Commented Aug 31, 2020 at 3:28

2 Answers 2


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


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.

  • That's a good advice!
    – ZhiyuanLck
    Commented Aug 31, 2020 at 8:47

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .