As with any TeX programming, the need to absorb and re-emit tokens arises in expl3
code. There are at least two reasons we may want to do this. The first is that tokenization occurs when an argument is absorbed. Thus we might want for example to switch category code setup and read a file:
\use:n { \ExplSyntaxOff \file_input:n {#1} }
In the above, \file_input:n
is a single token but within the file that is then read both _
and :
are not letters.
The second common thing we need to do is to have a case where \use:n
goes with some no-op or similar: we want a braced group for convenience but don't want the braces to affect the output. Thus
\if_meaning:w #1 #2
\exp_after:wN \use_none:n
\else:
\exp_after:wN \use:n
\fi:
{ tokens-here }
will insert the tokens without any surrounding group when the test is false, and otherwise will remove them entirely.
\@firstofone
which does the same, consider\foo{xxx}
where you decide later if\foo
is\@firstofone
or\@gobble
– David Carlisle Jul 31 '17 at 13:35