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


, 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)}


\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)})?


In LaTeX3 code blocks, both : and _ are 'letters'. Thus in the demo, the control sequence is \foo:nn, including the : and the nn. As the docs say

\cs_set:Npn \foo:nn #1#2 { (#1) / (#2) }

is exactly equivalent to



\cs_set:cpn { foo:nn } #1#2 { (#1) / (#2) }

is exactly equivalent to

\expandafter\long\expandafter\def\csname foo:nn\endcsname#1#2{(#1)/(#2)}

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'.

  • So, \long\def should be prepended with \catcode`:=11 and \catcode`_=11. Nov 24 '11 at 8:49
  • @Igor Conceptually yes, in the same way as saying that with a lot of LaTeX2e snippets "do not forget \makeatletter".
    – Joseph Wright
    Nov 24 '11 at 8:56
  • @IgorKotelnikov I just want to note here that \ExplSyntaxOn/Off is the expl3 analogue to \makeatletter/other. Catcode assignments aren't required :) (I say this here because I've seen it and they cited this Q.) May 18 '15 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.