Search Contact information
University of Cambridge Home Department of Engineering
University of Cambridge >  Engineering Department >  computing help >  LaTeX

Extending LaTeX

[Simple Macros] [Commands] [Environments] [Packages] [Classes] [See Also]

LaTeX lets you write new commands (or adapt old ones), create or adapt environments, and write your own packages and even classes. This document will give detailed descriptions on how to do simple things, but won't cover all the issues relating to class creation.

Simple Macros

Sometimes you might want to repeat a long expression. The tidy way to do this is to use \def (or \newcommand). The following defines \xdt to produce something like X.desktop
\def\xdt{$\cal X\!\!$\texttt{.desktop}}
One problem that can arise is that your new code can introduce unwanted space. The Spaces in macros section of the FAQ covers this issue.

Commands

Use \newcommand to create a command and \renewcommand to over-write an existing one. You can use only letters in the names of commands.

Environments

A new environment is slightly more difficult to create, because you can define what you want to happen on entering and leaving the environment.

\newenvironment{\ environmentname}[number of arguments][ default value of the 1st (optional) argument]{ entry code, using #1, #2 etc to denote arguments} { exit code - arguments can't be used}

Simple use isn't as painful as it looks - the following provides a variant of the itemize command, emphasising the items.

   \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.
produces The end of the environment ends the scope of the emphasis.

\renewenvironment is used to change existing environments, but you can't change the number of arguments an environment takes.

Packages

A package needn't have any special code, but usually it starts with some special package commands When writing a package you should try to minimize name-clashes Useful utilities from builting packages include

Classes

Creating a class file needs more work than package creation does. A class file can use many of the commands mentioned in the Packages section. In addition it can use

See Also

See for more details.
© Cambridge University Engineering Dept
Information provided by Tim Love (tpl)
Last updated: May 2007