Department of Engineering

Next: Packages Up: Customising Previous: Modifications

## New Commands

A completely new command can be created using

\newcommand{\ commandname}[number of arguments]{ command text, using #1, #2 etc to denote arguments}

For example,

\newcommand{\ve}[1]{$$#1_1 ... #1_n$$}
\ve{x}

produces as output x1 ... xn

A problem with this example is that it shouldn't change to math mode if LATEX is already in that mode. A better try would be

\newcommand{\ve}[1]{\ensuremath{#1_1 ... #1_n}}

which will only change to math mode if it's necessary.

A new environment is just as easily created - give the name of the environment, and what you want to happen on entering and leaving the environment. The following provides a variant of the itemize command.

\newenvironment{emlist}{\begin{itemize} \em}{\end{itemize}}
\begin{emlist}
\item first comment
\item second comment
\end{emlist}
The end of the environment ends the scope of the emphasis.

• first comment
• second comment
The end of the environment ends the scope of the emphasis.

 | computing help |