1

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.

  • 1
    Note that it is a good idea to mention which engine you are using. As e.e. lualatex is much more forgiven than xelatex. – daleif Oct 04 '22 at 13:08
  • Note you can also use the file name as well as the internal font name (this is required for xetex texlive fonts unless you have configured fontconfig to index texlive) – David Carlisle Oct 04 '22 at 13:13
  • Your document works without error for me in texlive 2022 xelatex and lualatex (with fontconfig set up for xetex) https://tex.stackexchange.com/a/619577/1090 – David Carlisle Oct 04 '22 at 13:16
  • @daleif Thanks! I just edited the question to say that I ran latexmk -xelatex. Is there anything else I need to do to indicate the engine? – Ben Kovitz Oct 04 '22 at 13:21
  • @DavidCarlisle Thanks! I will try upgrading to TeX Live 2022. And thanks for that link to your answer to a similar question: that might be the crucial piece of the puzzle. – Ben Kovitz Oct 04 '22 at 13:24
  • @BenKovitz 2022, 2021, 2020 are all the same as far as this is concerned. – David Carlisle Oct 04 '22 at 13:25
  • you can use LibreBaskerville-Regular.ttf if you want to load by file name – David Carlisle Oct 04 '22 at 13:27
  • @DavidCarlisle Hmm, \newfontfamily{\smallcaps}[RawFeature={+c2sc,+scmp}]{LibreBaskerville-Regular.ttf} got the same error as above. I'll try editing /etc/fonts/local.conf next. – Ben Kovitz Oct 04 '22 at 13:32
  • check your do works with luatex, also I have no idea where fontconfig looks for fonts on a mac (or ven if xetex uses fontconfig on a mac, you'll need to check) basically do whatever you would do to make a font known to safari – David Carlisle Oct 04 '22 at 13:35
  • @DavidCarlisle Well, it turns out that LibreBaskerville-Regular.otf worked! This even worked as the math font with mathspec. Would you like to post that as an answer? I can edit it to include the LaTeX code to get the math font. Small caps isn't working, but I can live with that. – Ben Kovitz Oct 04 '22 at 18:30

3 Answers3

1

If I look for the features of the LibreBaskerville font distributed with TeX Live in

.../texmf-dist/fonts/truetype/impallari/librebaskerville/

by doing

otfinfo -f $(kpsewhich LibreBaskerville-Regular.ttf)

I get

dlig    Discretionary Ligatures
frac    Fractions
kern    Kerning
liga    Standard Ligatures
ordn    Ordinals
sinf    Scientific Inferiors
sups    Superscript

which reveals that small caps are not supported.

To the contrary, BaskervilleF does support them.

\documentclass{article}
\usepackage{fontspec}

\setmainfont{LibreBaskerville}[ Extension=.ttf, UprightFont = -Regular, ItalicFont = -Italic, BoldFont = *-Bold, BoldItalicFont = LibreBskvl-BoldItalic, SmallCapsFont = BaskervilleF-Regular.otf, SmallCapsFeatures={Letters=SmallCaps,Scale=1.10791}, ]

\begin{document}

Baskerville \textsc{Baskerville}

\end{document}

enter image description here

However, it seems that BaskervilleF just scales down capitals. :-(

egreg
  • 1,121,712
  • Wow. It took me a day to get around to looking at your answer closely because I actually wasn't all that concerned with small capitals, just how to supply the name of the font to commands that need it. But now I see! I had no idea that you could specify so much in \setmainfont. I made two changes to get it to work on my computer: Extension=.otf and BoldItalicFont = *-BoldItalic, and now, not only do I have the spacious Libre Baskerville to counter my university's dissertation format's requirement of wide lines and small font sizes, I even have small caps! – Ben Kovitz Oct 05 '22 at 16:14
  • Great answer, as usual! Also, otfinfo -i will display the family names that the question was literally asking for, although if you have the filenames of the font family, it’s recommended to just use those. – Davislor Oct 09 '22 at 17:38
1

If you run the test document with lualatex it will confirm you have the font, and at the end of the log will show its full path. You can use the filename with fontspec which is easier to make work with xetex than the internal font name. In this case that is LibreBaskerville-Regular.otf

David Carlisle
  • 757,742
1

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.

Davislor
  • 44,045
  • Ah, I'm glad to see a direct answer to the question. I did not know about Scale=MatchLowercase. I'll be putting that to use. I'm getting the error message "Misplaced equals sign in key-value input on line 125" on \newfontfamily\baskerville{LibreBaskerville}. Any suggestions? – Ben Kovitz Oct 10 '22 at 13:01
  • I just fixed that error: a missing comma (I added it to your answer). It looks like Scale=MatchLowercase reduced the font size throughout the whole document, so I took that out. But I will use it later to scale Friz Quadrata, which is interspersed with the body text. Thanks! I'll accept this answer barring any surprises showing up in the next day or so. – Ben Kovitz Oct 10 '22 at 13:22