LaTeX Macros

One can create new "commands" for combinations that are used often.
These are called macros. The format is as follows (the brackets are essential):
\newcommand{\name}[no_of_parameters]{defn_of_command}
One can have a macro whose first argument is optional (note: when the first argument is specified, it has to be enclosed in square brackets):
\newcommand{\name}[no_of_parameters][default_1st_variable]{defn_of_command}

When the macro is invoked (with all its parameters specified), it is replaced by its definition, after the parameters are substituted with the specified values.

If the number of parameters is zero, the argument [no_of_parameters] can be omitted, or used as [0].
There can be at most 9 parameters. They are referred to in the definition of command by #1, #2,..., #9.

To redefine an already existing command, one has to use \renewcommand.
The command \providecommand defines the command only if it does not already exist; otherwise, it does not change its meaning.

Here are a few examples:

\newcommand{\R}{{\mathbb R}}
\renewcommand{\vector}[1]{(x_1,x_2,\ldots,x_{#1})}
\newcommand{\avector}[2]{(#1_1,#1_2,\ldots,#1_{#2})}
\newcommand{\aDEFvector}[2][a]{(#1_1,#1_2,\ldots,#1_{#2})}
Remarks:
Here is a piece of LaTeX code using them:
\documentclass{article} \usepackage{amssymb,amsmath} \newcommand{\R}{{\mathbb R}} \renewcommand{\vector}[1]{(x_1,x_2,\ldots,x_{#1})} \newcommand{\avector}[2]{(#1_1,#1_2,\ldots,#1_{#2})} \newcommand{\aDEFvector}[2][a]{(#1_1,#1_2,\ldots,#1_{#2})} \begin{document} Consider the following vectors with entries in $\R$: $\mathbf x=\vector{6}$, $\mathbf u=\avector{u}{7}$, $\mathbf a=\aDEFvector{8}$, $\mathbf w=\aDEFvector[w]{n+1}$. \end{document}
and the approximate way it would look:
Consider the following vectors with entries in R: x=(x1, x2, ... ,x6), u=(u1, u2, ... , u7), a=(a1, a2, ... , a8), w=(w1, w2, ... , wn+1).