## Quality fonts

The other day on Digg I saw a link for 30 high-quality free fonts for professional designs. Many of the samples seem decent, but I guess it sparked the question in my mind of just what constitutes a "high-quality font".

I suppose when I think of a a quality font, I tend to expect a consistent design along with some of the following:

• composing characters or glyphs for most diacritical marks, ideally Greek and Cyrillic glyphs as well
• proper kerning
• appropriate ligatures
• old-style numbers
• optical sizes

Given these criterion, offhand I have to say that perhaps the best high-quality free fonts that I can think of off the top of my head are probably the TeX Gyre fonts and the Latin Modern family.  I would be curious to hear about other recommendations.

## Fonts in LaTeX, Part Three: pdfTeX and TrueType

Update: The information in this post is out of date: otftotfm does presently have support for TrueType outlines. See my errata post for more information.

In the previous part of this tutorial, I explained how to put together the minimal infrastructure needed to use an OpenType font with pdfLaTeX.  However, I used the tool otftotfm to generate the font metrics TeX needs to lay out text. However, otftotfm only supports OpenType fonts that use PostScript font outlines, as opposed to TrueType font outlines. So in this part of the tutorial I will explain how to put together the necessary infrastructure for TrueType fonts. In preparation for that, we will first make a few changes to what we had done earlier.

For those that would find it useful, I've put together a  zip file containing all the files from the tutorials (except the fonts, which I don't want to deal with distributing).

Firstly, we are going to move the uses of \DeclareUnicodeCharacter out of UPagella.fd and into uenc.def:

 \ProvidesFile{uenc.def}% We are declaring an encoding named "U"\DeclareFontEncoding{U}{}{} % Technically these are not "allowed" in .def files,% but this is really the logical place to put the% declarations. % τ (0x03C4) maps to 0xF8 in the encoding\DeclareUnicodeCharacter{03C4}{\char"F8}% ε (0x03B5) maps to 0xF9 in the encoding\DeclareUnicodeCharacter{03B5}{\char"F9}% χ (0x03C7) maps to 0xFA in the encoding\DeclareUnicodeCharacter{03C7}{\char"FA}

As I mention in the comments, the documentation on font encoding definition files does not list \DeclareUnicodeCharacter to be one of the allowed declarations in a such a file, but it works, and it seems like the more logical place to configure it than in the font definition file.

Now that we have removed the uses of \DeclareUnicodeCharacter from UPagella.fd, it looks like:

 \ProvidesFile{UPagella.fd} % Delcaring a font family called "Pagella" for the encoding "U"\DeclareFontFamily{U}{Pagella}{} % Declare that font family "Pagella", for encoding "U", has a shape% with weight medium (m) and normal (n) slant (in otherwords, upright)\DeclareFontShape{U}{Pagella}{m}{n}{  % For all sizes...  <->  % ... use the font named  TeXGyrePagella-Regular--custom--base}{}

I am going to use Deja Vu Sans as the example TrueType font. Fortunately, if you followed everything from the second part of the tutorial, there is not much that needs to be done.

First, we need to generate metrics for Deja Vu Sans. As before, if you are using TeX Live, you'll have the necessary program:

% ttf2tfm DejaVuSans.ttf -q -T custom
ttf2tfm: WARNING: Cannot find character compwordmark'
specified in input encoding.
...
...
ttf2tfm: WARNING: Cannot find character zdotaccent'
specified in input encoding.
DejaVuSans   DejaVuSans.ttf Encoding=custom.enc

The program ttf2tfm is kind of unusual in that it first takes the filename argument and then all the options. So we've passed it the TrueType font we want to generate metrics for, DejaVuSans.ttf, the option -q to tell it not to print quite so much information, and the option -T custom which tells it to use the encoding defined in the file custom.enc we created in previous part.

Unlike otftotfm, ttf2tfm does not generate an entry that we could use in our map file, custom.map, so we need to write one ourselves. You will want to start with the map we generated by otftotfm for Tex Gyre Pagella, and you will want to add the line:

DejaVuSans <custom.enc <DejaVuSans.ttf

This says to map the TeX font name DejaVuSans to the file DejaVuSans.ttf using the encoding custom.enc. To learn more about the format of map files, there is a section on them in the pdfTeX manual.

Now we just need to create a font definition file for Deja Vu Sans. However, it is essentially the same as the one we created for TeX Gyre Pagella:

 \ProvidesFile{UDejaVuSans.fd} % Delcaring a font family called "DejaVuSans" for the encoding "U"\DeclareFontFamily{U}{DejaVuSans}{} % Declare that font family "DejaVuSans", for encoding "U", has a shape% with weight medium (m) and normal (n) slant (in otherwords, upright)\DeclareFontShape{U}{DejaVuSans}{m}{n}{  % For all sizes...  <->  % ... use the font named  DejaVuSans}{}

We have just replaced all occurrences of Pagella with DejaVuSans.

Finally, we just need to update our example document to use Deja Vu Sans:


Here we have used \renewcommand to set the default sans serif font, \sfdefault, to be DejaVuSans. In the body of the document, we've copied the text and surrounded it with the sffamily environment to have it typeset in sans serif.

Now we have everything we need to run pdflatex:

% pdflatex test-pdflatex.tex
This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
%&-line parsing enabled.
...
...
(./test-pdflatex.aux) (./upagella.fd) (./udejavusans.fd) [1]
(./test-pdflatex.aux) ){custom.enc}{a_qnnnfc.enc}<./TeXGyrePage
lla-Regular.pfb>
Output written on test-pdflatex.pdf (1 page, 34857 bytes).
Transcript written on test-pdflatex.log.

And we have the desired output:

And that's everything you need to get started with TrueType fonts and pdfLaTeX. Again, if you encounter any problems or notice any omissions, let me kow. I'll do some investigation and there will possibly be a fourth part on using fontinst.

## Fonts in LaTeX, Part One: XeLaTeX

Now and then I get asked about how to use some TrueType or OpenType font with LaTeX, so I figured I would take the time to write up some simple tutorials on how to do so. The first part will focus on the easiest route to making use of TrueType and OpenType fonts in LaTeX: XeTeX and XeLaTeX.

XeLaTeX also has the advantage of not only giving easy access to modern fonts, but also accepting Unicode input files.

The first thing you need to do is find out if you have XeLaTeX installed, and if it is a sufficiently up to date version. This is easiest to do from the command-line:
 % xelatex This is XeTeXk, Version 3.141592-2.2-0.996 (Web2C 7.5.6) %&-line parsing enabled. **^C 
This is the version that I am using for the tutorial, and is what comes with TeX Live 2007. I highly recommend just installing and using the entire TeX Live CD/DVD, even if you're using a Linux system that offers TeX Live packages, because, in particular for Debian/Ubuntu, I've found that the default installation often doesn't install some important packages, and it can be a pain sort through all the available packages using Synaptics or whatnot to find what it didn't install.

I am also assuming that you are using a (modern) Unix or MacOS X system. I assume that most of this material should also apply when using Windows, but if someone can comment, let me know.

Now, as an example, say you want to use the Pagella font from the TeX Gyre project. First download them and install the fonts (the otf files) as you normally would on your computer. Under MacOS X, this means using Font Book. If you double-click on an otf file it will load Font Book for you and there will be dialog with a button to install the font. If you load Font Book yourself, you can use the "Add Fonts..." menu item under the File menu to select the files. Under a modern Unix, I would recommend just placing the otf files in your ~/.fonts folder, though I think file managers like Nautilus also understand how to install fonts.

And that was all the installation work necessary; as I said, XeLaTeX is the easiest solution unless you have specialized needs. Now just create a small LaTeX document:

 \documentclass{article}\usepackage{fontspec}\setromanfont{TeX Gyre Pagella}\begin{document}Testing XeLaTeX! Greek: τεχ.\end{document}

The fontspec package isn't necessary, but it makes dealing with fonts in XeLaTeX much easier, for example it defines the convenient \setromanfont command. You can learn more about all of its great features from its beautifully formatted manual.

The other thing you might need to know is what XeLaTeX thinks your font is called. If you're using TeX Live, like I suggest, you will have the program otfinfo at your disposal that can do that for you:
 % otfinfo --family texgyrepagella-regular.otf TeX Gyre Pagella 
Note that despite its name, otfinfo will also work on ttf files, assuming that they include OpenType data in them. The other option is to use Font Book on MacOS X or fc-list from the command-line in Unix.

Now you just run xelatex:
 % xelatex test.tex This is XeTeXk, Version 3.141592-2.2-0.996 (Web2C 7.5.6) %&-line parsing enabled. entering extended mode (./test.tex ... ... Output written on test.pdf (1 page). Transcript written on test.log. 

I think that is about everything you need to know, but if you try this tutorial out and find that something doesn't work, let me know.  If you have more specialized or demanding typographical needs, you may want to use pdfTeX and pdfLaTeX, and part two of the tutorial will explain how to do the necessary configuration to use TrueType and OpenType fonts with them.

## Font identification

I've mentioned Identifont in the past, but I was just thinking that I should point out the existence of
WhatTheFont, a tool that will identify a font for you from an image. If failed to identify anything useful for the EPFL logo, but I doubt that corresponds to a real font. From a screen capture, it did correctly identify that the ∃xistential Type header at the top of the page is made from a member of the Warnock Pro family.

WhatTheFont was first brought to my attention on Daring Fireball.

## I’ve got a knack for it I guess

I discovered last night that Appendix B.4 of Fonts & Encodings is almost an exact copy of Appendix B.2, with a couple changes made, but overall the text is not appropriate to the expected content.  Appendix B.2 describes the OFM file format, and Appenidx B.4 the OVF format, but in B.4 most of the time it claims to be explaining OFM.  Given the size of the tome, I was not too surprised that this is not yet in the reported errata.

Despite everything the book covers I have also managed to find that one thing it does not really explain much about is the special font metrics used by TeX for typesetting mathematics.  They are named in the description of the TFM file format, but that seems to be the extent of the coverage.  In some sense this is partly okay, because the various TeX documentation explains what the parameters do.  The trouble is that I have yet to figure out how you can set them for existing fonts, short of hacking the TFM files generated by otftotfm or afm2tfm manually.  You might think this is something you could do with the TeX virtual font mechanism, but Fonts & Encodings specifically says that the metrics in a TFM file must match the virtual font because TeX only reads the TFM.

## Gentzen Symbol released

I just finished hastily packaging up a prototype release of Gentzen Symbol (I can't avoid working on my ICFP paper all day).  I would of course be interested in any feedback or problems people might have if they try using it, or suggestions on how to improve the design of the glyphs for future releases or development.

## Hands on with Fonts & Encodings (finally)

In September, I mentioned being quite excited by the new O'Reilly book Fonts & Encodings. Today, I was tempted to buy it from the campus bookstore at EPFL, but decided to do a little research because it would be nearly a 60% markup if I bought it here versus in the US. Fortunately, the EPFL library had purchased a copy which was not checked out.

Strangely, enough it is described as being translated from French by Scott Horne, but as far as I can tell there is no French edition (and if there is, I find it strange that the EPFL library and bookstore only had the English edition). Perhaps only the original manuscript by Yannis was in French.

I've only just begun to delve into it, at 1017 pages it will take some time to review it in depth, but if you are serious about typography I think this is a book that you will definitely want to own. It really covers the entire spectrum: Unicode text and how it works, through setting up fonts to display your text in operating systems and software, all the way to designing/editing/hinting fonts. I haven't looked at it in enough depth to be absolutely certain, but I am pretty sure it has nearly enough information on most formats that you could write software for them as well. It is truly a wondrous tome.

I will have to see what more I have to say once I've spent more time with it. One reason I thought of picking it up today was that it has quite a nice introduction to using METATYPE1, which with some luck I may use to start on a true meta-font for Gentzen Symbol. At the same time I guess I will try to package up the Type 1 PostScript version of Gentzen Symbol from my dissertation, assuming that there is anyone out there truly interested in using it in their own documents.

## New version of the DejaVu Sans Mono package

I just finished fixing the bugs Brian noted in the previous version.  You can grab it using darcs get from http://free-the-mallocs.com/repos/dejavu-sans-mono.  This version also includes support for the oblique members of the family.  These are accessed using \textsl{...} rather than \textit{...}.  If you try it out, let me know if you have any problems.