12.14.7 \DeclareRobustCommand


\DeclareRobustCommand* (same parameters

\DeclareRobustCommand and its starred form are generally like \newcommand and \newcommand* (see \newcommand & \renewcommand), with the addition that they define a so-called robust command, even if some code within the definition is fragile. (For a discussion of robust and fragile commands, see \protect.)

Also unlike \newcommand, these do not give an error if macro cmd already exists; instead, a log message is put into the transcript file if a command is redefined. Thus, \DeclareRobustCommand can be used to define new robust commands or to redefine existing commands, making them robust.

The starred form, \DeclareRobustCommand*, disallows the arguments from containing multiple paragraphs, just like the starred form of \newcommand and \renewcommand. The meaning of the arguments is the same.

Commands defined this way are a bit less efficient than those defined using \newcommand so unless the command’s data is fragile and the command is used within a moving argument, use \newcommand.

Related to this, the etoolbox package offers three commands and their starred forms: \newrobustcmd(*) \renewrobustcmd(*), and \providerobustcmd(*). They are similar to \newcommand, \renewcommand, and \providecommand and their own starred forms, but define a robust cmd. They have two possible advantages compared to \DeclareRobustCommand:

  1. They use the low-level e-TeX protection mechanism rather than the higher-level LaTeX \protect mechanism, so they do not incur the slight loss of performance mentioned above, and
  2. They make the same distinction between \new…, \renew…, and \provide…, as the standard commands. That is, they do not just write a log message when you redefine cmd that already exists; you need to use either \renew… or \provide…, or you get an error. This may or may not be a benefit.

Unofficial LaTeX2e reference manual