# Xelatex Fontspec Cannot Find Fonts

I've been working with a large document in Sharelatex for some time and I kept getting a fontspec error that it could not find the font file. However, despite this error message the document kept compiling normally, that is until I switched the font to Garamond. Now the document will only compile the sans-serif portion of the document.

Below is my MWE without the sans serif portion.

\documentclass[12pt]{scrbook}
\usepackage[paperwidth=7.5in, paperheight=9.25in, top=1in,   bottom=1.375in, left=1in, right=1in]{geometry}
\setlength{\parindent}{2em}

%Fonts
\usepackage{fontspec}
%This is ShareLaTeX Specific (or if the fonts are not installed in your system)
%-----------------------------------------------------------------------
% Garamond
\setmainfont[BoldFont=GARABD.otf,ItalicFont=GARAIT.otf]{GARAMOND.otf}

\begin{document}
Something is wrong! I am momentarily blinded and confused by moving, overlapping, translucent images that overwhelm my vision of the book I am reading. The room I sit in is visually a frenetic whirling mess. Abject fear grips me, first at the base of my spine, then it rips up my spine to my cortex and beyond. \par

\end{document}


Any ideas of how to fix this? I've tried altering the file names, but this has produced no result.

• Normally, you have to indicate only the name of the font family (not the name of the .otf file. Did you check the family name, as it is known by your system? – Bernard Jul 19 '16 at 17:20
• The problem here is that, by using ShareLatex, I have to upload the files off the system and then provide the file name. That's why I included the .otf, since it doesn't seem to work without it. – Richard Jul 19 '16 at 17:46
• They have an example of this here: sharelatex.com/project/578e6a78e0a7f0c46bcd6add – Richard Jul 19 '16 at 18:00
• Fixed it, for some reason it demands that I change the font name that SharLatex gives it to the one that matches the computer's name for it. – Richard Jul 19 '16 at 18:37

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.

# 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)}


The \set*font commands should accept a parameter Path=[Path] that points to the directory containing the files. This is only relevant if using fonts that are not known to the system. Otherwise you should provide the name of the font family as noted by bernard (first comment).