# latex Basic definition of macros

## Define a new basic command

A macro can be defined using `\newcommand`. For example:

``````\newcommand{\foo}{Just foo, you see?}
``````

defines a macro `\foo` that expands to `Just foo, you see?`. It can then be used like any built-in command, for example after that definition:

``````He said: ``\foo''
``````

expands to

``````He said: ``Just foo, you see?''
``````

## Define a new command with arguments

Macros can also have arguments. The number of arguments is given as optional argument between the command name and the replacement text. In the replacement text, the arguments are accessed with `#1`, `#2` etc. For example:

``````\newcommand{\better}[2]{A #1 is better than a #2.}
\better{solution}{problem} % gives: A solution is better than a problem
``````

## Redefining an existing command


``````\renewcommand{\foo}{Another foo, please.}
``````

After that redefinition, the macro `\foo` no longer expands to `Just foo, you see?` but to `Another foo, please.`