I am using xelatex, on CentOS 7, with font files that are in the local folder. (These fonts work on a different computer using Ubuntu.)

I am using XeTeX, from TexLive 2022. I have tried several different syntaxes for getting this work, which I read from different sites, and none of them work. How can I get xelatex to find the font files and use them?

Here is the latest code which does not work:

\setmainfont{<path to current directory/fontname.otf>}[
Bold = <path to current directory/name.otf>
Italic = <path to current directory/name.otf>

The error I get is:

! Package fontspec Error: The font "<fontname.otf>" cannot be found.

It does not display the path in the error, just the font name. I have tried putting {fontname} both before and after the type and name specifiers, neither of which worked. I have tried putting the whole path into each one, and using the "Path" variable, none of which worked. I tried other various ideas I saw in different scripts, none of which worked. What is the proper syntax?

  • 2
    try using lualatex instead, xelatex is very stubborn about where it looks for fonts, lualatex is not. Unless you really needed it should you probably not use xelatex use lualatex instead.
    – daleif
    Nov 16, 2022 at 16:36
  • lualatex can't find it either.
    – Machinus
    Nov 16, 2022 at 16:42
  • 1
    I assume you did not actually write /usepackage but the proper \usepackage? What happens when you omit <path to current directory>?
    – schtandard
    Nov 16, 2022 at 16:56
  • Oops, my post was wrong, but the script was right. Thanks for pointing that out. If I omit the path and keep the suffix, I get the same error. If I omit the path and the suffix, I get the same error after TeX tries to find the font in its own fonts folder and fails.
    – Machinus
    Nov 16, 2022 at 19:37
  • In that case you will have to share a full MWE. If I to \setmainfont{foo.otf} with LuaLaTeX and foo.otf in the compilation directory, it works just fine.
    – schtandard
    Nov 16, 2022 at 23:04

1 Answer 1


If the filenames are SomeFont-Regular.otf, SomeFont-Bold.otf and SomeFont-Italic.otf, You would wantsomething like

  UprightFont = {*-Regular},
  BoldFont = {*-Bold},
  ItalicFont = {*-Italic},
  Path = {./},
  Extension = {.otf}

Where the curly braces are out of an abundance of caution.

If you load the font in more than one place, put all that in one block rather than having multiple copies of it that will probably become inconsistent. For example,

  UprightFont = {*-Regular},
  BoldFont = {*-Bold},
  ItalicFont = {*-Italic},
  Path = {./},
  Extension = {.otf}


You could also put that \defaultfontfeatures[SomeFont] command into a file named SomeFont.fontspec, which would let you write \setmainfont{SomeFont} in the main document and make all your tweaks to the .fontspec file.

  • I have been trying to get this to work for a week. I can't tell why this does not work. On my system, no matter which of these ways I specify the font, I get the error: ! Package fontspec Error: The font <fontname> cannot be found." I am using XeTeX from Tex-Live 2022.
    – Machinus
    Nov 22, 2022 at 17:35
  • @Machinus Can you post a MWE and the .log file? Is fc-cache correctly configured, such that fc-list works?
    – Davislor
    Nov 22, 2022 at 19:32
  • Also, what are the actual filenames? Are they set readable with chmod 644 *.otf? Is the directory readable and executable with chmod 755 .?
    – Davislor
    Nov 22, 2022 at 19:35
  • And are you running XeTeX from the project directory, as your current working directory?
    – Davislor
    Nov 22, 2022 at 19:37
  • @Davislor would it make sense to use here only Path without specifying directory as the OP specified the font came from an Ubuntu so perhaps it is needed same document compiles also on original Ubuntu where the font is not located in the document source directory? I have not tested using Path without argument will work, but from fontspec doc, it looks as if it should.
    – user691586
    Apr 16, 2023 at 7:11

You must log in to answer this question.

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