Next: , Previous: , Up: Definitions   [Contents][Index]


12.2 \providecommand

Synopses, one of:

\providecommand{\cmd}{defn}
\providecommand{\cmd}[nargs]{defn}
\providecommand{\cmd}[nargs][optargdefault]{defn}
\providecommand*{\cmd}{defn}
\providecommand*{\cmd}[nargs]{defn}
\providecommand*{\cmd}[nargs][optargdefault]{defn}

Defines a command, as long as no command of this name already exists. If no command of this name already exists then this has the same effect as \newcommand. If a command of this name already exists then this definition does nothing. This is particularly useful in a file that may be loaded more than once, such as a style file. See \newcommand & \renewcommand, for the description of the arguments.

This example

\providecommand{\myaffiliation}{Saint Michael's College}
\providecommand{\myaffiliation}{Lyc\'ee Henri IV}
From \myaffiliation.

outputs ‘From Saint Michael's College.’. Unlike \newcommand, the repeated use of \providecommand to (try to) define \myaffiliation does not give an error.


Unofficial LaTeX2e reference manual