Font works with \usepackage but not with \newfontfamily

ebgaramondfontsfontspecinstalling-fonts

I am trying to get someone else's thesis template to run, but the EBGaramond font is not working. I also have never used .cls files in latex, so I'm not sure if I'm missing something. In the .cls file, the line causing problems is:

\newfontfamily{\smallcaps}[RawFeature={+c2sc,+scmp}]{EB Garamond}

and the error is: Package fontspec Error: the font ''EB Garamond'' cannot be found

I have tried replacing "EB Garamond" with "ebgaramond" and "EBGaramond".
I followed these directions to make sure the font was installed. To check that it was working, I tried using the command \usepackage{ebgaramond} in another document, which worked fine, so there seems to be something wrong about the specific line above. Also, I'm not sure if this is relevant, but the previous user of this template was exclusively using Overleaf.

Best Answer

xelatex will not find fonts in the tex-live tree by name unless you have configured fontconfig to find them, so you could try replacing the internal font name EB Garamond by the file name EBGaramond-Regular.otf so the file can be found by kpathsearch rather than fontconfig (luatex should work the same way with either form).

To configure fontconfig you need a file such as

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
  <dir>/usr/local/texlive/2021/texmf-dist/fonts/opentype</dir>
  <dir>/usr/local/texlive/2021/texmf-dist/fonts/truetype</dir>
</fontconfig>

"somewhere" (Mine is called local.conf in /etc/fonts but the details on a Mac will be different). Then run fc-cache to rebuild its font cache.

See texdoc texlive

Section 3.4.4 System font configuration for XeTeX and LuaTeX

Related Question