100

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 ?

9
  • 1
    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. Jul 27, 2010 at 1:39
  • 7
    @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?". :-) Jul 27, 2010 at 4:12
  • @ShreevatsaR: you are absolutely right. I didn't even consider the second option as being the question that was asked. My bad. Jul 27, 2010 at 5:03
  • @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.
    – Dima
    Jul 27, 2010 at 12:38
  • 6
    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. Aug 10, 2010 at 18:26

4 Answers 4

35

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

4
  • 1
    does that work in linux, and how does it help with installing fonts ?
    – Suresh
    Jul 27, 2010 at 0:48
  • 5
    XeLaTeX works on linux (and is probably installed already). It's a separate TeX engine, produces PDFs, and can use truetype fonts directly. Jul 27, 2010 at 1:38
  • I helps with installaing fonts, since nothing special needs to be done at all to use an already available system ttf font.
    – Dima
    Jul 27, 2010 at 1:54
  • 5
    That is the only viable solution now. It's 2011, we have XeLaTeX and LuaLaTeX, and they work. So use them. Aug 24, 2011 at 10:07
51

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

2
  • 1
    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. Aug 22, 2010 at 5:04
  • this works (mostly) but I am finding that the TriniteNo2 font seems to have improper spacing in XeTeX for "fi" and "fl" ... seems I need to place a space in there and then back up a little. Otherwise, words like "fish" just have a curve followed by "sh"
    – RichWalt
    Apr 26, 2022 at 14:30
25

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
3
  • 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.
    – cfr
    Apr 25, 2014 at 22:06
  • 1
    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. Apr 29, 2014 at 6:03
  • 1
    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.)
    – cfr
    Apr 29, 2014 at 13:57
2

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

2
  • 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. Aug 9, 2010 at 7:17
  • 2
    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-luatex Oct 20, 2010 at 7:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .