The LaTeX3 coding language,
_ as 'letters' in function and variable names. This allows use of
expl3 code-level material in a document
\cs_new:Npn .... % fails: command \cs followed by characters '_', 'n', 'e', 'w', etc.
\cs_new:Npn .... % works here: command name \cs_new:Npn
\ExplSyntaxOn command activates this, and also alters the treatment of spaces and line endings so these are ignored, meaning that
\cs_new:Npn \my_function:nn #1#2
% Code hre
does not require
% at the end of each line (compare to 'normal' LaTeX2e code). To allow inclusion of spaces in the output,
~ is made into a 'normal' space by
\ExplSyntaxOn. Note that this change in the behaviour of spaces is not essential to access
expl3 names, but the two are closely tied together as the combination allows 'clearer' programming in
\ExplSyntaxOff reverses this, returning
~ to their standard status and making spaces 'important' again.
At a technical level, the idea of category codes in command names is exactly the same as in What do \makeatletter and \makeatother do?, although the
\ExplSyntax... switches do more.
A couple of points to note about the treatment of
~ within a code block. First, as
~ is a 'space' inside a code block, a
~ at the start of a line is ignored by TeX
~ \cs_new:Npn ....
is exactly the same as
as the 'space' is ignored.
~ is a 'space' inside a code block,
\~ are still distinct and have the LaTeX2e definitions.