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 3: Packages and CTAN

Section 3.1: Packages and classes

Add-on (plug-in) features for LATEX are known as packages. Most of them can be used with any document class, to add extra formatting features. There over 5,000 packages, and several hundred of them are pre-installed with a full distribution of LATEX and can be used in your documents immediately. They are all stored in subdirectories of your TEX installation directory, named after each package. To find out what packages are available and what they do, you should use the CTAN search page which includes a link to Graham Williams’ comprehensive package catalogue. There are two main types of package:


A LATEX package is a file or collection of files containing extra commands and programming which add new formatting features, or modify those already existing. Installed package files all end with .sty (they used to be called ‘style files’) and they may also contain ancillary files as well like fonts or configurations files.


A LATEX class is a special kind of package which provides formatting template features for a whole document. There are many of these, and several dozen of them are pre-installed with LATEX. Class files all end with .cls and additional classes can also be downloaded from CTAN.

When you try to typeset a document which requires a package which is not installed on your system, LATEX will warn you with an error message that it is missing (see § C.3.3.7), and you can then download the package and install it using the instructions in § 3.2.

However, many TEX distributions can now catch this error, and offer to download and install the missing class or package for you right there and then, and then carry on typesetting. This feature, the TEX Live Package Manager (tlmgr), is not yet available in all distributions of LATEX, so check your documentation to see if it is working in your version. This useful facility avoids you having to do manual package installation except for a few packages that are very old or do not conform to the TDS standard (see § 3.2.1).

You can also download updates to packages you already have, both the ones that were installed along with your version of LATEX as well as ones you have added. Updates occur when a class or package author finds and fixes a bug, or adds a new feature. All package updates on CTAN are automatically announced on the Usenet newsgroup news:comp.text.tex. See § 3.2 for details of how to install packages and updates.

There is no limit to the number of packages you can have installed on your computer (apart from disk space!), but there is probably a physical limit to the number that can be used inside any one LATEX document at the same time, although it depends on how big each package is. In practice there is no problem in having even a couple of dozen packages active (this document uses over 30).

3.1.1 Using an existing class

We’ve already seen how to do this in § 2.1.1: it’s the document class name that you put in curly braces in the \documentclass line at the start of a LATEX document.

All classes have options (we saw some in use in the Quick Start document). The class documentation will explain what they are for and how to use them.

3.1.2 Using an existing package

To use a package already installed on your system, put a \usepackage command in your document Preamble with the package name in curly braces, as we have already seen in earlier chapters. For example, to use the xcolor package, which lets you typeset in colours (I warned you this was coming!), you would type:


This makes available a \color command and many others, and several sets of predefined palettes of colours which you can specify using options.

You can include several package names in one \usepackage command by separating the names with commas, and you can have more than one \usepackage command.

If you use the package options, you must give the package its own separate \usepackage command, like geometry and xcolor shown below:

\title{\color{Crimson}Practical Typesetting}
\author{\color{StateBlue}Peter Flynn\\Silmaril Consultants}
\date{\color{ForestGreen}January 2016}

(Incidentally, don’t actually do this: it’s a very crude and cumbersome way to do colours in titling. It’s fine for a one-time short document, but it will interfere with running heads if you use them; and if it’s for a repeatable style we’ll see in Chapter 7 ‘Programmability’ how it can be automated as part of the \maketitle command and kept out of the author’s way.)

Exercise 8: Add colour

Use the xcolor package to add some colour to your document. Stick with primary colours for the moment.

Use the geometry package to change the margins.

Reprocess and print your document if you have a colour printer (monochrome printers should print it in shades of grey).

The geometry package has options to let you specify margins, page and paper sizes, header and footer depths, and a lot of other page-geometry dimensions. The xcolor package has options to let you specify which of several standard palettes of colours you want to use.

It’s really important to read the documentation for the package concerned to find out what can be done and how to do it: see § 3.1.3 up next.

3.1.3 Package documentation

To find out what commands a package provides (and thus how to use it), you need to read the documentation. The simplest way is to use your command window and type texdoc followed by the package name. This will bring up the documentation in your PDF or DVI viewer. Alternatively, use your system’s file finder to look for the package name — it should turn up the package directory itself as well as the documentation directory — what you’re looking for is a PDF or DVI document.

If that doesn’t find it, in the texmf/doc directory of your installation there should be subdirectories full of .dvi and .pdf files, one for every package installed. These can be previewed or printed like any other DVI or PDF file (see § C.4.1). If your installation procedure has not installed the documentation, the files can all be viewed or downloaded from the package’s page on CTAN — followed by the package name.

Before using a package, you should read the documentation carefully, especially the subsection usually called ‘User Interface’, which describes the commands the package makes available. You cannot just guess and hope it will work: you have to read it and find out.

See the next section for details of how to generate the documentation for additional packages you install yourself.

Exercise 9: Read all about it

Find and view (or print) the documentation on the geometry package you used in the example ‘Add colour’.

Investigate some of the other package documentation files in the directory.