4

Perhaps I am missing something obvious here, but I am a bit confused and therefore coming up with this question.

I want to change the default "Latin Modern" font to something else. At the moment, to change it to one of the built-in fonts shipped with the TeX distribution I have.

I headed over to the fonts directory located at usr/local/texlive/2021/texmf-dist/fonts on my Mac OS to see which fonts I can use (other than downloading fonts from the internet and using them).

For example, I possibly have the font "EB Garamond" installed, since I can see the following files in the above directory:

fonts/
|- opentype/public/ebgaramond/EBGaramond-Regular.otf
|- opentype/public/ebgaramond/EBGaramond-Italic.otf
|- opentype/public/ebgaramond/EBGaramond-Bold.otf

and more. Other EB Garamond files are located in the tfm directory.

Now consider the following code:

% !TEX TS-program = XeLaTeX
\documentclass[a4paper]{article}
\usepackage{fontspec}
\setmainfont{EB Garamond}

\begin{document} Regular text. \textbf{Bold} text. \end{document}

I compile the file with XeLaTeX and get the following message:

! Package fontspec Error: The font "EB Garamond" cannot be found.

For immediate help type H <return>.

Now if I change the above line to \setmainfont{EBGaramond-Regular.otf} then I get the following message:

LaTeX Font Warning: Font shape `TU/EBGaramond-Bold.otf(0)/b/n' undefined
(Font)              using `TU/EBGaramond-Bold.otf(0)/m/n' instead on input line 9.

All I thought I was doing was following the MWE given in this answer.

Then what is wrong with my font specification?

Moreover, how can I systematically check whether this or other font is installed, and how can I (systematically) find its "family name" (EB Garamond in this instance) to be passed into the \setmainfont{THE FONT FAMILY NAME} command?

tush
  • 1,115

2 Answers2

8

xetex will not find texlive fonts by the internal font name unless you make them known to fontconfig.

texlive comes with a fontconfig file but does not install it by default to avoid making system changes. There are various ways to add this depending how fontconfig is set up.

I have a file /etc/fonts/local.conf that contains

<?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>

after adding this run fc-cache -f to get fontconfig to re-cache the font list.

See

Section 3.4.4 System font configuration for XeTEX and LuaTEX

in the texlive manual (texdoc texlive).

David Carlisle
  • 757,742
  • 1
    Thanks a lot for your quick reply! I accepted Mico's answer but your approach gives a lot of insight nonetheless. – tush Oct 20 '21 at 15:26
  • texlive-en.pdf says to copy that .conf file to /etc/fonts/conf.d/09-texlive.conf. So which target should actually be used, that or /etc/fonts/local.conf ? – murray Nov 06 '21 at 01:09
  • @murray either works, depending on how you view it. Placing it in conf.d makes it an extended but standard system setting, placing it in local.conf makes it a non standard local addition, but it only affects how you think of it, and what perhaps happens if you do a full operating system update, it doesn't affect what fontconfig actually does. (late reply:-) – David Carlisle Jul 27 '23 at 13:07
7

If you don't want to change the fontconfig file, you could add an explicit Path option to the argument of \setmainfont to get your document to compile under XeLaTeX if you refer to fonts by their (implicit) name rather than by the otf or ttf filename.

Since the EB Garamond OpenType font family features 2 "regular" font weights -- 'Regular' and 'Medium' -- and 3 "bold" font weights -- 'Semibold', 'Bold', and 'ExtraBold' -- in both upright and italic font shapes, it's probably a good idea to switch from using font names to using filenames, in order to inform LaTeX exactly which fonts should be used in your document, by setting explicit filename values for the options UprightFont, ItalicFont, BoldFont and BoldItalicFont. If you use file names rather than font names, it's no longer necessary to set the Path option under XeLaTeX.

The following code runs under both XeLaTeX and LuaLaTeX.

enter image description here

% !TEX TS-program = XeLaTeX
\documentclass{article}
\usepackage{fontspec}

\begin{document}

\setmainfont{EBGaramond}[% %Path=/usr/local/texlive/2021/texmf-dist/fonts/opentype/public/ebgaramond/, Extension = .otf , UprightFont = -Regular, ItalicFont = -Italic, BoldFont = -SemiBold, BoldItalicFont = -SemiBoldItalic]

Regular. \textit{Italic.} \textbf{Semibold.} \textit{\textbf{Semibold-italic.}}

\setmainfont{EBGaramond}[% %Path=/usr/local/texlive/2021/texmf-dist/fonts/opentype/public/ebgaramond/, Extension = .otf , UprightFont = -Medium, ItalicFont = -MediumItalic, BoldFont = -ExtraBold, BoldItalicFont = -ExtraBoldItalic]

Medium. \textit{Medium-italic.} \textbf{Extrabold.} \textit{\textbf{Extrabold-italic.}} \end{document}

Mico
  • 506,678