The fontspec package Font selection for XeTeX and LuaLATEX
The fontspec package Font selection for XeTeX and LuaLATEX
By file name
XeTeX and LuaTEX also allow fonts to be loaded by file name instead of font name.
When you have a very large collection of fonts, you will sometimes not wish to have them all installed in your system's font directories.
In this case, it is more convenient to load them from a different location on your disk.
This technique is also necessary in XeTeX when loading OpenType fonts that are present within your TEX distribution,
such as /usr/local/texlive/2013/texmf-dist/fonts/opentype/public.
Fonts in such locations are visible to XeTeX but cannot be loaded by font name, only file name;
LuaTEX does not have this restriction.
When selecting fonts by file name, any font that can be found in the default search paths
may be used directly (including in the current directory)
without having to explicitly define the location of the font file on disk.
Fonts selected by filename must include bold and italic variants explicitly,
unless a .fontspec file is supplied for the font family (see Section 2.3).
We'll give some first examples specifying everything explicitly:
\setmainfont{texgyrepagella-regular.otf}[
BoldFont = texgyrepagella-bold.otf ,
ItalicFont = texgyrepagella-italic.otf ,
BoldItalicFont = texgyrepagella-bolditalic.otf ]
fontspec knows that the font is to be selected by file name by the presence of the '.otf' extension.
An alternative is to specify the extension separately, as shown following:
\setmainfont{texgyrepagella-regular}[
Extension = .otf ,
BoldFont = texgyrepagella-bold ,
... ]
If desired, an abbreviation can be applied to the font names based on the mandatory 'font name' argument:
\setmainfont{texgyrepagella}[
Extension = .otf ,
UprightFont = *-regular ,
BoldFont = *-bold ,
... ]
In this case texgyrepagella
is no longer the name of an actual font,
but is used to construct the font names for each shape;
the * is replaced
by 'texgyrepagella'.
Note in this case that UprightFont is required for constructing the font name of the normal font to use.
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:
\setmainfont{texgyrepagella}[
Path = /Users/will/Fonts/ ,
UprightFont = *-regular ,
BoldFont = *-bold ,
... ]
Note that XeTeX and LuaTEX are able to load the font without giving an extension,
but fontspec must know to search for the file;
this can be indicated by using the Path feature without an argument:
\setmainfont{texgyrepagella-regular}[
Path, BoldFont = texgyrepagella-bold,
... ]
My preference is to always be explicit and include the extension;
this also allows fontspec to automatically identify that the font should be loaded by filename.
In previous versions of the package,
the Path feature was also provided under the alias ExternalLocation,
but this latter name is now deprecated and should not be used for new documents.
some options
BoldFont = ⟨font name⟩
ItalicFont = ⟨font name⟩
BoldItalicFont = ⟨font name⟩
SlantedFont = ⟨font name⟩
BoldSlantedFont = ⟨font name⟩
SwashFont = ⟨font name⟩
BoldSwashFont = ⟨font name⟩
SmallCapsFont = ⟨font name⟩
UprightFont = ⟨font name⟩
\usepackage{xcolor}
\fontspec[Color=red]{Verdana} ...
\definecolor{Foo}{rgb}{0.3,0.4,0.5}
\fontspec[Color=Foo]{Verdana} ...
\fontspec[Color=red,Opacity=0.7]{Verdana} ...