[Tex/LaTex] xkeyval error when I try to use fontspec and OpenType fonts in XeLaTeX

fontsfontspecUbuntuxetexxkeyval

I can't seem to get XeLaTeX to load OpenType fonts using \fontspec. Section 4.2 of the fontspec documentation says that I need to load OpenType fonts by filename rather than font name, but when I compile the following:

\documentclass[letterpaper]{scrartcl}

    \usepackage{xltxtra}

    \fontspec[Path = /home/[MYHOME]/.fonts/]{lmroman10-regular.otf}
    \begin{document}

    0123456789.

    The quick brown fox jumped over the lazy dogs.

    ``firefly''

    \end{document}

XeLaTeX generates the following errors:

 [XeLaTeX] finished with exit code 1

./xelatexbase.tex:12:Undefined control sequence ... /home/[MYHOME]/.fonts/{lmroman10-regular.otf}

./xelatexbase.tex:12:Package xkeval Error: 'Path' undefined in families 'options' ... /home/[MYHOME]/.fonts/ 

I've verified that lmroman10-regular.otf is in /home/[MYHOME]/.fonts/. I must be doing something wrong with the Path argument, and I suspect it's something simple, but I don't see what.

I've posted the minimal example that generates this error, but documents using \fontspec with arguments that more closely track the examples in section 4 of the documentation do the same. The document compiles when I comment out \fontspec.

This on Ubuntu 10.10 with the latest full installation of TexLive from the repositories.

Best Answer

It works for me with a fully updated Tex Live 2010. Do not use the Ubuntu texlive packages when you want to use fontspec (or any other modern packages). The version in Ubuntu are now more than a year and a half old, and thus have many bugs that have long since been fixed. Install TeX Live directly.

There are a few other things worth pointing out:

  • The manual says (in section 4.2)

    [You may have fonts outside of] your system’s font directories.

    As ~/.fonts is a system font directory, you can load fonts by name from there.

  • I think fontspec loads the Latin Modern fonts by default. If you want to load them explicitly it is more convenient to load them from your systems TEXMF tree (TeX Live should include those fonts).

  • \fontspec in the preamble doesn't affect anything, as it changes the current font, and there is no current font in the preamble. Use \setmainfont instead.
  • In summary, to load the LM Roman 10 font explicitly from the TeX Live font dirs you should use

    \setmainfont[
      Extension = .otf,
      UprightFont = *-regular,
      BoldFont = *-bold,
      ItalicFont = *-italic,
      BoldItalicFont = *-bolditalic,
    ]{lmroman10}
    

    Note that the TeX Live font directories are searched automatically. You should probably do analogous things with \setsansfont and \setmonofont. Also, you will probably want to add the Ligatures=TeX option.

[Remark: XeLaTeX from MikTeX and LuaLaTeX on all systems can load fonts from the TEXMF tree by name.]

Related Question