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

http://www.radamir.com/tex/ttf-tex.htm

Damir Rakityansky

Before we begin (TeX) 

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:

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.

[Tip]

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.

[Tip]

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.

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: