## Sunday, July 22, 2012

### Using all kinds of fonts in LaTeX (Part 1)

The reason I like using LaTeX is because of the beautiful PDFs that it produces. However, for a typesetting system that intends to be everything a typographer wants it to be, it's surprisingly difficult to use a variety of fonts and maintain strong control over the typography.

The LaTeX font catalogue (http://www.tug.dk/FontCatalogue/) is a great resource for fonts. All of the fonts listed there can be used by including packages in the preamble, which makes them very easy to include. However, the selection is a bit limited. Arial is available as a very close approximation to the ubiquitous Helvetica. But Arial/Helvetica is relatively thick. What if I want to use Helvetic Neue Light or Ultralight? As far as I know, I can't use a package for either of those. And if I'm serious about document design, I'll want access to display fonts for titles and headings. Unfortunately, the LaTeX font catalogue has a very poor selection of display fonts.

The next easiest way to get non-standard fonts into a document is to use XeTeX/XeLaTeX as the typesetting engine and the fontspec package. Fontspec lets you insert system fonts into your documents (and unfortunately, it's not compatible with pdfLaTeX). On a Mac, you can find your system fonts by looking into the "Font Book" application or by entering the following into the Terminal:

fc-list

Since you're going to get a lot of text in the output, you may want to pipe the results into a text file, for example:

fc-list > fontlist.txt

Any fonts that are listed in the output can be included in a TeX file with the following lines. I'll use Helvetica Neue Light as an example:

\usepackage{fontspec} % Provide features for AAT and OpenType fonts
\setmainfont{Helvetica Light} % Define the default font family

You can use macros other than \setmainfont. You could for example use \setsansfont{Helvetica Light} to make Helvetica Neue Light the default font for sans serif text.

And if you want to use a new font, you can simply install it on your system. For Mac OSX, at least, installing fonts is incredibly easy. You can go to a variety of websites to find and download new fonts to your computer [1]. Usually, they're in ZIP files, so you simply unzip the file and then double click on the font file, e.g. a *.ttf file or a *.otf file. It will open in Font Book, and then you can click the "Install Font" button to install it [source]. It's pretty straightforward.

So it seems like this solves the problem of getting different fonts into a TeX document, right? Well, yes, but there's an important disadvantage to using XeLaTeX to typeset your document: You can't use any of the features in the microtype package. The microtype package makes available several functions that typographers need, for example, control over kerning and inter-word spacing. (You can play around with inter-word spacing, for example, and quickly see how it changes the "feel" of the document.) Microtype also does protrusion, which makes your margins look straight to the human eye. And since all things are complicated in LaTeX, microtype is – of course – not compatible with XeLaTeX.

So if you want access to all the features in microtype, you'll need to use pdfLaTeX as the typesetting engine, and in this case, you can't use the fontspec package to include system fonts into the document. That means you'll need to install new fonts into your TeX system. I'll explain how to do that in the next blog post.

Notes
1. I haven't gotten that far into fonts, but Font Squirrel (http://www.fontsquirrel.com/) seems like a good resource. One thing to keep in mind is that fonts can be free for personal use but not for commercial use. Personally, I would prefer to use only unrestricted, free fonts, since some of my work is commercial, and I'm not sure what I'll be using my personal work for in the future.