fontspec
fontspec copied to clipboard
loading "lua fonts"
I have been playing around with "lua fonts" where the font definitions are stored in a lua files. (The examples are in https://github.com/u-fischer/lua-font-pond/ in the latex folder, some resources are in the texmf folder).
Basically it means that I have to load the font like this if the lua-file is stored in the current folder:
\font\duckchessfamily = "[luafont-duckchess.lua]:mode=node;+liga;+tlig;original=latinmodernsans"
This lookup can be easily made also with fontspec
\newfontface\duckchessfamily{latex-font-chess.lua}[Path,RawFeature={original=latinmodernsans}]
But if the font is in the texmf-tree (in the tex subfolder) then the only syntax that seems to work is:
\font\duckchessfamily = "file:luafont-duckchess.lua:mode=node;+liga;+tlig;original=latinmodernsans"
and I can't find no way to reproduce this with fontspec. Could some option to force this lookup with luatex be added?
Thanks for the suggestion Ulrike.
I can switch the file load syntax from [#1] to “file:#1” (it’s gone back and forth a couple times — usually due to compatibility/bugs) and add a keyval for “original”. If you were to invent an optimal interface syntax here, how do you think it would look?
Actually after some sleep I'm no longer sure that I want the file syntax. The problem with it is that it constantly triggered the recreation of the database (and so slowed down the compilation) and I had to manipulate luaotfload-database.lua to avoid it. But a better option is to use the [..]
syntax together with a kpse
search. This has the addition benefit that it allows to store the lua-files in the tds
into fonts/misc
which imho is a much more fitting place then tex
.
\documentclass[parskip=full]{scrartcl}
%\font\duckchessfamily = "[\directlua{tex.sprint(kpse.find_file("latex-font-demo-rule-texmf-fontmisc.lua","misc fonts"))}]:mode=node;+liga;+tlig;original=latinmodernsans" at 20pt
\usepackage{fontspec}
%This lua font is currently in texmf/tex/generic/luafont
\newfontface\duckchessfamily
{luafont-duckchess.lua}[Path=
\directlua{tex.sprint(
luatexbase.registernumber("catcodetable@latex"),
file.pathpart(kpse.find_file("luafont-duckchess.lua")).."/"
)}]
%This lua font is in texmf/fonts/misc/luafont
\newfontface\rulefontface
{latex-font-demo-rule-texmf-fontmisc.lua}[Path=
\directlua{tex.sprint(
luatexbase.registernumber("catcodetable@latex"),
file.pathpart(kpse.find_file("latex-font-demo-rule-texmf-fontmisc.lua","misc fonts")).."/"
)}]
\begin{document}
\sffamily
We proudly present the duck chess font:
{\duckchessfamily
1. Nf3 nf6 2. e4 e5 3. Bb5 lb4 4. Qe2 qe7 5. Rg1 rg7 6. Kf1 kf7
}
and a font with rules
{\rulefontface
abcdefghij}
\end{document}
So what I would like is a KPSE
key (the name is naturally up to you) which maps to the Path=\directlua ....
call. The value of the key should set the ftype. The default value should be misc fonts
so that
\newfontface\rulefontface
{latex-font-demo-rule-texmf-fontmisc.lua}[KPSE]
works directly, and if the file is in the tex-folder one should use KPSE=tex
.
Regarding the original
key: Not every lua font needs to have this key. And lua fonts can also define more keys (the chess font e.g. has a "chessscale" key allowing to scale only the chess figurines) so I don't think that fontspec should/can implement an interface. Such keys should be set with RawFeature
.