Installing custom fonts in LaTeX
How to install custom OpenType fonts in LaTeX
You want to use your favourite OpenType font, but don’t want to use XeTeX. No problem! Using custom OpenType fonts in latex isn’t that hard (since I did the hard work for you :D).
This guide should work for Linux too, although the examples here are all from OS X. This guide also assumes that you install the fonts system-wide, though adapting it for a user install shouldn’t be too difficult.
Requirements
You will need your desired OpenType fonts (duh). For the rest of this post, I’ll use the exemplary PragmataPro font by Fabrizio Schiavi as illustration. You should simply replace “PragmataPro” with whatever font it is you’re working with, except for the last section which will be specific to PragmataPro (you should modify the instructions in that section to suit the particular font you’re installing).
You will also need to install LCDF TypeTools. This can be done using brew install lcdf-typetools on OS X. However, we will not be using LCDF TypeTools
directly. Instead, we will rely on the package fontools (install using sudo tlmgr install fontools), which provides the command autoinst which is a
convenient wrapper around LCDF TypeTools.
Let’s go!
Move to your font directory. Mine looks like this:
$ ls
Changes log.txt
End-User License Agreement.txt
PragmataProB_0821.ttf
PragmataProI_0821.ttf
PragmataProR_0821.ttf
PragmataProZ_0821.ttf
PragmataPro™ All Characters.txt
PragmataPro™ Ligatures.png
PragmataPro™ OpenType Features.png
First we need to find the encoding files. The documentation for autoinst claims that the tool includes the encoding files for OT/T1/TS1/LY1, but autoinst couldn’t seem to find them on my system. In any case, it’s not too difficult to get them from your existing latex installation.
$ kpsewhich fontools_ot1.enc
/usr/local/texlive/2016basic/texmf-dist/fonts/enc/dvips/fontools/fontools_ot1.enc
You want the directory path. As you can see, the encoding files on my system are
in the directory
/usr/local/texlive/2016basic/texmf-dist/fonts/enc/dvips/fontools/.
Next, copy the encoding files into the current font directory.
$ cp /usr/local/texlive/2016basic/texmf-dist/fonts/enc/dvips/fontools/*.enc .
$ ls
Changes log.txt
End-User License Agreement.txt
PragmataProB_0821.ttf
PragmataProI_0821.ttf
PragmataProR_0821.ttf
PragmataProZ_0821.ttf
PragmataPro™ All Characters.txt
PragmataPro™ Ligatures.png
PragmataPro™ OpenType Features.png
autoinst.log
fontools_ly1.enc
fontools_ot1.enc
fontools_t1.enc
fontools_ts1.enc
Now, install! Or rather, let the magic of autoinst do all the hard work for us.
You should list all the font files you have for that font (each corresponding to
the different weights). In this case, I have 4
weights—regular/italic/bold/bolditalic. You should also change the
--typewriter flag to --sanserif if your font is a sans serif font, or
nothing (i.e. no flag) if it’s a serif font.
$ sudo autoinst --typewriter PragmataProR_0821.ttf PragmataProI_0821.ttf PragmataProZ_0821.ttf PragmataProB_0821.ttf
otftotfm: warning: TrueType-flavored font support is experimental
I had to round some heights by 0.0105000 units.
I had to round some heights by 0.0105000 units.
otftotfm: warning: TrueType-flavored font support is experimental
otftotfm: warning: not enough room in encoding, ignoring 80 glyphs
otftotfm: (The font uses more glyphs than the encoding has available slots,
otftotfm: so these glyphs have been left out:
otftotfm: ampersand_ampersand ampersand_ampersand_amp ampersand_asterisk
otftotfm: ampersand_equal ampersand_hyphen ampersand_percent ampersand_plus
otftotfm: ampersand_slash asciicircum_equal asciicircum_period
... output truncated ...
Generate map files with sudo updmap-sys --enable Map=PragmataPro.map.
$ sudo updmap-sys --enable Map=PragmataPro.map
... output truncated ...
updmap is creating new map files
... output truncated ...
Files generated:
/usr/local/texlive/2016basic/texmf-var/fonts/map/dvips/updmap:
15806 2016-07-02 13:53:10 builtin35.map
21279 2016-07-02 13:53:10 download35.map
2008385 2016-07-02 13:53:11 psfonts_pk.map
2014763 2016-07-02 13:53:10 psfonts_t1.map
2014758 2016-07-02 13:53:10 ps2pk.map
14 2016-07-02 13:53:11 psfonts.map -> psfonts_t1.map
/usr/local/texlive/2016basic/texmf-var/fonts/map/pdftex/updmap:
2014765 2016-07-02 13:53:11 pdftex_dl14.map
2013100 2016-07-02 13:53:11 pdftex_ndl14.map
15 2016-07-02 13:53:11 pdftex.map -> pdftex_dl14.map
/usr/local/texlive/2016basic/texmf-var/fonts/map/dvipdfmx/updmap:
329 2016-07-02 13:53:10 kanjix.map
Transcript written on "/usr/local/texlive/2016basic/texmf-var/web2c/updmap.log".
updmap: Updating ls-R files.
Ta-da!!! All you need to do to use your fancy new font is to include it in your tex file using
\RequirePackage[scale=0.8]{PragmataPro}
You can check out the list of available style options in the autoinst documentation.
Optional (but you probably want to do it)
For reasons that are beyond me, the author of autoinst decided that the font,
when included via RequirePackage, should configure itself as the document
default font. That is, if you did what I just did in the previous section, your
entire document will be using the PragmataPro font. Clearly, that doesn’t
really make sense here; what we really want is to use PragmataPro only when
explicitly called for by texttt{}. Sadly, autoinst does not provide any option
to disable that behaviour.
So we have to do it manually. First, find the generated style file.
$ find / -name PragmataPro.sty -type f -print 2>/dev/null
/usr/local/texlive/2016basic/texmf-local/tex/latex/PragmataPro/PragmataPro.sty
Now, edit that file. Go right to the bottom, and remove the one line shown below:
\renewcommand*
{\ttdefault}
{PragmataPro-\PragmataPro@figurealign\PragmataPro@figurestyle}
\renewcommand*{\familydefault}{\ttdefault} % <-- Remove this line!
\endinputDone.
Epilogue
Hope this helps someone. Or has everyone moved to LuaLaTeX already..?