Four steps to better LaTeX documents

June 30th, 2008  |  Published in Computing  |  5 Comments

Here are some simple things you can do to make your LaTeX documents more attractive and functional. (Updated May 2009; now there are more than four suggestions.)

Use pdflatex

The target of your document is either a printer or a file. In either case, you will probably want some way to turn your TeX source into a PDF document. You can do this in several ways: using dvipdf, using Adobe Distiller, or using a fake printer driver. Each of these, though, is sort of a pain. If you use the pdflatex TeX driver, which is a standard part of modern TeX distributions, you’ll get much better results.

pdflatex is almost completely compatible with documents that are acceptable to standard latex, with one important exception: all of your included graphics will need to be PDF files. This isn’t really a drawback, though, since a PDF is much more likely to be free of the sort of bounding-box and font drama that can often plague EPS figures.

You can use the ifpdf package to conditionally execute code when running under pdflatex or otherwise:


\usepackage{ifpdf}

\ifpdf
\usepackage[pdftex]{graphicx}
\else
\usepackage{graphicx}
\fi

Use the microtype package for better typography

Now that you’re using pdfTeX, you have access to better typography. pdfTeX provides features to help ensure that optical margins appear straight, that the typographic color of your text is more uniform, and that unattractive “rivers” are kept to a minimum. The microtype package, which you may already have installed, provides a convenient interface to these features. These options are suitable for set-it-and-forget-it use:


\usepackage[protrusion=true,expansion=true]{microtype}

Even using the defaults buys you a great deal. As a small example of one feature, see the following detail from a document that uses microtype:

Example of character protrusion

Note how the commas and periods extend somewhat into the right margin. This actually helps to make the margin look less ragged than if they were aligned strictly to the left of the right margin. The microtype package can give you a great deal more control over micro-typographic features; see its copious documentation for details.

Use otfinst.py to take advantage of your OpenType faces

As a longtime LaTeX user and as a longer-time reader of technical literature, I approach the Computer Modern Roman fonts with fond nostalgia — it’s hard for me to see them without recalling classics like The Little Schemer or EOPL.

There are faces that are rather nicer, if you’re not targeting an audience with a similar nostalgia profile to mine. Unfortunately, many of them aren’t immediately usable with LaTeX. In particular, it’s not immediately apparent how to use OpenType fonts in your LaTeX documents — and reading about how to do convert and install one’s OpenType fonts will likely give even experienced LaTeX hackers nightmares about strange creatures like “.fd,” “.tfm,” and the dreaded “kpathsea.”

John Owens at UC Davis has a very nice script called otfinst.py that automates the whole process of converting PostScript-flavored OpenType fonts to metric and outline files that LaTeX can use and then installing these and other support files. It’s very easy to use — to install Minion Pro, for example, you’d need only to type:


otfinst.py Minion*.otf

in a shell window and then include the following line in your document:


\usepackage{minion}

I’ve used it successfully to convert many Adobe faces, including Minion, Myriad, Cronos, Warnock, Kepler, Arno Pro (used in the above example), and Garamond Premier Pro. It also works out-of-the-box with some FF typefaces. I haven’t licensed any for-pay FF faces, but I did successfully convert FF Mt to use as a small-caps logo face.

(If you don’t have any decent OpenType faces, you might poke around and see if you prefer the standard garamond or palatino packages to CMR. These aren’t as nice as a “real” Palatino or Garamond, but they’re rather nicer than CMR.)

Use svn-multi for a LaTeX interface to Subversion keywords

You should keep your documents under version control.

If you do, and you use Subversion, then you should install the svn-multi package, which provides a nice interface to access svn keywords from LaTeX documents that span multiple files. Mark Eli Kalderon at University College London wrote a nice article showing how to use svn-multi.

When I’m drafting a document and getting external feedback, I find it especially convenient to be able to include revision numbers with file names in page footers. This way, I can see what revision a hardcopy comes from — and then use latexdiff-svn to compare its contents to those of the current version.

Use vc with other version control systems

If you don’t use Subversion, you won’t be able to use svn-multi. However, you still might want to include version control information in your documents. The vc package is more flexible than svn-multi but is a little more difficult to set up: you’ll have to incorporate a preprocessing step into a makefile or invoke a script from within your documents. vc allows including version control metadata in documents controlled in bzr, Subversion, and git, which is the system that I currently prefer. git support is especially notable because git does not support keyword expansion.

Typeset better tables

Thanks to Nate Rosenblum for a pointer to the booktabs package. Essentially, this package makes it possible and easy to set tables properly. The documentation includes several standard tables contrasted with the results possible with booktabs as well as a discussion of some of the rules for typesetting tables. As an example, here is a table from my VMCAI 2009 paper:

example table

Responses

  1. Thomas says:

    September 5th, 2008 at 6:25 am (#)

    Awesome info!
    Thanks a lot!!

  2. KG says:

    August 29th, 2009 at 9:20 pm (#)

    Thanks 🙂

  3. Jim Pudar says:

    September 10th, 2009 at 5:39 pm (#)

    Hello, thanks for the article! I have been trying to figure out how to convert Adobe Garamond Pro from opentype for a long time, and have had no luck with anything.

    I am using MiKTeX in windows, and have no clue at all what to do with otfinst.py.

    Is there an easy place to start? How do I install it at all?

    Any help would be greatly appreciated!

    jimpudar@gmail.com

  4. Johannes Braunias says:

    July 12th, 2011 at 3:51 am (#)

    The URL for Microtype has changed to http://www.ctan.org/pkg/microtype

  5. wb says:

    July 12th, 2011 at 6:49 am (#)

    Thanks; I’ve updated the post.

Leave a Response