Defining commands

In LaTeX, you can define a new command, override an existing command or, in LaTeX2e only, provide a new command if it doesn’t already exist, using the following commands:

  • newcommand{cmd}[args][opt]{def}
  • renewcommand{cmd}[args][opt]{def}
  • providecommand{cmd}[args][opt]{def} – LaTeX2e

The arguments of these are as follows:

The name of the new or redefined command. A followed by a string of lower and/or uppercase letters or a followed by a single nonletter. For newcommand the name must not be already defined and must not begin with end; for renewcommand it must already be defined. The providecommand command is identical to the newcommand command if a command with this name does not exist; if it does already exist, the providecommand does nothing and the old definition remains in effect.
An integer from 1 to 9 denoting the number of arguments of the command being defined. The default is for the command to have no arguments.
opt (LaTeX2e only)
If present, then the first of the number of arguments specified by args is optional with a default value of opt; if absent, then all of the arguments are required.

The text to be substituted for every occurrence of cmd; a parameter of the form #n in cmd is replaced by the text of the nth argument when this substitution takes place.

For example:

% Write a macro

Renewing the command overwrites the behaviour of a previously defined command. If you attempt to renew a command that hasn’t been defined yet, you will get an error.

% Redefine the macro

If you provide a command, the command is created if it doesn’t already exist. If the command does already exist, there will be no effect. The original command’s behaviour will not be affected.

% Provide a macro

Leave a comment

What do you have to say about this?

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: