Your support for our advertisers helps cover the cost of hosting, research, and maintenance of this document

Formatting information — An introduction to typesetting with LATEX

Chapter 7: Programmability

In this chapter…

  1. Simple replacement macros
  2. Macros using information gathered previously
  3. Macros with arguments
  4. Nested macros
  5. Macros and environments
  6. Reprogramming LATEX's internals

We've touched several times on the ability of LATEX to be reprogrammed. This is one of its central features, and one that still, after nearly a quarter of a century, puts it well above many other typesetting systems, even those with macro systems of their own. It's also the one that needs most foreknowledge, which is why this chapter is in this position.

LATEX is in fact itself just a collection of macros — rather a big collection — written in TEX's internal typesetting language. These macros are little program-like sets of instructions with a name which can be used as shorthand for an operation you wish to perform more than once.

Macros can be arbitrarily complex. Many of the ones used in the standard LATEX packages are several pages long, but as we will see, even short ones can very simply automate otherwise tedious chores and allow the author to concentrate on writing.

  1. If you move all this preamble into a style file of your own, you don't need these commands: the use of @ signs in command names is allowed in style and class files. 

  2. Don't try this at home alone, children! This one is safe enough, but you should strictly avoid \def for a couple of years. Stick to \newcommand for now.