Installing TTF fonts in LaTeX

The easiest way is with XeTeX or LuaTeX and the fontspec package. They can use any TTF font installed on the system. For Linux this means both the system wide fonts and any fonts you put into ~/.fonts/ (e.g. by installing them via Nautilus).

To use the fonts you simply have to load the fontspec package and set the font:

\documentclass{article}

\usepackage{fontspec}
\setmainfont{Arial}

\begin{document}
Lorem ipsum...
\end{document}

Then compile the the document with xelatex or lualatex. The fontspec documentation describes all the possibilities for changing fonts.

The only drawbacks (as far as I am aware) are that you can only generate .pdf files and that you need a sufficiently new TeX distribution (TeX Live 2009 should work for XeTeX and Tex Live 2010 for LuaTeX).


One solution is to use XeLaTeX, which lets you use system fonts (mostly) hassle-free.


The process for PdfTeX is something like this (depends a little bit on your distribution):

  1. Get autoinst.pl from Fontools from CPAN
  2. Get otf2tfm from lcdf-typetools
  3. Run autoinst.pl (using Perl) on all ttfs
  4. Add generated PdfTeX font mapping (in MikTeX for instance initexmf --edit-config-file updmap, add Map yourmap.map and run initexmf --mkmaps)

You can do the whole process manually as well (autoinst.pl is nothing but a smart wrapper):

  1. Create tfm metrics and a ttfonts.map using ttf2tfm
  2. Create virtual font tables using vptovf
  3. Create afm metrics using ttf2afm
  4. Create pdf font map using afm2tfm
  5. Put *.tfm, *.afm, *.ttf, *.vf into the fonts/tfm/ etc.
  6. Add the font maps
  7. Create a package/sty to pull the various fonts into a font family (this is where I am stuck)

My ruby script for running the commands looks like this:

require 'fileutils'  

basename = "Nexus"

open("#{basename}.map", 'a') { |pdfFontMap|

    Dir["#{basename}*.ttf"].each{ |file|

        file.sub!(/\.ttf$/, "")

        ttf = "#{file}.ttf"

        file.gsub!(/_/,"") # Remove underscores

        puts `ttf2tfm #{ttf} -q -T T1-WGL4.enc -v ec#{file}.vpl rec#{file}.tfm >> ttfonts.map`

        puts `vptovf ec#{file}.vpl ec#{file}.vf rec#{file}.tfm`

        puts `ttf2afm -e T1-WGL4.enc -o rec#{file}.afm #{ttf}`

        pdfFontMap.puts `afm2tfm rec#{file}.afm -T T1-WGL4.enc rec#{file}.tfm`.gsub(/\r|\n/, "") + " <#{ttf}"
    }
}

You can find more details about the manual way in:

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

P.S.:

  • Run initexmf --update-fndb EVERY time new files are put somewhere