


-

No, it is not correct.

\newcommand defines a new command, and makes an error if it is already defined.

\renewcommand redefines a predefined command, and makes an error if it is not yet defined.

\providecommand defines a new command if it isn't already defined.

If you want to define a command whether it is new or predefined, you can use \def or

\providecommand\foo{}
\renewcommand\foo{...}

-
I never knew what to do with \providecommand or how to do this unconditional definition in LaTeX-style code. Thanks! –  Ryan Reich Nov 25 '11 at 21:11

They have all in common, that they define a new command, but the precondition and behavior differs a bit:

• \renewcommand works only if the command is already defined: it's a redefinition

• \newcommand doesn't work if the command is already defined: so it's a completely new definition

• \providecommand works like \newcommand, but if the command is already defined, the (re)definition is ignored


\providecommand may be helpful, if the same code would be used in several documents. If you would use it, you should be aware that it might have no effect. But using it you can avoid compile time errors.

For all commands exists a starred version. To see the difference, have a look at:

If you really don't want error checking, you could use \def, see:

-

The idea is to prevent an accidental overwriting of commands by a not so knowledgeable user.

1. \newcommand defines a new command and gives an error if the command already exists. It does not overwrite an existing command.

2. \renewcommand overwrites an existing command and gives an error if the command does not already exist.

3. \providecommand defines a new command if the command with this name does not exist, or does nothing if it exists.

Exercise: use \providecommand and \renewcommand to define a command which may either exist or not.

-
Leo Liu's answer already contains the solution to your exercise. –  Gonzalo Medina Nov 25 '11 at 19:34
@GonzaloMedina We wrote our texts simulatenously :) –  Boris Nov 25 '11 at 20:51