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 is a great resource for fonts. All of the fonts listed there can be used by including packages in the preamble, so they’re very easy to use. However, the selection is a bit limited. Arial is available as a close approximation to the ubiquitous Helvetica. But Arial/Helvetica is relatively thick. What if you 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, too. 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 command in the Terminal:

fc-list

Because you’re going to get a lot of text in the output, you may want to pipe the results into a text file. You can use the following command to pipe the output into a plain-text file called fontlist.txt:

fc-list > fontlist.txt

Any font that is listed in the output can be included in a LaTeX document with the following code (in the document preamble). The example uses Helvetica Neue Light.

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

You can also set a sans-serif font and a monospaced font. For example, to set Helvetica Neue Light as the document’s sans-serif font, enter the following in the preamble of your LaTeX document:

\setsansfont{Helvetica Light} % 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 an *.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 LaTeX 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, such as control over kerning and inter-word spacing. (I recommend to play around with inter-word spacing, for example, to quickly see how it changes the “feel” of the document.) microtype also does protrusion, which makes documents’ margins appear straight to the human eye. And because all things are complicated in LaTeX, microtype is not compatible with XeLaTeX.

So if you want access to all the features in microtype, you need to use pdfLaTeX as the typesetting engine, and in this case, you can’t use the fontspec package to include system fonts in the document. As a result, you need to install new fonts in 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 seems like a good resource. Keep in mind that fonts can be free for personal use but not for commercial use. Personally, I would prefer to use only unrestricted, free fonts, because some of my work is commercial, and I’m not sure what I’ll be using my personal work for in the future.

No comments:

Post a Comment