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 ?
4 Answers
One solution is to use XeLaTeX, which lets you use system fonts (mostly) hassle-free.
-
1
-
5XeLaTeX 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.– DimaJul 27, 2010 at 1:54
-
5That 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
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).
-
1I 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"– RichWaltApr 26, 2022 at 14:30
The process for PdfTeX is something like this (depends a little bit on your distribution):
- Get autoinst.pl from Fontools from CPAN
- Get otf2tfm from lcdf-typetools
- Run autoinst.pl (using Perl) on all ttfs
- Add generated PdfTeX font mapping (in MikTeX for instance
initexmf --edit-config-file updmap
, addMap yourmap.map
and runinitexmf --mkmaps
)
You can do the whole process manually as well (autoinst.pl is nothing but a smart wrapper):
- Create tfm metrics and a ttfonts.map using
ttf2tfm
- Create virtual font tables using
vptovf
- Create afm metrics using
ttf2afm
- Create pdf font map using
afm2tfm
- Put *.tfm, *.afm, *.ttf, *.vf into the
fonts/tfm/
etc. - Add the font maps
- 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
-
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.– cfrApr 25, 2014 at 22:06 -
1Well 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
-
1Well 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.)– cfrApr 29, 2014 at 13:57
LuaTeX brings TTF-support, but I have no Idea how mature it is right now.
-
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
-
2The 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
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.