next up previous contents
Next: Moving arguments Up: Commands for class and Previous: Reporting errors, etc   Contents


Defining commands

LATEX2e provides some extra methods of (re)defining commands that are intended for use in class and package files.

The *-forms of these commands should be used to define commands that are not, in TEX terms, long. This can be useful for error-trapping with commands whose arguments are not intended to contain whole paragraphs of text.


\DeclareRobustCommand {<cmd>} [<num>] [<default>] {<definition>}
\DeclareRobustCommand* {<cmd>} [<num>] [<default>] {<definition>}

This command takes the same arguments as \newcommand but it declares a robust command, even if some code within the<definition> is fragile. You can use this command to define new robust commands, or to redefine existing commands and make them robust. A log is put into the transcript file if a command is redefined.

For example, if \seq is defined as follows:

   \DeclareRobustCommand{\seq}[2][n]{%
     \ifmmode
       #1_{1}\ldots#1_{#2}%
     \else
       \PackageWarning{fred}{You can't use \protect\seq\space in text}%
     \fi
   }
Then the command \seq can be used in moving arguments, even though \ifmmode cannot, for example:
   \section{Stuff about sequences $\seq{x}$}

Note also that there is no need to put a \relax before the \ifmmode at the beginning of the definition; this is because the protection given by this \relax against expansion at the wrong time will be provided internally.


\CheckCommand {<cmd>} [<num>] [<default>] {<definition>}
\CheckCommand* {<cmd>} [<num>] [<default>] {<definition>}

This takes the same arguments as \newcommand but, rather than define <cmd>, it just checks that the current definition of <cmd> is exactly as given by <definition>. An error is raised if these definitions differ.

This command is useful for checking the state of the system before your package starts altering the definitions of commands. It allows you to check, in particular, that no other package has redefined the same command.


next up previous contents
Next: Moving arguments Up: Commands for class and Previous: Reporting errors, etc   Contents
Johannes L. Braams 2003-05-18