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
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 wasBaskervilleF
. If it finds the wrong font, you can tell it to show the top few matches. So,on my box gives me
It’s also possible to give more complex queries to either
luaotfload-tool
,fc-match
orfc-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 orkpsewhich 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
andLibreBskvl-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: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,will give you a big dump that includes
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.