9

I have some .ttf fonts in ~/Library/Fonts that I would like to use with XeLaTeX, but it can't seem to find them. For example, this will compile:

\documentclass[]{article}
\usepackage{fontspec}
\setmainfont{Times New Roman}

\begin{document}
The quick brown fox jumps over the lazy dog.
\end{document}

But this won't:

\documentclass[]{article}
\usepackage{fontspec}
\setmainfont{Times New Roman.ttf}

\begin{document}
The quick brown fox jumps over the lazy dog.
\end{document}

And yes, Times New Roman.ttf is in ~/Library/Fonts.

6
  • Your title is a bit misleading: XeLaTeX does find the font, but it seems to depend on the denomination you give as argument to the \setmainfont command. I don't know the exact rules for it, but it appears that the simpler this denomination is, the better works. Commented May 3, 2015 at 13:16
  • @FranckPastor Good, it shows people that I have no idea what's going on. :) I changed it anyway. Commented May 3, 2015 at 13:18
  • @HenriMenke So I should put my font file in the texmf tree? The closest thing I could find is texmf-local, which has a fonts folder. Will that work? Commented May 3, 2015 at 13:20
  • @HenriMenke I just used this as an example. The fonts I actually want to use aren't system fonts. What should I do then? I'm not sure whether I should put my document in Library/Fonts or put my fonts with the tex documents. Commented May 3, 2015 at 13:24
  • Only use texmf-local for sharing on multi-user systems. The "right" place for personal additions to TeX is your personal TeX directory. On Linux this is ~/texmf; on Macs it's ~/Library/texmf; and on Windows it's C:\texmf. Subdirectories must be the same as other texmf's, so on Macs, TTF fonts go in ~/Library/texmf/fonts/truetype/{fontname}/ - In Linux and OS X, LaTeX will automatically search those directories. Under MikTeX, you need to add the directory to the FNDB, and remember to update it after any changes. For more details, see latex.silmaril.ie/formattinginformation/personal.html Commented Oct 4, 2015 at 14:00

1 Answer 1

16

You seem to have a misunderstanding of font lookup of xetex. The different lookup mechanisms are described in detail in the XeTeX manual, but I will try to boil things down a little for an answer.

If you provide a font name, e.g. Times New Roman, as in your first example, where you call

\setmainfont{Times New Roman}

then XeTeX will use your system's font utility to lookup the font. On GNU/Linux this is usually fontconfig. XeTeX will say to fontconfig “Where is the font with the name «Times New Roman»?”, and fontconfig will reply something like “It is located in .fonts/Times New Roman/Times New Roman.ttf.” Then XeTeX will proceed to call xdvipdfm which loads the font from that file.

If you provide a file name instead of a font name, e.g. Times New Roman.ttf, as in

\setmainfont{Times New Roman.ttf}

then XeTeX will immediately hand over to the xdvipdfm utility to include the font from that file, i.e. either from Times New Roman.ttf in the current directory or via kpathsea from the texmf tree.

It is advisable to install fonts as system fonts, such that you don't have multiple copies of a font floating around your directories. If this is not possible for whatever reason then you should place the font files alongside your document in the same directory or maybe, if you use many fonts, in a subfolder solely dedicated to fonts. You may then load the fonts by their relative paths, as in

\setmainfont{fonts/Times New Roman.ttf}

N.B.: I don't like spaces in file names, because some pieces of software tend to break if you don't escape them properly.

You must log in to answer this question.

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