I want to know the reasoning behind the (La)TeX inferface for defining commands with leading backslashes. I see why a backslash has to be used to call (expand) a command (macro), but I do not understand why it is used in definitions.
There are many ways to define a command in (La)Tex (ignoring the \let
commands and the LaTeX 3 core and possible others) giving the command name with a leading backslash:
- TeX:
\def
,\gdef
,\edef
andxdef
, all having possibly the prefix\long
- LaTeX:
\newcommand
,\renewcommand
,providecommand
,DeclareRobustCommand
, all having possibly the suffix*
- etoolbox:
\newrobustcommand
,\renewrobustcommand
,providerobustcommand
, all having possibly the suffix*
- xparse:
\DeclareDocumentCommand
,\NewDocumentCommand
,\RenewDocumentCommand
,\ProvideDocumentCommand
, all having possibly an+
in the argument specification
There is also the possibility to define a command without a backlash
- TeX:
\expandafter\def\csname name \endcsname
(similar for the commands mentioned for TeX above) - etoolbox:
\csdef
(similar for the commands mentioned for TeX above)
I think the definitions without a backslash have clear advantages:
- more general: allowing to create dynamically named commands (e.g. \csdef{double#1}{#1,#1})
- better semantic: The backslash means using a variable, i.e. expanding it
- shorter: Save one character, do not disturb the eye
The question is: Why do the default command definitions need a backlash when it seems more useful to do without?
Specifiying the question a bit more:
Obviously, the definitions from etoolbox have advantages compared to the TeX ones being much shorter and clearer. The xparse definitions have clear advantages regarding their arguments' flexibility, too. So it seems natural to combine them. If one would define (with \expandnext
from etextools) a command like
\NewDocumentCommand{\declare}{mmm}{%
\expandnext{\DeclareDocumentCommand}{\csname #1\endcsname}{#2}{#3}%
}
what would one loose? Let us assume, that new
, renew
and provide
would be defined similarly and let us keep the local/global discussion and the possible expansion of the third argument aside, leading to \gdeclare
, \edeclare
and xdeclare
in the long run.