Friday, April 18, 2008

How to use true type fonts (ttf) in MikTeX

LaTeX uses Type1 printer fonts (pfb) by default. True type fonts (ttf) also can be accepted by LaTeX. There are several common ways to do this job. One is to generate a tmf/vp pair for each ttf font using ttf2tfm and vptovf. Another approach is to use ttf2pt1 to get pfb, then use that file. In these ways ttf fonts can be embedded into dvi files. However, problem arises when dvi is converted to ps or pdf. Dvi driver converts the ttf fonts to pk fonts, which is not vector-coded. Thus, there is enormous artifact in the output pdf file. The edge of the characters appear zigzagged when magnified. Fortunately, there is a way to get smooth edges as well as avoid the tedious work to modify the LaTeX configuration files, which is strongly not recommended, because those files would get overwritten every time when LaTeX upgrades.

Here is the solution. Very simple. Use pdfLaTeX. I will just give a few steps instead of dull and tedious explanations.

Take the Arial font for example. It contains four shapes: normal, bold, italic and italic bold, with file name corresponding to arial.ttf, arialbd.ttf, ariali.ttf and arialbi.ttf.

Step 1. Run the following commands.


ttf2afm -e T1-WGL4.enc -o ecarial.afm %SystemRoot%\Fonts\arial.ttf
ttf2afm -e T1-WGL4.enc -o ecarialbd.afm %SystemRoot%\Fonts\arialbd.ttf
ttf2afm -e T1-WGL4.enc -o ecariali.afm %SystemRoot%\Fonts\ariali.ttf
ttf2afm -e T1-WGL4.enc -o ecarialbi.afm %SystemRoot%\Fonts\arialbi.ttf
afm2tfm ecarial.afm -T T1-WGL4.enc ecarial.tfm > arial.map
afm2tfm ecarialbd.afm -T T1-WGL4.enc ecarialbd.tfm >> arial.map
afm2tfm ecariali.afm -T T1-WGL4.enc ecariali.tfm >> arial.map
afm2tfm ecarialbi.afm -T T1-WGL4.enc ecarialbi.tfm >> arial.map
del ecarial.afm
del ecarialbd.afm
del ecariali.afm
del ecarialbi.afm


Step 2. Move all the tfm file to folder: "D:\Program Files\MiKTeX\fonts\tfm\winfonts\arial".

Step 3. Modify "arial.map", append the ttf file name to each line. It should look like this:


ecarial ArialMT " T1Encoding ReEncodeFont " <T1-WGL4.enc <arial.ttf
ecarialbd Arial-BoldMT " T1Encoding ReEncodeFont " <T1-WGL4.enc <arialbd.ttf
ecariali Arial-ItalicMT " T1Encoding ReEncodeFont " <T1-WGL4.enc <ariali.ttf
ecarialbi Arial-BoldItalicMT " T1Encoding ReEncodeFont " <T1-WGL4.enc <arialbi.ttf


Step 4. Move "arial.map" to folder: "D:\Program Files\MiKTeX\fonts\map\dvips\winfonts"

Step 5. Create a file named "t1arial.fd" in "D:\Program Files\MiKTeX\tex\latex\winfonts" with the following contents:


\ProvidesFile{t1arial.fd}[font for Arial]

\DeclareFontFamily{T1}{arial}{}

\DeclareFontShape{T1}{arial}{m}{n}{<-> ecarial}{}
\DeclareFontShape{T1}{arial}{m}{sl}{<->ssub * arial/m/it}{}
\DeclareFontShape{T1}{arial}{m}{it}{<-> ecariali}{}

\DeclareFontShape{T1}{arial}{b}{n}{<-> ecarialbd}{}
\DeclareFontShape{T1}{arial}{b}{sl}{<->ssub * arial/b/it}{}
\DeclareFontShape{T1}{arial}{b}{it}{<-> ecarialbi}{}

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

\pdfmapfile{arial.map}

\endinput


Step 6. Update the MikTeX directory.

Step 7. Write a simple tex file to test the result.


\documentclass[12pt]{article}
\renewcommand\encodingdefault{T1}
\renewcommand\rmdefault{times}
\renewcommand\sfdefault{arial}
\renewcommand\ttdefault{cour}
\newcommand\N{{N\hspace*{0.4em}}}
\begin{document}
This is font \textrm{Times \N{}ew Roman}.

This is font \textsf{Arial}.

This is font \texttt{Courier New}.

This is font {\usefont{T1}{comic}{m}{n} Comic Sans MS}.
\end{document}



2 comments:

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

Unknown said...

Thank you for this! I'v scoured the net and, besides being the only method that has worked for me thus far, this is the most concise and clear explanation of how one goes about incorporating TTFs in pdflatex. Now if I can only figure out how to automate the entire process for all my TTFs...