Back to: Class 9

LaTeX packages

LaTeX is a programming language, so users can make extensions. Even if you cannot find the time and energy to write LaTeX code, you can still benefit from the extensibility of LaTeX because many users have contributed their work to the Comprehensive TeX Archive Network (CTAN), where you can find many packages that do things you would like to do in LaTeX, and even more packages that do things that you never thought of doing. Here are some examples of how to locate, download, install, and use a few of these packages.

Suppose that you would like a package to help with composing examinations. If you go to the LaTeX online catalogue www.tex.ac.uk/tex-archive/help/Catalogue/catalogue.html then you will see three CTAN subdirectories that look promising: exam (a package by Philip Hirschhorn),  examdesign (a package by Jason Alexander), and exams (a package by Hans van der Meer). 

The first package is the easiest to use of the three. To download this package, go to the exam directory and download the files exam.cls and examdoc.tex. For the download you can probably grab a file with your World-Wide Web browser by holding down the Shift key while you click the left mouse button on the name of the file (or, if you are using a mouse with multiple keys, try right-click).

The file exam.cls is a LaTeX class file: a set of macros that LaTeX implements if you start your source file with \documentclass{exam} instead of starting with \documentclass{article}. The file examdoc.tex is documentation about how to use this new document class. Execute the command latex examdoc (two or three times, until you stop getting messages about running latex again), and then either view the documentation on screen via xdvi examdoc &, or run dvips examdoc, which should print the resulting PostScript file to your default printer unless you pick another printer, say prnxxx, and run the command dvips examdoc -Pprnxxx.


Exercise: Typeset a quiz

Make up and typeset a quiz for a high school algebra class. Use some of the features of the exam document class, as illustrated in the sample quiz.


One of the interesting features of the sample quiz is the fancy formatting of headers and footers. This functionality is available independently of the exam package in a separate package, fancyhdr, written by Piet van Oostrum. To use the fancyhdr package, download the files in the CTAN directory from the TeX Catalog Online.. This package consists of a style file fancyhdr.sty rather than a class file, so you can use it with any document class by putting the command \usepackage{fancyhdr} in the preamble of your LaTeX source file. You can learn how to use the package by reading the documentation.

The exam class in Jason Alexander's examdesign package has some features not present in Philip Hirschhorn's package. For example, Jason Alexander's exam class has special environments for fill-in-the-blank questions, for short-answer questions, for true-false questions, and for multiple-choice questions. It also binds answers to questions so that an examination and a matching answer key can easily be generated from the same source file. It addition, it allows for automated randomizing of the order of the questions, so that you can produce multiple forms of the same exam.

The examdesign package is distributed via a method common to the more elaborate LaTeX packages. The essential files are exam.dtx and exam.ins. If you run the command latex exam.ins, then the class file exam.cls will be created automatically from the file exam.dtx. On the other hand, if you run the command latex exam.dtx, then you will get documentation for the package.

If you are going to experiment with both of these exam packages, then you had better keep them in different directories so that they do not conflict with each other.

You could have found these packages yourself by browsing the LaTeX online catalogue. On the home page of the catalogue, you will find links to mirror sites; selecting the closest site may speed up your access. Click on Alphabetic Index and select the letter E to look for exam packages.


Exercise: Typesetting URLs

Locate and download Donald Arseneau's  package url.sty. Use it to typeset a paragraph that describes your five favorite URLs.



Exercise: Watermarks

It is sometimes useful to put a background image on each page of a document. For example, you might mark preliminary versions of a memorandum with the word DRAFT in large letters. This is easy to do if you are using a PostScript printer.

Locate and download Juergen Vollmer's draftcopy package, and install it by executing the command latex draftcopy.ins in a terminal window. Use the package to typeset your "Completing the Square" LaTeX document.



Exercise: Wrapping text around graphics

In an earlier section we saw how to insert graphics in a LaTeX document by using the standard graphics package. Several packages are available to flow text around included graphics: wrapfig.sty, floatflt.sty, and picins.sty. The package recommended by Piet van Oostrum is picins.sty.

Locate and download the picins package. (On a Unix system, you may need to delete a spurious ^Z at the end of the file picins.sty.) Then use the package to reproduce the typesetting in the online example.