Installing TTF fonts in LaTeX

72,433

Solution 1

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

Solution 2

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).

Solution 3

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

Solution 4

LuaTeX brings TTF-support, but I have no Idea how mature it is right now.

Share:
72,433

Related videos on Youtube

Suresh
Author by

Suresh

Updated on November 25, 2021

Comments

  • Suresh
    Suresh almost 2 years

    One of the annoying aspects of LaTeX is the limited number of fonts that come by default, and the pain involved in making new fonts 'LaTeX' ready. I have a collection of truetype fonts that I'd like to prepare for use, and I definitely want to make sure I have vector versions of these fonts (i.e not type 3/bitmapped versions). Is there a relatively painless way to do this ?

    • Willie Wong
      Willie Wong over 13 years
      Short answer: not really. I had to do it once 6 years ago to get some additional Chinese fonts working with CJKlatex, and all I can remember of that experience is that it was a complete pain and I would never, ever try to do that again.
    • ShreevatsaR
      ShreevatsaR over 13 years
      @Willie: This is an example of the all-too-common XY problem: the answer to "is there a painless way to generate latex font metrics from TTF fonts?" may well be "not really", but the XeLaTeX mention below is an answer to the question of "is there a painless way of using TTF fonts in a document?". :-)
    • Willie Wong
      Willie Wong over 13 years
      @ShreevatsaR: you are absolutely right. I didn't even consider the second option as being the question that was asked. My bad.
    • Dima
      Dima over 13 years
      @ShreevatsaR: exactly. It's not obvious from the question whether latex engine is a must, or any engine capable of processing LaTeX syntax is fit for the answer. Also it hasn't been specified which type of output is expected: dvi, ps, pdf, svg, or all of the above.
    • Suresh
      Suresh over 13 years
      I'd prefer latex, and I want to generate dvi/ps/pdf.
    • Martin Heller
      Martin Heller about 13 years
      There is a nice TUGboat article by S. Kroonenberg called "Font installation the shallow way" <tug.org/TUGboat/Articles/tb27-1/tb86kroonenberg-fonts.pdf>. The article provides a number of examples of how to use different kinds of fonts with (pdf)LaTeX.
    • graffe
      graffe about 12 years
      What I don't understand is why there isn't a script that just does it for you? That way only one person ever has to understand the convoluted process.
    • Suresh
      Suresh about 12 years
      I've made the switch to xelatex, and am much happier :)
    • Vicent
      Vicent almost 11 years
      Still no way to do this (installing a .TTF font in LaTeX) in a save and successful way, in MiKTeX 2.9 (pdf)LaTeX???
  • Suresh
    Suresh over 13 years
    does that work in linux, and how does it help with installing fonts ?
  • ShreevatsaR
    ShreevatsaR over 13 years
    XeLaTeX works on linux (and is probably installed already). It's a separate TeX engine, produces PDFs, and can use truetype fonts directly.
  • Dima
    Dima over 13 years
    I helps with installaing fonts, since nothing special needs to be done at all to use an already available system ttf font.
  • Roman Plášil
    Roman Plášil about 13 years
    It works. And it's not too difficult to use in ConTeXt. But I'm not sure if anyone exposed this functionality to LaTeX already.
  • Herbert Sitz
    Herbert Sitz about 13 years
    I use XeTeX myself and think it's a good solution. There are some drawbacks, though, that may or may not be important to particular users. One of the major drawbacks for some is that the microtype package for XeTeX is not fully functional; microtype with pdftex gives much better results.
  • Ulrike Fischer
    Ulrike Fischer about 13 years
    The above example for xelatex (with fontspec + Arial) will work unchanged with lualatex too (with a recent fontspec). A discussion about difference of xelatex + lualatex is here tex.stackexchange.com/questions/3094/drawbacks-of-xetex-luat‌​ex
  • Martin Schröder
    Martin Schröder about 12 years
    That is the only viable solution now. It's 2011, we have XeLaTeX and LuaLaTeX, and they work. So use them.
  • cfr
    cfr over 9 years
    I don't know if initexmf is an old invocation or a MiKTeX specific one but it is not something you should or could do in TeX Live at any time, let alone every time new files are put somewhere. Moreover, there is no required equivalent if you install into TEXMFHOME. Moreover describing this as 'the process for pdfTeX' is wrong. It is a process. It is not the only one. Also, I am pretty sure the manual process is mis-described. At the very least, it involves unnecessary steps.
  • Christopher Oezbek
    Christopher Oezbek over 9 years
    Well cfr, the answer is 4 years old, so your mileage may vary and feel free to provide a better answer. Most of your comment does not provide any useful information for anybody.
  • cfr
    cfr over 9 years
    Well it tells somebody running TeX Live that their system's failure to find initexmf is normal and does not mean their TeX installation is borked. It doesn't tell them what to do instead since that would take more than a comment. But it does tell them that they should look elsewhere for instructions. As I say, this command might have worked in past TeX Live installations or might be right for MiKTeX. But it isn't right for any relatively recent version of TeX Live. (In the strong sense that it isn't possible for relatively recent versions of TL.)