Package fontspec error the font cmu serif cannot be found

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} ...

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.

David Carlisle's user avatar

asked May 4, 2021 at 13:22

sparusaurata's user avatar

11

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

answered May 4, 2021 at 14:09

daleif's user avatar

daleifdaleif

50.9k4 gold badges80 silver badges149 bronze badges

1

Thought I would share another workaround, specifically for CMU fonts. Let’s say you want to be sure your file builds on any MiKTeX setup, and you want to use CMU for main, sans and mono fonts. In this case, as @u-fischer noticed, you can use font file names, instead of the font name. However, in this case you’ll have to also manually list file names for Bold, Italic and BoldItalic fonts. For some fonts it’s easy, e.g., for XITS font files are named xits-regular.otf, xits-bold.otf etc., but it’s not the case with CMU.

Instead of using font names like this

documentclass{article}

usepackage{fontspec}

setmainfont{CMU Serif}
setsansfont{CMU Sans Serif}
setmonofont{CMU Typewriter Text}

% needed if you use cyrillic symbols
newfontfamilycyrillicfont{CMU Serif}
newfontfamilycyrillicfontsf{CMU Sans Serif}
newfontfamilycyrillicfonttt{CMU Typewriter Text}

begin{document}
        а {bfseries a {itshape a}} {itshape a}
        
textsf{а {bfseries a {itshape a}} {itshape a}}

texttt{а {bfseries a {itshape a}} {itshape a}}
end{document}

Which fails without the <rejectfont> workaround from above, use font file names like this

documentclass{article}

usepackage{fontspec}

setmainfont[
    BoldFont={cmunbx.otf},
    ItalicFont={cmunti.otf},
    BoldItalicFont={cmunbi.otf}
]{cmunrm.otf} % {CMU Serif}
setsansfont[
    BoldFont={cmunsx.otf},
    ItalicFont={cmunsi.otf},
    BoldItalicFont={cmunso.otf}
]{cmunss.otf} % {CMU Sans Serif}
setmonofont[
    BoldFont={cmuntb.otf},
    ItalicFont={cmunit.otf},
    BoldItalicFont={cmuntx.otf}
]{cmuntt.otf} % {CMU Typewriter Text}

% needed if you use cyrillic symbols
newfontfamilycyrillicfont[
    BoldFont={cmunbx.otf},
    ItalicFont={cmunti.otf},
    BoldItalicFont={cmunbi.otf}
]{cmunrm.otf}   % {CMU Serif}
newfontfamilycyrillicfontsf[
    BoldFont={cmunsx.otf},
    ItalicFont={cmunsi.otf},
    BoldItalicFont={cmunso.otf}
]{cmunss.otf} % {CMU Sans Serif}
newfontfamilycyrillicfonttt[
  BoldFont={cmuntb.otf},
  ItalicFont={cmunit.otf},
  BoldItalicFont={cmuntx.otf}
]{cmuntt.otf} % {CMU Typewriter Text}

begin{document}
        а {bfseries a {itshape a}} {itshape a}
        
textsf{а {bfseries a {itshape a}} {itshape a}}

texttt{а {bfseries a {itshape a}} {itshape a}}
end{document} 

Which should work on any MiKTeX setup.

  • Index
  • » Applications & Desktop Environments
  • » [SOLVED] [luatex/texlive]: fontspec Error: font «Arial» can’t be found

Pages: 1

#1 2020-08-13 12:26:39

newsboost
Member
Registered: 2016-07-24
Posts: 155

[SOLVED] [luatex/texlive]: fontspec Error: font «Arial» can’t be found

Hi all,

I haven’t used latex for some years and I see lualatex is the new kid in town, and it’s already installed on my side (I think as part of texlive-most). I got a document that is being compiled using:

Latexmk: This is Latexmk, John Collins, 17 Apr. 2020, version: 4.69a.
Latexmk: applying rule 'pdflatex'...
Rule 'pdflatex': File changes, etc:
...
...
------------
Running 'lualatex --shell-escape  -recorder  "my_document.tex"'
------------
This is LuaHBTeX, Version 1.12.0 (TeX Live 2020/Arch Linux)
 system commands enabled.
...
LaTeX2e <2020-02-02> patch level 5
 L3 programming layer <2020-06-03> (./some_report.cls
Document Class: some_report 2014/09/23 v2.0 Custom SOME LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/fleqn.clo)
(/usr/share/texmf-dist/tex/latex/base/size11.clo)
(/usr/share/texmf-dist/tex/generic/iftex/ifluatex.sty
(/usr/share/texmf-dist/tex/generic/iftex/iftex.sty))
(/usr/share/texmf-dist/tex/latex/fontspec/fontspec.sty
(/usr/share/texmf-dist/tex/latex/l3packages/xparse/xparse.sty
(/usr/share/texmf-dist/tex/latex/l3kernel/expl3.sty
(/usr/share/texmf-dist/tex/latex/l3backend/l3backend-pdfmode.def))
(/usr/share/texmf-dist/tex/latex/l3packages/xparse/xparse-generic.tex))
(/usr/share/texmf-dist/tex/latex/fontspec/fontspec-luatex.sty
(/usr/share/texmf-dist/tex/latex/base/fontenc.sty)
(/usr/share/texmf-dist/tex/latex/fontspec/fontspec.cfg)))
luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: "Font Arial not found.".
luaotfload | resolve : sequence of 3 lookups yielded nothing appropriate.

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

For immediate help type H <return>.
 ...

l.195 newfontfamily
                  sometitlepagefont{Tahoma}

I’m not allowed to share the document, but if needed, maybe I could make a minimal working document… I hope however we generally speaking maybe could solve it… I’ve tried to guess at which font package to install, e.g. «yay -S ttf-merge-one» and currently have both aur/urw-arial and extra/ttf-croscore installed + texlive-most. Not solved. Then I came across https://www.tug.org/fonts/getnonfreefonts/ and tried «texlua install-getnonfreefonts» and installing locally (to avoid possibly conflicts with package managers aur/pacman): «getnonfreefonts —user -a»… Still not working. Finally, the second-latest thing I tried was to follow https://wiki.archlinux.org/index.php/Microsoft_fonts and copy all fonts — but I still get the same error with the «Arial»-font… Last thing I tried was deleting ~/.texlive and run luatex again (it was slower, and wrote «luaotfload | db : Font names database not found, generating new one» + «luaotfload | db : This can take several minutes; please be patient» so I hoped this would work) — but also that failed…

Now I don’t have any more ideas… I’m hoping there’s a font/latex/luatex user who can/could guide me a bit and help solve this problem? I would be grateful for possible solutions/ideas, thanks…

Last edited by newsboost (2020-08-13 15:55:27)

#2 2020-08-13 12:38:06

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,833
Website

Re: [SOLVED] [luatex/texlive]: fontspec Error: font «Arial» can’t be found

I use xelatex, not lualatex, but I believe they handle fonts similarly through fontspec: are you loading the fontspec package?  If so, it will depend on fontconfig for identifying fonts, right?  What does `fc-match Arial` return?


«UNIX is simple and coherent…» — Dennis Ritchie, «GNU’s Not UNIX» —  Richard Stallman

#3 2020-08-13 14:14:57

newsboost
Member
Registered: 2016-07-24
Posts: 155

Re: [SOLVED] [luatex/texlive]: fontspec Error: font «Arial» can’t be found

Trilby wrote:

I use xelatex, not lualatex, but I believe they handle fonts similarly through fontspec: are you loading the fontspec package?  If so, it will depend on fontconfig for identifying fonts, right?  What does `fc-match Arial` return?

The fontspec package is loaded via a .cls-file that the document uses:

usepackage{fontspec}
setmainfont{Calibri}
newfontfamilysomeheadingfont{Cambria}
newfontfamilysomeaddressfont{Arial}
newfontfamilysometitlepagefont{Tahoma}

It’s weird, I don’t know about the «fc-match»-command, but this is the output:

$ fc-match Arial
arial.ttf: "Arial" "Regular"

It seems incorrect, when the font fails to load, based on this? But I don’t know enough about how these things works — appreciate your help, thanks!

#4 2020-08-13 14:24:50

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,833
Website

Re: [SOLVED] [luatex/texlive]: fontspec Error: font «Arial» can’t be found

Out of curiosity, can you try xelatex and post the errors it produces if it still fails.


«UNIX is simple and coherent…» — Dennis Ritchie, «GNU’s Not UNIX» —  Richard Stallman

#5 2020-08-13 14:47:16

newsboost
Member
Registered: 2016-07-24
Posts: 155

Re: [SOLVED] [luatex/texlive]: fontspec Error: font «Arial» can’t be found

Trilby wrote:

Out of curiosity, can you try xelatex and post the errors it produces if it still fails.

Yeah, no problem, that also won’t work:

(/usr/share/texmf-dist/tex/latex/base/fleqn.clo)
(/usr/share/texmf-dist/tex/latex/base/size11.clo)
(/usr/share/texmf-dist/tex/generic/iftex/ifluatex.sty
(/usr/share/texmf-dist/tex/generic/iftex/iftex.sty))

! Must be compiled with lualatex. Or even better: 'latexmk -lualatex main.tex' 
.

par 
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.202 fi
         
? q
OK, entering batchmode%                                                 

I don’t understand how that font-stuff works… Any ideas? I would be happy to try :-)

#6 2020-08-13 14:56:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,833
Website

Re: [SOLVED] [luatex/texlive]: fontspec Error: font «Arial» can’t be found

Sorry, I guess your document has lualatex specifics.  I’m not familiar with lualatex errors, so I was hoping to see if it’d replicate with xelatex — but there’s a different error with that.  From what I know of it, lualatex *should* use font-config to get system fonts, and as fc-match finds Arial, lualatex should as well — so I’m not sure why it’s failing.


«UNIX is simple and coherent…» — Dennis Ritchie, «GNU’s Not UNIX» —  Richard Stallman

#7 2020-08-13 15:05:01

newsboost
Member
Registered: 2016-07-24
Posts: 155

Re: [SOLVED] [luatex/texlive]: fontspec Error: font «Arial» can’t be found

Yeah, ok… Thanks a lot for the suggestions anyway,luatex is also new to me! :-)

UPDATE: Oh, figured it out after spending TOO MANY HOURS looking the wrong places… I used fonts from here: https://wiki.archlinux.org/index.php/Microsoft_fonts — the instructions tells to «chmod 644 /usr/share/fonts/WindowsFonts/*». I didn’t think too much about it. When rebuilding font cache as root, there are no problems. But for things to work as a normal user, I had to do……………. (so simple, as root)…

chmod +x /usr/share/fonts/WindowsFonts

So the directory was missing the executable permission (I began noticing something about permissions)… Damn… Thanks again for the help, I’m happy it works now! :-)

Last edited by newsboost (2020-08-13 15:54:15)

#8 2020-08-13 15:36:27

progandy
Member
Registered: 2012-05-17
Posts: 5,071

Re: [SOLVED] [luatex/texlive]: fontspec Error: font «Arial» can’t be found

You can try to update the luatex font database and look at which font files are scanned with

luaotfload-tool -uvvvv >fontdbupdates.log

The fonts currently in the database can be listed with

luaotfload-tool --list=format

Last edited by progandy (2020-08-13 15:43:21)


| alias CUTF=’LANG=en_XX.UTF-8@POSIX ‘ |

#9 2020-08-13 15:57:49

newsboost
Member
Registered: 2016-07-24
Posts: 155

Re: [SOLVED] [luatex/texlive]: fontspec Error: font «Arial» can’t be found

Thanks progandy, I didn’t knew these commands — but I was also looking for something like those commands… Now I also know these commands, if something similar happens in the future…

Last edited by newsboost (2020-08-13 15:58:17)

Asked
11 months ago

Viewed
413 times

i was trying to write my paper with a latex template. when i compiled it, this file was giving following error:

Package fontspec Error: The font "Kaiti SC Regular" cannot be found.

I’m using macOS M1, version 11.3.1.
the full log file:

./thuthesis.cls:994: Package fontspec Error: The font "Kaiti SC Regular" cannot be found.

For immediate help type H <return>.
 ...                                              
                                                  
l.994 thu@set@cjk@font
                       

./thuthesis.cls:994: Package fontspec Error: The font "Kaiti SC Regular" cannot be found.

For immediate help type H <return>.
 ...                                              
                                                  
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Cannot use XeTeXfeaturename with nullfont; not an AAT or Graphite font.
<argument> XeTeXfeaturename l_fontspec_font 
                                              3
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Cannot use XeTeXisexclusivefeature with nullfont; not an AAT or Graphite font.
<argument> ...isexclusivefeature l_fontspec_font 
                                                  3>0
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Cannot use XeTeXselectorname with nullfont; not an AAT or Graphite font.
<argument> XeTeXselectorname l_fontspec_font 
                                               3space numexpr 3-1relax 
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Cannot use XeTeXfeaturename with nullfont; not an AAT or Graphite font.
<argument> XeTeXfeaturename l_fontspec_font 
                                              3
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Cannot use XeTeXisexclusivefeature with nullfont; not an AAT or Graphite font.
<argument> ...isexclusivefeature l_fontspec_font 
                                                  3>0
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Cannot use XeTeXselectorname with nullfont; not an AAT or Graphite font.
<argument> XeTeXselectorname l_fontspec_font 
                                               3space numexpr 3-1relax 
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Missing endcsname inserted.
<to be read again> 
                   numexpr 
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Missing endcsname inserted.
<to be read again> 
                   numexpr 
l.994 thu@set@cjk@font
                       

./thuthesis.cls:994: LaTeX Error: Missing begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Extra endcsname.
<recently read> endcsname 
                           
l.994 thu@set@cjk@font
                       

./thuthesis.cls:994: Package fontspec Error: The font "Kaiti SC Bold" cannot be found.

For immediate help type H <return>.
 ...                                              
                                                  
l.994 thu@set@cjk@font
                       

./thuthesis.cls:994: Package fontspec Error: The font "Kaiti SC Bold" cannot be found.

For immediate help type H <return>.
 ...                                              
                                                  
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Cannot use XeTeXfeaturename with nullfont; not an AAT or Graphite font.
<argument> XeTeXfeaturename l_fontspec_font 
                                              3
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Cannot use XeTeXisexclusivefeature with nullfont; not an AAT or Graphite font.
<argument> ...isexclusivefeature l_fontspec_font 
                                                  3>0
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Cannot use XeTeXselectorname with nullfont; not an AAT or Graphite font.
<argument> XeTeXselectorname l_fontspec_font 
                                               3space numexpr 3-1relax 
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Cannot use XeTeXfeaturename with nullfont; not an AAT or Graphite font.
<argument> XeTeXfeaturename l_fontspec_font 
                                              3
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Cannot use XeTeXisexclusivefeature with nullfont; not an AAT or Graphite font.
<argument> ...isexclusivefeature l_fontspec_font 
                                                  3>0
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Cannot use XeTeXselectorname with nullfont; not an AAT or Graphite font.
<argument> XeTeXselectorname l_fontspec_font 
                                               3space numexpr 3-1relax 
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Missing endcsname inserted.
<to be read again> 
                   numexpr 
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Missing endcsname inserted.
<to be read again> 
                   numexpr 
l.994 thu@set@cjk@font
                       
./thuthesis.cls:994: Extra endcsname.
<recently read> endcsname 
                           
l.994 thu@set@cjk@font
                       
)

asked Mar 11, 2022 at 4:23

hui deng's user avatar

1

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Package caption error caption outside float
  • Package biblatex error incompatible package ucs
  • P31e1 0008 ev hev hv system interlock error evc 305
  • Package babel error unknown option russian either you misspelled it
  • P31b8 leaf ошибка

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии