[XeTeX] Loading a Font Family from a Local File

Alan Munn amunn at gmx.com
Tue Mar 8 17:47:15 CET 2011

On Mar 8, 2011, at 11:27 AM, Rob Oakes wrote:

> Dear XeTeX Users,
> I am writing with a somewhat simple question, but it was not one that I was able to find a straightforward answer to.
> I am currently working on a document class for a non-profit. They will be using LyX to typeset and publish a number of books related to Mexican culture. I've been asked to create both a LaTeX document class for them and a LyX layout that allows them to use the document class in a WYSIWYG environment.  For the design, I would like to use the memoir class and two open  type fronts: Linux Libertine and ADF Universalis.
> On my own computer, I am able to use use the fonts through fontspec commands, as they were installed using Font Book on Mac OS X. However, to simplify the installation of the template, I would like to place the font files in the same folder as the class and then load them from the directory, rather than from the system fonts folder.
> Does anyone know how that might be done using fontspec? I know it is possible to load individual font-files, but I was hoping to be able to use the entire families.  Any thoughts would be extremely appreciated.

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, ...]
>     {texgyrepagella}

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

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


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.

Alan Munn
amunn at gmx.com

More information about the XeTeX mailing list