When I compile a document using the CMU Serif font:

%!TeX program = xelatex
\documentclass{article}

\usepackage{fontspec}
\setmainfont{CMU Serif}

\begin{document}
Lorem ipsum...
\end{document}


I get an error: Package fontspec: The font "CMU Serif" cannot be found, even if the font is actually installed in /usr/share/texlive/texmf-dist/fonts/opentype/public/cm-unicode/.

I know that I can load the fond by giving a filename (several filenames with the variants), but why does \setmainfont{CMU Serif} not work?

EDIT : Several topics here mention a /.../fonts/conf/texlive-fontconfig.conf file, but there is no such file on my computer. I have no idea whether it is related to my problem, so i just mention it.

• have you tried lualatex instead of xelatex? xelatex is motoriously crankry about where it looks for fonts. I cannot get it to use texlive fonts on my Linux box. No issues what so ever with lualatex – daleif May 4 at 13:25
• linux systems need additional fontconfig setup if you want to call fonts by font name, see tug.org/texlive/doc/texlive-en/texlive-en.html#x1-330003.4.4 – Ulrike Fischer May 4 at 13:26
• On my system that config file lives in /opt/texlive/2021/texmf-var/fonts/conf/texlive-fontconfig.conf. From the PATH you gave it seems you are using a TeXLive from a Linux dist. No idea if they include texlive-fontconfig.conf – daleif May 4 at 13:29
• @UlrikeFischer see my EDIT : maybe is this the cause of my problem? – sparusaurata May 4 at 13:30
• please don't change the question title (most questions get solved:-) just mark the question as answerd by accepting the answer. – David Carlisle May 4 at 17:19

My setup is different than yours but you can probably adapt it. My version of texlive-fontconfig.conf has the following contents

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<dir>/opt/texlive/2021/texmf-dist/fonts/opentype</dir>
<dir>/opt/texlive/2021/texmf-dist/fonts/truetype</dir>
<dir>/opt/texlive/2021/texmf-dist/fonts/type1</dir>
</fontconfig>


You will need to adapt the first two <dir>'s to what fits your system. And it is recommended (David via chat) to delete the type1 line.

Once you have that proceed as described in

https://www.tug.org/texlive/doc/texlive-en/texlive-en.html#x1-330003.4.4

that worked fine on my system, where xelatex normally cannot use the TL fonts.

That is I did:

sudo cp texlive-fontconfig.conf /etc/fonts/conf.d/09-texlive.conf
sudo fc-cache -fsv

• It works, thanks a lot! – sparusaurata May 4 at 14:18