I don't understand an example from section 6.1 of expl3-intro.tex from LATEX3 documentation. It is said there:
Here are two equivalent ways of defining the function
\foo:nn
:\cs_set:Npn \foo:nn #1#2 {(#1)/(#2)} \cs_set:cpn {foo:nn} #1#2 {(#1)/(#2)}
These macros are respectively equivalent to \TeX's
\long\def\foo:nn
, and
\expandafter\long\expandafter\def\csname foo:nn\endcsname
.
Note the
:nn
suffix to denote that |\foo| takes two arguments.
Given equivalents seem to be reduced rather than complete. Could somebody provide accurate equivalents of
\cs_set:Npn \foo:nn #1#2 {(#1)/(#2)}
and
\cs_set:cpn {foo:nn} #1#2 {(#1)/(#2)}
?
In particular, I wonder at \long\def\foo:nn
. Is colon allowed in command names in Plain TeX or LaTeX 2e? Is it assumed here that catcode of :
has been changed? If so, corresponding commands are suggested to be explicitly added to the above example. And where is the expanded part of definitions (i.e. {(#1)/(#2)}
)?
Best Answer
In LaTeX3 code blocks, both
:
and_
are 'letters'. Thus in the demo, the control sequence is\foo:nn
, including the:
and thenn
. As the docs sayis exactly equivalent to
and
is exactly equivalent to
Here, I've taken advantage of fact that spaces are ignored in LaTeX3 code blocks. I've also assumed in the first example that
:
is a 'letter'.