Xelatex Fontspec Cannot Find Fonts
With setmainfont
you're essential building case-sensitive font paths.
- Path=working directory for fonts
- BoldFont=filename segment of path
- ItalicFont=filename segment of path
- Extension=file extension of path
You're code does not work because you are telling fontspec to look in all paths like this (example shows paths for bold font):
/usr/local/texlive/2016/texmf-dist/fonts/opentype/GARABD.otf/GARAMOND.otf
/usr/local/texlive/2016/texmf-dist/fonts/truetype/GARABD.otf/GARAMOND.otf
/usr/local/texlive/2016/texmf-dist/fonts/type1/GARABD.otf/GARAMOND.otf
... any other font directory in your environment/GARABD.otf/GARAMOND.otf
TeX Default Known Font Path Segments
On Unix-based computers, you can figure out the TeX font folders with:
cat $(kpsewhich -var-value TEXMFSYSVAR)/fonts/conf/texlive-fontconfig.conf
which evaluates to /home/texlive/2016/texmf-var/fonts/conf
for 2016, or for the appropriate year of your installed version.
Otherwise fontspec
does have an automatic path finding mechanism for system fonts, where you can just do \setmainfont{Arial}
, but this is not as explicit and therefore in my experience leads to problems with cross-platform or cross-computer compatibility.
See How do I load a texlive font with fontspec?
Empowering YOU to DO it Yourself
Find folder where you files reside (without knowing your OS, I will just make up something)
Given fonts are in same folder with these names:
/Library/Fonts/GARABD.otf
/Library/Fonts/GARAIT.otf
/Library/Fonts/GARAMOND.otf
How would I set up fontspec
for this?
\usepackage{fontspec}
\setmainfont[%
Path = /Library/Fonts/ ,
UprightFont = MOND ,
BoldFont = BD ,
ItalicFont = IT ,
Extension = .otf
]{GARA} % {contains only what is common among all file names (usually basename of font family)}
Notes
Many pro fonts use dashes in their file names to separate the variants, so you'll often see the following:
/Library/Fonts/DejaVuSansCondensed.ttf
/Library/Fonts/DejaVuSans.ttf
/Library/Fonts/DejaVuSans-ExtraLight.ttf
/Library/Fonts/DejaVuSansCondensed-Bold.ttf
/Library/Fonts/DejaVuSans-BoldOblique.ttf
/Library/Fonts/DejaVuSansCondensed-Oblique.ttf
/Library/Fonts/DejaVuSansCondensed-BoldOblique.ttf
/Library/Fonts/DejaVuSans-Oblique.ttf
/Library/Fonts/DejaVuSans-Bold.ttf
How would i set this up? Well, unfortunately fontspec
does not support all of those fonts simultaneously, so I might either settle for less and use \setmainfont
or load them all by breaking them up into families e.g. \newfontfamily\dejavucondensed
\newfontfamily\dejavu
\newfontfamily\dejavulight
.
\usepackage{fontspec}
\newfontfamily\dejavu[%
Path = /Library/Fonts/ ,
UprightFont = ,
BoldFont = -Bold ,
ItalicFont = -Oblique ,
Extension = .ttf
]{DejaVuSans} % {contains only what is common among all file names (usually basename of font family)}