Access Keys:

# How can I define new commands in LaTeX?

If you find yourself needing to use a particular bit of text (with or without LaTeX commands) in your document multiple times, it may be convenient for you to define it as a command, using \newcommand. For example, if you were tired of typing the commands for a degree symbol, you might do

   \newcommand{\dg}{$^\circ$ }


and then in your text, you could say

   At 10 in the morning, it was 68\dg outside


and LaTeX would automatically substitute "\$^\circ " to make a degree symbol where you had typed \dg.

Next, you can create commands which include arguments, by including a field for the number of arguments in your \newcommand line, and putting the arguments themselves in as #1, #2, and so on. For example, if you were creating a description list and you wanted each of them to have the item itself to be in bold and the rest to be in italics, like so

   \begin{description}
\item[\bf Elephant] {\em A big grey animal with a trunk}
\item[\bf Zebra] {\em A stripey looking horse}
\end{description}


then you could use a \newcommand for that:

   \newcommand{\animal}[2]{\item[\bf #1] {\em #2}}

\begin{description}
\animal{Elephant}{A big grey animal with a trunk}
\animal{Zebra}{A stripey looking horse}
\end{description}


## IS&T Contributions

#### Documentation and information provided by IS&T staff members →

February 25, 2009

### Get Help

Request help
from the Help Desk
Report a security incident
to the Security Team
Labels:
olc-latex olc-latex Delete