[Tex/LaTex] Why are there so many underscores in LaTeX3 commands

latex3tex-history

This question springs from a comment of mine and the subsequent discussion in chat.

I don't know anything about TeX, but I can easily understand a command like:

\let\oldmacro\somemacro

whereas

\cs_set_eq:NN

is not so clear to me.

In particular, all those underscores within the command names thoroughly dizzy me. Why was _ chosen, instead of writing \csSetEq, for example?

Moreover, why is :NN needed? Why is it necessary to add syntax information to the command name?

Isn't having self-explanatory commands one of the strength of LaTeX?

Best Answer

Underscores

\csSetEq wouldn't work: for such basic, internal commands you need names that a normal user can't accidental overwrite. That's why internal LaTeX2e commands have @ and context uses ! and also underscores: \c_anch_sidebars_current \c!bottomoffset.

expl3 couldn't use @ as it could to easily clash with existing commands and packages and from the other possible non-letters (!,?, *,+,...) imho underscores are not a bad choice: When you get used to it you can read many commands like sentences. \cs_set_eq = commands set equal, \tl_if_exist, \regex_extract_once.

The :NN-syntax

One problem when reading (La)TeX code is that it is very difficult to see how many arguments a command has (if any). This makes it difficult to understand the processing of a command and to debug errors due to missing or wrong argument. A command like e.g. \@sect takes 6 arguments but you have to go back to the definition to see this. With the :NN-syntax you have a much better overview.

Related Question