Using TrueType (TTF) fonts in LaTeX

[Update: If you are using LuaLaTeX, properly including Truetype fonts is much easier.]

This is a tutorial for using TrueType (TTF) fonts in pdf(la)tex. The document tries to be as complete as possible for what it does, and its emphasis is on the benefits that recent developments of the LCDF typetools deliver. Comparing other popular tutorials written before the LCDF typetools 2.79 release (which enabled TTF support for most fonts), this actually saves a couple of intermediate steps.
There are a couple of nice tutorials around, see, for example, Damir Rakityansky's page or Christophe Caignaert's knowledge baseGeoffrey Washburn's article in his excellent blog is geared towars OTF fonds and also includes the usage of otftotfm.

Necessary tools

What we will actually use is only the otftotfm executable, hence it is required to have a recent (>=2.79) version of theLCDF typetools installed. Obviously, you'll want a working LaTeX installation as well; it is assumed that a recent version of pdflatex is included.
The word "Taffi" with (above) and
without (below) proper kerning and ligatures.

What we have and what we need

So, you have your favourite font myfont.ttf and you'd like to use it in LaTeX? To access all the benefits that (La)TeX brings over using generic WYSIWYG editors (like kerning, and ligatures), there's need to generate a file or two to provide LaTeX with this kind of extra information. If you ask yourself why to go through the hassle, please have a look at Dario Taraborelli's The Beauty of LaTeX.

Let's get it on: TeX font files

  1. Come up with an appropriate (internal) TeX name for your font. This is not mandatory, but sticking to some guidelines will certainly help to keep things in shape. You'll certainly want to have a look at Karl Berry's font name scheme here. From now on, the tutorial assumes that the font name is jcsr8t (which would be Microsoft's [j] Comic Sans [cs], regular type [r], T1 (Cork) encoding [8t]). Of course, please, do not use Comic Sans, EVER; for reasons why, see Putting the Sans in Comic sans.
  2. Generating all the necessary files happens in one swift step; just do

    $ otftotfm \
    --no-type1 \
    -fkern \
    --encoding="T1-WGL4.enc" \
    --map-file="" \
    "myfont.ttf" \

    This will generate the files jcsr8t.vpljcsr8t.tfm, and jcsr8t--base.tfm, plus the encoding file (mostlya_012foobar.enc), and generate the correct entry in the map file Note that there's a plethora of options for otftotfm (which may actually save you the next two steps as well), so please take look at the manual.
  3. If your TeX tree is ~/texmf/ you'll be required to copy
    • all .tfm files to ~/texmf/fonts/tfm/microsoft/comicsans/,
    • all .vf files to ~/texmf/fonts/vf/microsoft/comicsans/,
    • all .ttf files to ~/texmf/fonts/truetype/comicsans/, and
    • the .enc files to ~/texmf/fonts/enc/dvips/comicsans/.
    Note that otftotfm can do that for you quite automatically, see the --automatic option of the tool. In this case, don't forget to also specify --vendor="microsoft" and --typeface="comicsans" to actually get the directories right.
  4. The only thing that remains is telling TeX about the new files, and this is done by
    $ texhash
    $ updmap --enable Map=~/texmf/fonts/maps/dvips/comicsans/
Done! This should be enough to get your font working in TeX.

Testing the font


$ pdftex testfont

and provide the TeX font name you chose in step 1 (jcs); what you should get is a PDF file displaying a table of your font, followed by a short text sample of it. Alternatively, you can also use the LaTeX package fonttable;

Font table for Auto 1.

Convenient access in LaTeX

In LaTeX, typically, you'll want to be able to say \usepackage{comicsans} in the header and have convenient access to your font by, for example, \textsf{sans-serif text sample}, without ever touching the TeX internals. To achieve this, we'll merely have to create two more files, T1jcs.enc and comicsans.sty. Let's start with the first one.
  1. The .fd file connects the TeX font jcsr8t to the LaTeX information "font family: jcs", "font series: medium, m" (as opposed to bold, b), "font shape: upright, n" (as opposed to italic, it). The contents of T1jcs.fd then read

    [2009/06/14 Provides font definitions for T1/jcs.]
    \DeclareFontShape{T1}{jcs}{m}{n} {<-> jcsr8t } {}

    Usually there is more than only one \DeclareFontShape line, referring to, for example, italic or bold versions of a font family. Anyway, LaTeX knows about the family jcs now, so what we could do within a LaTeX document is

    Lorem ipsum {\fontfamily{jcs}\fontseries{m}\fontshape{n} \selectfont dolor sit} amet

    The "dolor sit" part should now appear typeset in myfontIf the encoding is set to T1, LaTeX will look for a file named T1jcs.fd. If you don't change the encoding and remain at TeX's defaul OT1 (which is inferior to T1), LaTeX will look for OT1jcs.fd and complain if it is not found. To simply render all of your text in myfont, it is enough to add


    to the header of your LaTeX document.
  2. If you'd like to to handle the latter in a more sane way (which I hope is the case), the .sty file is your friend. A short example would be

    [2009/06/14 John Doe LaTeX package loading myfont TTF font]




    Then, your LaTeX header must include only the line \usepackage{comicsans} and you have what you were looking for.
Happy TeXing!



  1. Thanks for this tutorial.

    1. The automatic -a option is the way to go. Then you don't need to call updmap yourself. If you have already run otftotfm without -a you may have messed things up. It could be necessary to delete
    before starting from scratch.
    2. Don't mess about with .ttf files in your local directory. Put them in the right place immediately. (See item 5 below).
    3. lcdf-typetools 2.66 is recent enough.
    4. On Ubuntu, T1-WGL4.enc is not in a minimal TeXLive installation. Install freetype1-tools.
    5. The script in the tutorial to run otftotfm can't just be cut and pasted, since it has some em dashes where there should be two dashes. Maybe some over-clever text editor? I used:

    mkdir -p ~/$FONTDIR
    mv comic.ttf $FONTDIR
    otftotfm -ae T1-WGL4.enc $FONTDIR/comic.ttf jcsr8t

    6. You don't need to say -notype1, otftotfm is smart enough.
    7. In the case of ComicSans -fkern does nothing.


Post a Comment