CERN Accelerating science

This website is no longer maintained. Its content may be obsolete. Please visit for current CERN information.

next up previous
Next: Defining New Environments Up: LaTeXeAn Overview Previous: Defining new commands

Defining commands

Commands are defined or redefined in LaTeX with:

     command definition  [1mm]
     command definition  [1mm]
     command definition

The first and second commands show enhancements with respect to LaTeX 2.09 by providing the possibility to have an optional argument when (re)defining a user command. The presence of such an optional parameter is flagged by the presence of the second optional argument default, which specifies the default value of that argument when it is not specified explicitly when the command is used. The last form is useful for general purpose files that are included in a document and over which the user does not always have control (eg. databases). If \mycom is not yet defined, the \providecommand will act as \newcommand and define it, otherwise the existing definition is kept.

The number of arguments, which includes the optional argument, is in the range 0\(\le\)\Larg{narg ( )9}. If the command has no arguments, then the [0] can be omitted. Inside the command definition part, the arguments are referenced as #1 to #\Larg{narg}, the optional argument, if present, being the first one.

For example, compare the following commands, with no, one mandatory, one optional, and one optional and one mandatory argument, allowing the user more freedom in each case.


If a command should work both in math and in text mode, special care should be taken in its definition. In LaTeXe you have the following command:

\ensuremath{math code}

As its name implies ensuremath ensures that its argument is always typeset in math mode by surrounding it if necessary with $ signs. For instance, the above can be rewritten as:

\seq,\quad\seqm{z} or $\seq,\quad\seqm{z}$

Janne Saarela
Wed May 17 14:38:58 METDST 1995