# Which commands exist to define new commands?

Which commands are there that one can use to define new commands in (La)TeX?

There are: \let, \def, \[re]newcommand[*], \DeclareRobustCommand[*], and ...?

(And I've seen things like \DeclareMathOperator.)

-
I think there is only \def which defines a new command. \let just assigns a new name. All the others are “only” wrappers around \def, of which there can be arbitrarily many. – canaaerus Feb 11 '13 at 7:36
@canaaerus I suspected something like that. But which well-known (or not so well-known) wrappers are there? – Lover of Structure Feb 11 '13 at 7:45
@LoverofStructure i think your question is rather vague. Just consider LaTeX2e's \newcounter. It sets up a new counter but also defines a command called \thecounter which prints the counter. So for a complete answer one would have to list a lot of macros. – bloodworks Feb 11 '13 at 7:49
@bloodworks Thanks for your contribution; \thecounter without any space ... that's weird. If a comprehensive list is long, so be it :-) – Lover of Structure Feb 11 '13 at 7:57
@LoverofStructure It would be useful to know if you are talking about primitives or higher-level wrappers, and also if you mean just macros or other cases (e.g. do \chardef or \toksdef count?). – Joseph Wright Feb 11 '13 at 8:14

The LaTeX "official" interface provides

\newcommand
\renewcommand
\providecommand

\newlength
\newsavebox

\newenvironment
\renewenvironment
\newtheorem

\newcounter


All these commands define one or more commands (some only for internal usage) and provide tests for avoiding clobbering of existing commands. There's also \newfont, but its usage is deprecated.

The kernel has many other command-defining macros:

\DeclareRobustCommand

\DeclareTextCommand
\DeclareTextCommandDefault
\DeclareTextSymbol
\DeclareTextSymbolDefault
\DeclareTextAccent
\DeclareTextComposite
\DeclareTextCompositeCommand

\DeclareMathSymbol
\DeclareMathAccent
\DeclareMathDelimiter

\protected@edef


Of these, only the first one is commonly used in LaTeX programming (it shouldn't be used indiscriminately as a replacement of \newcommand, though). The last is very useful in core LaTeX programming.

Some additional packages provide new functions:

\DeclareMathOperator      (amsmath)
\DeclarePairedDelimiter   (mathtools)


are commonly found, but there are scores of other command-defining functions in the hundreds of packages around.

Another commonly used utility for defining commands is the primitive \let, that "copies" the current meaning of a token into a control sequence, allowing for "redefining a macro in terms of itself". However, for the nonexpert (and also the expert) programmer, the

\LetLtxMacro


provided by the letltxmacro package by H. Oberdiek is a recommended replacement.

The etoolbox package provides another set

\newrobustcmd
\renewrobustcmd
\providerobustcmd


(look at the documentation for a description).

Eventually, all of these command-defining functions boil down to the primitive commands

\def
\gdef
\edef
\xdef

\let
\futurelet

\chardef
\mathchardef
\countdef
\dimendef
\skipdef
\muskipdef
\toksdef

\font