Using TrueType fonts with TeX (LaTeX)
and
pdfTeX (pdfLaTeX)

Damir Rakityansky,
radamir@technologist.com

This note describes how to add TrueType fonts support to TeX and LaTeX. This information is provided for educational purpose only. I do not know if procedures described here violate any copywrite/license agreement. Also, names ectimes and winfonts are used just for example. I do not know how they should be named correctly.

1 Before we begin (TeX) 7 Using new fonts in LaTeX
2 Creating TeX Font Metrics (tfm) 8 Before we begin (pdfTeX)
3 Creating Virtual Fonts (vf) 9 Creating Adobe Font Metrics (afm)
4 Installation of fonts for TeX and LaTeX 10 Gathering map file
5 Testing the installation in TeX 11 Installation of fonts for pdfTeX and pdfLaTeX
6 Using new fonts in TeX 12 Testing the installation in pdfTeX
13 Acrobat Bug Note

Before we begin (TeX)

Base configuration, used in this document, is MiKTeX 1.11 (complete.exe) + Update Three and Ghostscript+GSview 5.50.

Adobe Acrobat users, please read a Bug Note at the end of the document.

Suppose, we want to typeset in Times New Roman instead of Computer Modern Roman (cmr). Times New Roman in Windows 9x/NT 4 is a Unicode font which has almost all symbols from Computer Modern. Certainly, they are in different places. To use these fonts in TeX (LaTeX) and PDF documents, it is necessary to create two more fonts: raw tex font, containing necessary characters but without kerning information, and virtual tex font with kerns and ligatures. For simplicity, we’ll use the rule that if TrueType font file has a name foo.ttf, than virtual tex font in T1 encoding will be named ecfoo and raw tex font will be named recfoo. Times New Roman family of fonts is presented by the files times.ttf, timesi.ttf, timesbd.ttf and timesbi.ttf, found in c:\windows\fonts directory in Windows 9x or c:\winnt\fonts in Windows NT. The family has Regular, Italic, Bold and BoldItalic members. We’ll also create oblique (slanted) versions of Regular and Bold members, which will be marked by letter “o” at the end of the name. The above is summarized in a table:

  TrueType File Name (.ttf) TeX Name (virtual font; .vf, .tfm) Raw TeX Name (.tfm, .afm, .pk)
Regular times ectimes rectimes
Italic timesi ectimesi rectimesi
Bold timesbd ectimesbd rectimesbd
BoldItalic timesbi ectimesbi rectimesbi
Oblique - ectimeso rectimeso
BoldOblique - ectimesbdo rectimesbdo

Also we’ll need an encoding vector—a file which determines characters positions in a new fonts. We’ll use a file T1-WGL4.enc which corresponds to T1 encoding.

To be able to typeset with Cyrillic characters, you should use T2A-mod0.enc file or similar, found in T2 package.

Create a temporary working directory and copy font files (times.ttf, timesbd.ttf, timesbi.ttf, timesi.ttf from c:\windows\fonts [Attention! Directory is hidden.]) and encoding file (T1-WGL4.enc) there. Now we are ready for actual work.

Creating TeX Font Metrics (tfm)

Run commands:

ttf2tfm times.ttf -q -T T1-WGL4.enc -v ectimes.vpl rectimes.tfm >> ttfonts.map
ttf2tfm timesi.ttf -q -T T1-WGL4.enc -v ectimesi.vpl rectimesi.tfm >> ttfonts.map
ttf2tfm timesbd.ttf -q -T T1-WGL4.enc -v ectimesbd.vpl rectimesbd.tfm >> ttfonts.map
ttf2tfm timesbi.ttf -q -T T1-WGL4.enc -v ectimesbi.vpl rectimesbi.tfm >> ttfonts.map

This will create a tfm files of raw fonts and vpl files of virtual fonts. To generate slanted versions of regular and bold font, command should be extended like this:

ttf2tfm times.ttf -q -T T1-WGL4.enc -s .167 -v ectimeso.vpl rectimeso.tfm >> ttfonts.map
ttf2tfm timesbd.ttf -q -T T1-WGL4.enc -s .167 -v ectimesbdo.vpl rectimesbdo.tfm >> ttfonts.map

Creating Virtual Fonts (vf)

Run commands:

vptovf ectimes.vpl ectimes.vf ectimes.tfm
vptovf ectimesi.vpl ectimesi.vf ectimesi.tfm
vptovf ectimesbd.vpl ectimesbd.vf ectimesbd.tfm
vptovf ectimesbi.vpl ectimesbi.vf ectimesbi.tfm
vptovf ectimeso.vpl ectimeso.vf ectimeso.tfm
vptovf ectimesbdo.vpl ectimesbdo.vf ectimesbdo.tfm

This creates vf and tfm files for virtual fonts. After that you can delete vpl files:

del *.vpl

Installation of fonts for TeX and LaTeX

Now vf and tfm files should be moved to the place where MiKTeX can find them. Move all vf files to c:\localtexmf\fonts\vf\ms\times\, and all tfm files to c:\localtexmf\fonts\tfm\ms\times\. The directories ms\times are not mandatory, you can leave the files even in parent dirs, but this way it is easier to maintain them and it corresponds to the general rule of placement: <supplier>\<family>.

Open the file ttfonts.map in a temporary working directory with your favorite text editor (notepad :) and copy its contents to clipboard. Now open a file c:\texmf\ttf2tfm\base\ttfonts.map with the same editor and paste the lines from clipboard. Beware that your editor does not wrap long lines automatically. Save the file.

This is sufficient for generating DVI file, but to view or print it, there should be a raster (pk) font. MiKTeX will attempt to generate it automatically with new utility: ttf2pk. For successful generation ttf2pk should find both TrueType font and encoding file. It happens that ttf2pk can find ttf files, if they are installed and are in a system fonts directory, and it looks for encoding files in a directory c:\texmf\pdftex\base\ (among others).Therefore you have to copy T1-WGL4.enc to c:\texmf\pdftex\base\.

Now we have to update databases:

Start=>Programs=>MiKTeX=>Maintenance=>Refresh Filename Database

Testing the installation in TeX

Change current directory from temporary working to some other where there are no files related to fonts creation. To have a look at our brand new fonts, run a command

tex testfont

It will ask about a font to test. Enter "ectimes". It will ask about a command. Enter "\table\eject\init". This time enter "ectimeso", then "ectimesbd" and so on. After all fonts are tested, enter a command "\bye". This will create a file testfont.dvi in current directory.

If you have problems at this stage, it is either wrong font names or tfm, vf files placement.

But do not hurry to open testfont.dvi with YAP. If something goes wrong, it is quite hard to trace the problem in YAP. Better try converting dvi to PostScript:

dvips testfont.dvi

Here you will have plenty of messages about what is happening. In particular, the generation of pk for TrueType will look like this:

- make_pk_font (rectimes, 600, 600, ljfour)
name: rectimes, dpi=600, bdpi=600, mag=magstep(0.0), mode=ljfour
C:\texmf\miktex\bin\makemf.exe --verbose rectimes
Cannot find rectimes source file.
C:\texmf\miktex\bin\ttf2pk.exe -q -n rectimes 600
ttf2pk: WARNING: Cannot map character `compwordmark'.
ttf2pk: WARNING: Cannot map character `perthousandzero'.
ttf2pk: WARNING: Cannot map character `dotlessj'.
ttf2pk: WARNING: Cannot map character `ff'.
ttf2pk: WARNING: Cannot map character `ffi'.
ttf2pk: WARNING: Cannot map character `ffl'.
ttf2pk: WARNING: Cannot map character `visualspace'.
ttf2pk: WARNING: Cannot map character `Germandbls'.
Creating rectimes.pk...
move rectimes.pk
C:\localtexmf\fonts\pk\modeless\ms\times\dpi600\rectimes.pk

As you can see, Times New Roman is missing several characters, most notably ff, ffi and ffl ligatures.

Using new fonts in TeX

To use new fonts in TeX, you can issue a commands like:

\font\myfont=ectimes
\font\mybigfont=ectimes at 36pt
\myfont Hello, I am being typeset in Times New Roman 

\mybigfont Me too...

Using new fonts in LaTeX

LaTeX requires some additional efforts. Create a font definition file t1tnr.fd in c:\localtexmf\tex\latex\winfonts directory with the following contents:

\ProvidesFile{t1tnr.fd}[Put your description of font here]

\DeclareFontFamily{T1}{tnr}{}

\DeclareFontShape{T1}{tnr}{b}{n}{<->ectimesbd}{}
\DeclareFontShape{T1}{tnr}{b}{sl}{<-> ectimesbdo}{}
\DeclareFontShape{T1}{tnr}{b}{it}{<-> ectimesbi}{}

\DeclareFontShape{T1}{tnr}{m}{n}{<-> ectimes}{}
\DeclareFontShape{T1}{tnr}{m}{sl}{<-> ectimeso}{}
\DeclareFontShape{T1}{tnr}{m}{it}{<-> ectimesi}{}

\DeclareFontShape{T1}{tnr}{bx}{n}{<->ssub * tnr/b/n}{}
\DeclareFontShape{T1}{tnr}{bx}{sl}{<->ssub * tnr/b/sl}{}
\DeclareFontShape{T1}{tnr}{bx}{it}{<->ssub * tnr/b/it}{}

\endinput

Now you can use new fonts in LaTeX like the following:

\documentclass{article}
\begin{document}
\usefont{T1}{tnr}{m}{sl} 

Hello, I am being typeset in Times New Roman Slanted 

\end{document}

Finally, if you want to use Times New Roman as you default roman font, put two \renewcommand command in preamble:

\documentclass{article}

\renewcommand{\encodingdefault}{T1}
\renewcommand{\rmdefault}{tnr}

\begin{document}

Hello, I am being typeset in \textsl{Times New Roman Slanted} 

\end{document}

Now you can try use pdftex and pdflatex to create PDF documents but new fonts will be embeded as bitmaps which makes the whole pdf-story half useless. Let's see how to embed TrueType fonts in PDF documents in native format.

Before we begin (pdfTeX)

First you shoulld check that your pdfTeX is up and running. A command

pdftex story

will give the following screen messages:

C:\texmf>pdftex story
This is pdfTeX, Version 3.14159-12r (MiKTeX 1.11c)
(pdftex.cfg) (story.tex [1<cm.map>])
*

Enter a command \bye and you should get

*\bye
<cmtext.enc><cmr10.pfb><cmsl10.pfb><cmbx10.pfb>
Output written on story.pdf (1 page, 31672 bytes).
Transcript written on story.log.

There are two important things in these lines. First is (pdftex.cfg) and <cm.map>, which means that pdftex has found its configuration file and loaded the Computer Modern fonts map. Second is <cmtext.enc><cmr10.pfb>..., which means that Type 1 PostScript fonts CMR10, CMSL10 and CMBX10 were included in document along with encoding file.

Creating Adobe Font Metrics (afm)

To create afm files, go back to temporary working directory and run the following commands:

ttf2afm -e T1-WGL4.enc -o rectimes.afm times.ttf
ttf2afm -e T1-WGL4.enc -o rectimesi.afm timesi.ttf
ttf2afm -e T1-WGL4.enc -o rectimesbd.afm timesbd.ttf
ttf2afm -e T1-WGL4.enc -o rectimesbi.afm timesbi.ttf

The program will complain it can not find few characters but will create desired afm files.

Gathering map file

Now we have to create a map file whiich will map raw tex font names to actual TrueType names. Though this can be done by copying necessary strings from afm files, it also can be accomplished by afm2tfm program. As the name implies, it creates tfm files whcih we already have. But a side effect of this proram is outputting a string which is necessary for map file. Run the following commands:

afm2tfm rectimes.afm -T T1-WGL4.enc rectimes.tfm >>winfonts.map
afm2tfm rectimesi.afm -T T1-WGL4.enc rectimesi.tfm >>winfonts.map
afm2tfm rectimesbd.afm -T T1-WGL4.enc rectimesbd.tfm >>winfonts.map
afm2tfm rectimesbi.afm -T T1-WGL4.enc rectimesbi.tfm >>winfonts.map
afm2tfm rectimes.afm -T T1-WGL4.enc -s .167 rectimeso.tfm >>winfonts.map
afm2tfm rectimesbd.afm -T T1-WGL4.enc -s .167 rectimesbdo.tfm >>winfonts.map

Open winfonts.map file for editing and add near the end of each line a name of the corresponding ttf file :

rectimes TimesNewRomanPSMT " T1Encoding ReEncodeFont " <times.ttf T1-WGL4.enc
rectimesi TimesNewRomanPS-ItalicMT " T1Encoding ReEncodeFont " <timesi.ttf T1-WGL4.enc
rectimesbd TimesNewRomanPS-BoldMT " T1Encoding ReEncodeFont " <timesbd.ttf T1-WGL4.enc
rectimesbi TimesNewRomanPS-BoldItalicMT " T1Encoding ReEncodeFont " <timesbi.ttf T1-WGL4.enc
rectimeso TimesNewRomanPSMT " .167 SlantFont T1Encoding ReEncodeFont " <times.ttf T1-WGL4.enc
rectimesbdo TimesNewRomanPS-BoldMT " .167 SlantFont T1Encoding ReEncodeFont " <timesbd.ttf T1-WGL4.enc

Installation of fonts for pdfTeX and pdfLaTeX

Create a directory in localtexmf tree c:\localtexmf\fonts\afm\ms\times and move all afm files there.

Create a directory in localtexmf tree c:\localtexmf\pdftex\base and move winfonts.map file there.

Edit the filec:\texmf\miktex\config\miktex.ini: find the line which starts with "TrueType Font Dirs=" and add windows fonts directory:

TrueType Font Dirs=.;%R\fonts\truetype//;c:\windows\fonts

Open c:\texmf\pdftex\base\pdftex.cfg file for editing and add the following line:

map +winfonts.map

As you can see, there are a lot of other map files available in this dir, but most of them require that you additionaly purchase font files.

Now we have to update databases:

Start=>Programs=>MiKTeX=>Refresh databases

Testing the installation in pdfTeX

Change current directory from temporary working to some other where there are no files related to fonts creation and run a command

pdftex testfont

It will ask about a font to test. Enter "ectimes". It will ask about a command. Enter "\table\eject\init". This time enter "ectimeso", then "ectimesbd" and so on. After all fonts are tested, enter a command "\bye". Screen output will be like this:

pdftex testfont
This is pdfTeX, Version 3.14159-12r (MiKTeX 1.11c)
(pdftex.cfg) (testfont.tex
Name of the font to test = ectimes
Now type a test command (\help for help):)
*\table\eject\init
[1<cm.map><winfonts.map>]
Name of the font to test = ectimesbdo
Now type a test command (\help for help):
*\table\bye
[2]<T1-WGL4.enc><timesbd.ttf><cmttext.enc><cmtt10.pfb><times.ttf><cmitext.enc><
cmti10.pfb><T1-WGL4.enc><cmr10.pfb><cmr7.pfb>
Output written on testfont.pdf (2 pages, 195888 bytes).
Transcript written on testfont.log. 

As you can see, this time pdftex has found winfonts.map and embeded encodingg file T1-WGL4.enc and TrueType fonts times.ttf and timesbd.ttf into resulting PDF document. Open testfont.pdf with GSview and you will see:

Adobe Acrobat users, please read a Bug Note at the end of the document.

Using new fonts with pdfTeX and pdfLaTeX is the same as with plain TeX and LaTeX respectively.

We are done...

Acrobat Bug Note

PDF files are easier to work with in Adobe Acrobat Reader than in GSview but Acrobat has a "feature": it can not correctly display document with embeded TrueType fonts which are already installed in Windows. If you open the same pdf file with Acrobat Reader 3.01 you will see

Acrobat displays only characters, which was not touched by reencoding! If you try to uninstall the font from Windows (NOT RECOMMENDED with Times New Roman), Acrobat will show the same file just fine:

Member of Canada HyperBanner