I'm new to TeX. I have the following problem: How can I load a font from a file in a directory, which is located in the root of the project?

Say I have something like:


Loading it when it's right on the root seems to work.

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode


hello world


However I can't figure how to load it when it's in the fonts directory. I've tried ./fonts/DancingScript-Regular.ttf, fonts/DancingScript-Regular.ttf, "fonts/DancingScript-Regular.ttf" and file:./fonts/DancingScript-Regular.ttf. None of them work.

All guides seem to focus on some sort of "how to install the font" but I can't work with that since the fonts may change (regularly) and would cause a sort of font version hell; it's also not very version control friendly. The Fonts section in the LaTeX WikiBook doesn't seem to cover using your own fonts either.

Also, can I load the fonts as a sort of preset/alias? Since for a lot I have basically font families, so around 10 variants (oblique, bold, bold oblique, regular, etc). I would like to avoid repeating a declaration if possible.

  • @Martin this is a XeLaTeX question. TTF fonts are supported.
    – Alan Munn
    Mar 3, 2011 at 16:19
  • assuming you're on a *nix system, you might want to run the fc-cache command to update the fonts available to your system, then they will be available to xelatex without having to specify it.
    – Mica
    Mar 3, 2011 at 23:28
  • 1
    @Mica, my problem is cross-platform actually. I need a setup where people can collaborate on the project using something like git.
    – srcspider
    Mar 3, 2011 at 23:47
  • I have same symptom and solved it. Attached my solution on here.
    – Joshpy
    Feb 20, 2019 at 19:39

2 Answers 2


The following solution works for both XeLaTeX and LuaLaTeX.

P. 7 of the fontspec manual says:

To load a font that is not in one of the default search paths, its location in the filesystem must be specified with the Path feature:

\fontspec [ Path = /Users/will/Fonts/, 
UprightFont = *-regular,
 BoldFont = *-bold, ...]

The path doesn't have to be specified absolutely, so if you have your font(s) in e.g. texsource/fonts and your source is in texsource, you can use:

\fontspec [ Path = fonts/, ... ]  { } % note that the trailing '/' is required

Since it's usually inadvisable to use the \fontspec command directly, a more usual use would be to use one of the main font selecting commands, or \newfontfamily.

\setmainfont [ Path = fonts/, ... ] { }
\setsansfont [ Path = fonts/, ... ] { }
\setmonofont [ Path = fonts/, ... ] { }
\newfontfamily [ Path = fonts/, ... ] { }

Note that the part that follows the specification for the UprightFont, etc. must match the names of the actual font you are using. So for example, if your font files are named

MyFont-Roman.ttf and MyFont-Italic.ttf

the command to load them would use:

\fontspec [Path = fonts/,
    UprightFont = *-Roman,
    ItalicFont = *-Italic


Remember you don't need to use the \fontspec command specifically. Any other font selection command from fontspec such as \setmainfont or \newfontfamily can also be used with a Path specification as described earlier.

Unless you have a specific need for the fonts to be local, it's easiest just to install them into your system (on a Mac, /Library/Fonts) and they will be found automatically.

  • 27
    For anybody attempting this at home, the note "the trailing '/' is required" is not optional. I spent more time than I'd like to admit trying to get the Path correct until I realized that this comment in the code was the key.
    – Hooked
    Feb 20, 2013 at 18:52
  • @Hooked That is because the entire definition consists of path elements-some static and some dynamic. I tried explaining it here tex.stackexchange.com/questions/320096/…. Jan 23, 2018 at 15:05

I'll add as a bit of an aside, if you've read this and are still having problems.. the ttf that the code looks for is the same as the name of the font specified in the tex doc. So if the font name has spaces the ttf filename has to have spaces to! e.g. I had this:

\newfontfamily{\rim}[Path=./fonts/, Scale=1.5]{Rat Infested Mailbox}

And the font name was RatInfestedMailbox.ttf and xelatex couldn't find the font. When I renamed the font to 'Rat Infested Mailbox.ttf' xelatex finds it and is happy. In fact, the name of the ttf file has to be exactly the same as the font name (including e.g. special character like & if they're in the font name and case sensitivity (on linux)).

So it looks like the search for the ttf file doesn't do anything clever at all (like scan all ttfs in the font paths looking for the right font name if it can't find a .ttf with the given name straight up).

You must log in to answer this question.

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