[Tex/LaTex] ‘table index is nil’ error when using the Avenir font with fontspec + luatex

errorsfontspecluatex

According to the fontspec package's user manual (2017/03/31 v2.6a, Section 5.1, p. 12)

Fonts known to LuaTEX […] may be loaded by their standard names as you'd speak them out loud, such as Times New Roman or Adobe Garamond. […]
The simplest example might be something like
\setmainfont{Cambria}[...]
[…] The 'font name' can be found in various ways, such as by looking in the name listed in a application like Font Book on Mac OS X.

My operating system is Mac OS X. The following screenshot shows the Times New Roman font in in my Font Book application.

The Times New Roman font in Font Book

The following screenshot shows the Avenir font name in my Font Book application.

The Avenir font in Font Book

The following LaTeX document sets the main font of the document to Times New Roman.

\documentclass{report}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\begin{document}
Hello, world!
\end{document}

Processing this document with the LuaLaTeX format (i.e. with the LuaLaTeX "engine") results in the following pdf, as expected:

Hello, world!

However, replacing 'Times New Roman' with 'Avenir' and reprocessing the document with the LuaLaTeX format results in no pdf, and the following error message:

ERROR: table index is nil.

— TeX said —

\scan_stop:
l.3 \setmainfont{Avenir}

— HELP —
From the .log file…

The lua interpreter ran into a problem, so the remainder of this lua chunk will be ignored.

What's the problem? Why doesn't the Avenir example work whereas the Times New Roman one does?


Operating System: macOS Sierra Version 10.12.5
MacTex distribution: MacTeX-2017
LuaTeX: Version 1.0.4

Best Answer

I don't really know why LuaLaTeX is not able to associate Avenir Book to the upright font; with XeLaTeX it seems to go well.

Actually, if one looks closely, when XeLaTeX is used, the .ttc font file in the /System/Library/Fonts folder is used, not one of the files in /Library/Fonts. Perhaps this is the issue when LuaLaTeX comes into play, because luaotfload has a different strategy for choosing fonts.

For LuaLaTeX you need to specify the font names (at least in this case):

\documentclass{report}
\usepackage{fontspec}

\setmainfont{Avenir}[
  UprightFont=* Book,             % or Light
  ItalicFont=* Book Oblique,      % or Light Oblique
  BoldFont=* Black,               % or Medium
  BoldItalicFont=* Black Oblique, % or Medium Oblique
]

\begin{document}

Hello, world! \fontname\font

{\itshape Hello \fontname\font}

{\bfseries Hello \fontname\font}

{\bfseries\itshape Hello \fontname\font}

\end{document}

This would be needed also with XeLaTeX if you want Medium instead of Black.

Output with LuaLaTeX

enter image description here

Output with XeLaTeX

enter image description here

Output with XeLaTeX and just \setmainfont{Avenir}

enter image description here