1

When I try to compile a file using XeLaTeX and fontspec that uses the Dejavu Sans font (that's of course not already installed in the MacOS system), by \usepackage{pifont}, or if I want to use the font CMU Serif by \setsansfont{CMU Serif}, fontspec cannot find the fonts (error Package fontspec Error: The font "CMU Serif" cannot be found.).

I'm aware that one workaround is to add the directory that provides these fonts (/Library/TeX/Root/texmf-dist/fonts/opentype) as a symlink inside ~/Library/Fonts. However, doing so breaks some websites on Firefox (likely due to sandboxing and duplicate font issues), and Firefox is really that much more crucial than latex.

It's not possible that there is no other solution apart from either specifying the file path for each font or causing trouble on my entire MacOS system installation, to force fontspec to find a custom directory with fonts... Can anyone please help resolve this?

Related issue describing in more detail the conundrum: Fontspec package can't find "Latin Modern Mono" on MacOS/MacTeX

1
  • Welcome to tex.sx. Commented Apr 14, 2023 at 14:46

1 Answer 1

1

(a bit too long for comment) The fontspec manual mentions in 2.2 By file name how to load by filename which is not quite same as a full file path. For example on my system

\documentclass{article}

\usepackage{fontspec}

%\XeTeXtracingfonts1
\setmainfont{DejaVuSans}[
    Extension      = .ttf,
    BoldFont       = *-Bold,
    ItalicFont     = *-Oblique,
    BoldItalicFont = *-BoldOblique
]

\begin{document}

abcde

\textit{abcde}

\textbf{abcde}

\textbf{\textit{abcde}}
\end{document}

I used the \XeTeXtracingfonts1 in a first pass to have all details in the log file with using syntax \setmainfont{DejaVu Sans} and the symlinks in place. Then I could identify the font basenames (alternatively use the FontBook to get them).

Problem with the above is specifying the extension. I think I once had a problem (warning: I doubt very much my own paragraph here, because TeXLive will have same structure everywhere, so it must have been some other context where the fonts were not in TeXLive or were installed system wide on one computer and from TeXLive in another) of portability because on some system the font used was installed with .otf extension (i.e. in texmf-dist/fonts/opentype) and on some other with .ttf (in texmf-dist/fonts/truetype).

Reading (again) 2.2 By file name it appears perhaps the better syntax would be here:

\usepackage{fontspec}

\XeTeXtracingfonts1
\setmainfont{DejaVuSans}[
    Path,
    BoldFont       = *-Bold,
    ItalicFont     = *-Oblique,
    BoldItalicFont = *-BoldOblique
]

\begin{document}

abcde

\textit{abcde}

\textbf{abcde}

\textbf{\textit{abcde}}
\end{document}

This works on my mac os after having removed the symlink to texmf-dist/fonts/truetype but not sure if there is some cache involved. A priori it should work on pristine install also.

enter image description here

1
  • The main problem here is that one has to specify manually the fle basenames for Italic, Bold, and BoldItalic.
    – user691586
    Commented Apr 15, 2023 at 8:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .