Using a Truetype font in Pdflatex 

http://ipe.compgeom.org/pdftex_1.html

I'll explain the necessary steps for adding a TTF font using the Lucida-Handwriting font lhandw.ttf as an example (one can find this font on most PCs).

Note that there is an alternative route for making documents using Truetype fonts: You could convert the TTF font to Postscript Type 1 format, using the tool ttf2pfb. (The use of Postscript fonts is now quite standard in Tex, and you can use these fonts in ordinary Latex, with dvips as a postprocessor—you don't need Pdflatex.) The font conversion process converts the font outlines flawlessly, as TTF's quadratic Bezier splines can be converted exactly into Postscript cubic Bzier splines. Postscript and Truetype fonts use different hinting systems, though, and so hinting is not converted. This is fine as long as you plan to print the resulting document (printer resolutions are so good that hinting is irrelevant). But when the document is displayed on a screen in, say, Acrobat Reader, using the original TTF font seems to give a better result. For more information about Pdftex font handling, see the links on the TUG pdftex support page.

And then, it can be done, so why not? :-)

Checking the Pdftex version 

First, let's check the version of pdflatex:

mihoen[~].. pdflatex This is pdfTeX, Version 3.14159-13d (Web2C 7.3.1) **

So it appears that this RedHat distribution came with pdftex 0.13d, which is ancient. You need at least version 1.21a (see the Pdftex page to verify what the current version is).

It is not easy to only recompile/reinstall Pdftex because of the interdependencies of the various TeX components. Just update your installation of MikTeX/tetex using the official mechanism.

Providing the font metrics files 

We need to put the font where Pdflatex can find it. Let's try the current directory:

mihoen[~].. kpsewhich -progname=pdflatex lhandw.ttf
./lhandw.ttf

It seems Pdflatex can find it all right.

Now we have to create a TFM file (Tex metric file) for the font. I'm using ttf2tfm for this. This tool wasn't installed on my Linux system. You can probably find an rpm package that installs it on Linux, such as Suse's freetype-tools.rpm. If you use MikTeX 2.0, ttf2tfm is already there. I simply built it from sources.

I also copied the encoding file T1-WGL4.enc from the ttf2tfm package. (Here is a local copy.)

mihoen[~].. ttf2tfm lhandw.ttf -p T1-WGL4.enc

<...lots of output, listing all the characters, and complaining
about characters that haven't been found ...>

Using T1-WGL4.enc as input encoding.

lhandw   lhandw.ttf Encoding=T1-WGL4.enc

The last line output is meant to be put into the fontmap file. I'm not sure whether Pdflatex can handle this syntax — the one I've shown above works in any case.

For the moment, I just left the resulting file lhandw.tfm in the current directory. Check that Pdflatex will find it there:

mihoen[~].. kpsewhich -progname=pdftex lhandw.tfm
./lhandw.tfm

Setting up the Latex font 

Now we need to ask Latex to use the new font. Here is a little test file test.tex.

% File 'test.tex'
\documentclass{article}
\renewcommand{\encodingdefault}{T1}
\renewcommand{\rmdefault}{lhandw}
\renewcommand{\sfdefault}{phv}
\renewcommand{\ttdefault}{pcr}
\title{Using Lucida Handwriting}
\author{Otfried Cheong}
\begin{document}
\maketitle
This is just a---silly---test of the Lucida-Handwriting font.
\end{document}

This makes Lucida-Handwriting the default roman font (and uses Helvetica and Courier as sans-serif and typewriter fonts). If you just wished to use the Lucida font somewhere in your document, you could use the following:

\usefont{T1}{lhandw}{m}{n}

Or, more professionally, you would put this in the preamble:

\DeclareTextFontCommand{\textlh}
{\fontencoding{T1}\fontfamily{lhandw}\selectfont}

Running Pdflatex on test.tex succeeds, but shows this message:

LaTeX Font Warning: Font shape `T1/lhandw/m/n' undefined
(Font)              using `T1/cmr/m/n' instead on input line 8.

Pdflatex still doesn't know about the font. What is missing is a font description file. Latex is looking for the font "T1/lhandw/m/n", so this file has to be called t1lhandw.fd. I've created such a file in the current directory:

\ProvidesFile{t1lhandw.fd}[Lucida-Handwriting font]

\DeclareFontFamily{T1}{lhandw}{}

\DeclareFontShape{T1}{lhandw}{m}{n}{
   <-> lhandw
}{}

\DeclareFontShape{T1}{lhandw}{bx}{n}{<->ssub * lhandw/m/n}{}

\DeclareFontShape{T1}{lhandw}{m}{it}{<->ssub * ptm/m/it}{}
\DeclareFontShape{T1}{lhandw}{m}{sl}{<->ssub * ptm/m/sl}{}
\DeclareFontShape{T1}{lhandw}{m}{sc}{<->ssub * ptm/m/sc}{}

\DeclareFontShape{T1}{lhandw}{bx}{it}{<->ssub * ptm/b/it}{}
\DeclareFontShape{T1}{lhandw}{bx}{sl}{<->ssub * ptm/b/sl}{}
\DeclareFontShape{T1}{lhandw}{bx}{sc}{<->ssub * ptm/b/sc}{}

\pdfmapline{+lhandw\space <lhandw.ttf\space <T1-WGL4.enc}

We tell Pdflatex to use the Lucida font for both the normal medium and the bold style. The remaining six declarations tell Pdflatex to substiture the Times font for the italic, slanted, and small-caps shapes of the roman font.

The resulting PDF file looks fine in both Xpdf and Acrobat Reader.

Cleaning up the mess 

By now we have cluttered up the current directory with lots of new files: t1lhandw.fd, T1-WGL4.enc, lhandw.ttf , and lhandw.tfm. All of these should go into a nice cosy place on the system, so that they can be found whereever Pdflatex is run.

If you are not a system administrator on a Unix system, you would just create your own small TeX-tree, and set the environment variables TEXPSHEADERS (for .enc files), TTFONTS for Truetype fonts, and TEXINPUTS for .fd files.

If you are a system administrator, you should move the files to suitable places in the local TeX-tree.

On MikTeX, I recommend creating a local TeX-tree as well. Create a directory, say c:\Mytexmf and start the MikTeX options program (in the MikTeX menu). In the "Roots" tab, press "Add" and select the directory you just created. Move it up so that it is before the standard root directory (c:\texmf). You can now check the configuration file \texmf\miktex\config\miktex.ini for the exact paths searched by MikTeX. One choice would be

  • \mytexmf\pdftex\enc for T1-WGL4.enc,
  • \mytexmf\fonts\tfm for the .tfm file,
  • \mytexmf\fonts\truetype for the .ttf file,
  • \mytexmf\pdftex\latex for the .fd file.

After copying, press the "Refresh FNDB" button to update MikTeX's filename database.

It should now work to compile test.tex even when that is the only file in the current directory.

Otfried Cheong