LibreBaskerville Font Name – What is the Font Name of LibreBaskerville in XeTeX?

fontsxetex

I can load the package 'librebaskerville' but I can't seem to refer to it in commands that take the name of a font.

Here's a short .tex file to demonstrate:

\documentclass{article}

\usepackage{librebaskerville}

% All of these fail
%\newfontfamily{\smallcaps}[RawFeature={+c2sc,+scmp}]{librebaskerville}
\newfontfamily{\smallcaps}[RawFeature={+c2sc,+scmp}]{Libre Baskerville}
%\newfontfamily{\smallcaps}[RawFeature={+c2sc,+scmp}]{LibreBaskerville}

\begin{document}
Some text.
\end{document}

Running with latexmk -xelatex (on both Ubuntu 18.04 and OSX 12.4), this generates an error message like this:

(/usr/local/texlive/2020/texmf-dist/tex/latex/base/textcomp.sty))kpathsea:make_tex: Invalid filename `Libre Baskerville', contains ' '


! Package fontspec Error: The font "Libre Baskerville" cannot be found.

What name is needed to refer to the librebaskerville font in commands like \newfontfamily, \setmathsfont, and \setmathrm? Or how could I find out? (I already did a bunch of googling.)


Update: The above .tex file works on Overleaf.

Best Answer

Although the inimitable @egreg gave an answer that got to the root of your problem, nobody’s yet given a completely literal one, and someone who finds this page in a search might be looking for one.

A good way to find a font by name from the command line is

luaotfload-tool --find "Libre Baskerville" --fuzzy

If the name is correct, this will display the full path of the file.

If that doesn’t get you the exact match—if you had only remembered that it was some version of Baskerville—--fuzzy would have told you that the closest match was BaskervilleF. If it finds the wrong font, you can tell it to show the top few matches. So,

luaotfload-tool --find "Baskerville" --fuzzy --limit=4

on my box gives me

luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: Font "Baskerville" not found.
luaotfload | resolve : sequence of 3 lookups yielded nothing appropriate.
luaotfload | resolve : Cannot find "Baskerville" in index.
luaotfload | resolve : Looking for close matches, this may take a while ...
luaotfload | query : Distance from "baskerville": 1
    BaskervilleF
luaotfload | query : Distance from "baskerville": 3
    ADFBaskerville
    GFSBaskerville-Regular
luaotfload | query : Distance from "baskerville": 5
    BaskervilleF Bold
    Libre Baskerville
luaotfload | query : Distance from "baskerville": 6
    QTBasker-Bold

It’s also possible to give more complex queries to either luaotfload-tool, fc-match or fc-search, but the above is usually what you want.

At this point, you want to check for a file named LibreBaskerville.fontspec, with a filename search or kpsewhich LibreBaskerville.fontspec. If that existed, all configuration would be done for you and \setmainfont{LibreBaskerville} would load it. In this case, however, it does not.

Once you have the path, searching the directory will give you the filenames of the fonts in the family. In this case: LibreBaskerville-Bold.ttf, LibreBaskerville-Italic.ttf, LibreBaskerville-Regular.ttf and LibreBskvl-BoldItalic.ttf. The recommended way to load this family is by filename, like in egreg’s answer, although I usually do it slightly differently in case I need to re-use the same font family:

\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[LibreBaskerville]{
  Extension=.ttf,
  UprightFont    = *-Regular,
  ItalicFont     = *-Italic,
  BoldFont       = *-Bold,
  BoldItalicFont = LibreBskvl-BoldItalic,
  SmallCapsFont  = BaskervilleF-Regular.otf,
  SmallCapsFeatures={Letters=SmallCaps},
  Ligatures={Common,Discretionary,TeX}
}

% I don’t want to repeat all of the above multiple times when I select the
% same font more than once, and probably introduce inconsistencies.
\setmainfont{LibreBaskerville}
\newfontfamily\baskerville{LibreBaskerville}

However, there is also another way. If you tell luaotfload-tool to display font information and not just the filename, it will give you all the font’s internal names. So,

luaotfload-tool --find "Libre Baskerville" -i

will give you a big dump that includes

compatiblename: Libre Baskerville
        family: Libre Baskerville
      fontname: LibreBaskerville-Regular

and a number of others. Normally, fontspec should be able to find the font by one of these names, but it doesn’t always work.

Related Question