[Tex/LaTex] luaotfload can’t find fonts

fontsluaotfloadluatexmiktex

I am using MiKTeX 2.9 on Windows. luaotfload does not find the fonts located in the MiKTeX-maintained root directory (which is C:\Program Files (x86)\MiKTeX 2.9\ on my system) and I am therefore unable to load them directly with LuaLaTeX and fontspec. My distribution and packages seem up-to-date; where could the problem come from?

Here is a minimal working example:

\documentclass{minimal}

\usepackage{fontspec}
\setmainfont{Latin Modern Roman}
\setsansfont{Latin Modern Sans}
\setmonofont{Latin Modern Mono}

\begin{document}
Hello world.
\end{document}

I know that fontspec loads Latin Modern fonts as the default fonts but specifying them manually should work; however, I get the following errors:

The font "LatinModernRoman" cannot be found.
The font "LatinModernSans" cannot be found.
The font "LatinModernMono" cannot be found.

It appears that, indeed, they are not in the database otfl-names.lua. And the situation is the same for all other fonts in MiKTeX directories. However, there is no problem with the fonts located in my local TEXMF: they do appear in the database and I can access them easily (well… not completely! — see my second question). I tried to play with the OSFONTDIR environment variable but got no luck. With XɘTeX, the previous example works fine (although fonts in local TEXMF “cannot be loaded by font name, only file name” [from fontspec documentation]).

I have a second question about fonts which, this time, are in the database otfl-names.lua but can’t be accessed directly by their full name because of their unusual subfamily parameter. This issue is discussed here and here. It seems the situation has not changed, has it?

Any clarification on those points is welcome.

Best Answer

I've finally found a solution (with the hint by Ulrike Fischer): Simply edit (with administrator rights):

C:\Program Files (x86)\MiKTeX 2.9\tex\luatex\lualibs\lualibs-dir.lua

And paste add these lines to the filter (around line 95) just before "P(1)"

P("(")  / "%%(" +
P(")")  / "%%)" +

The brackets will be escaped and therefore the fonts in the "program files (x86)/miktex" folder can be found.

Related Question