Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actually looking up fonts on the filesystem #413

Open
kberry opened this issue Feb 10, 2020 · 11 comments
Open

actually looking up fonts on the filesystem #413

kberry opened this issue Feb 10, 2020 · 11 comments

Comments

@kberry
Copy link

kberry commented Feb 10, 2020

Hi again Will - given a TeX source with (for example)
\setmonofont[Scale = .95]{zcoN-Regular.otf}
I was quite surprised to learn that my .fonts.conf was relevant in any way with that specification. But it is. luaotfload still prefers system fonts to filesystem fonts, if it can match the name. Argh! (I had an old version of zcoN in my fonts.conf, and it was being found instead of the current version as found with kpsewhich.)

luaotfload-tool has an option --prefer-texmf to undo this, but I don't think that helps at the fontspec level. I asked on luaotfload, and Marcel said (latex3/luaotfload#130) that it can be done with Lua:

\directlua{
  fonts.names.set_location_precedence { "local", "texmf", "system" }
}

wdyt? Could this be added to fontspec given the lookup-by-filename request?

He also mentioned omitting the brackets on the \font:

\font\xxx "kpse:zcoN-Regular.otf" % instead of:
%\font\xxx "[zcoN-Regular.otf]" 

though I have a feeling that would impact other things. Though I guess I don't really know. --thanks, karl.

@wspr
Copy link
Collaborator

wspr commented Feb 10, 2020

Thanks -- having an option to only search kpse would make sense in fontspec. I guess it would just look like

\setmonofont{foo.otf}[OnlyKpse]

or similar. That could then change the brackets interface to a kpse: on for external filenames. Further thoughts on the interface?

@kberry
Copy link
Author

kberry commented Feb 10, 2020

That would be a good improvement. But I was thinking of something even stronger: make kpseonly the default behavior when filename lookups are requested. Why would I want system fonts involved at all when I explicitly asked for a filename lookup? (Answer: I don't.)

There could be an option for the reverse, [CheckSystemToo], although that doesn't sound easy to implement given the need for different syntaxes in the \font call.

However, if you think that is too incompatible a change at this point, please at least change the documentation to say that "filename lookups" aren't really -- system fonts are still found first, absent the potential new option. It was a great (and unwelcome) surprise to me.

I just hope there are no ill effects from this new kpse:foo.otf call. I'll be impressed if it all "just works" ...

@wspr
Copy link
Collaborator

wspr commented Feb 11, 2020 via email

@zauguin
Copy link
Member

zauguin commented Feb 11, 2020

That would be a good improvement. But I was thinking of something even stronger: make kpseonly the default behavior when filename lookups are requested. Why would I want system fonts involved at all when I explicitly asked for a filename lookup? (Answer: I don't.)

In my experience, it is quite common that people download some font, install it and then want to use it from TeX. Of course, the most obvious name is the name of the file they just downloaded (Finding the font name at the very least would involve opening the file, sometimes even finding the right tool to get such information...). So the requirement to find a system font by filename is not particularly uncommon. Actually I know multiple people who were confused by XeTeX finding different fonts when using fontnames or font filenames.

So while I think that a OnlyKpse option would be a great idea, I think that the default should stay the same.

There could be an option for the reverse, [CheckSystemToo], although that doesn't sound easy to implement given the need for different syntaxes in the \font call.

However, if you think that is too incompatible a change at this point, please at least change the documentation to say that "filename lookups" aren't really -- system fonts are still found first, absent the potential new option. It was a great (and unwelcome) surprise to me.

In which way aren't these really filename lookups? The fonts are looked up by filename, there are just more places in which we look for them.

I just hope there are no ill effects from this new kpse:foo.otf call. I'll be impressed if it all "just works" ...

The most important difference I can think of right now is that they support different characters. For obvious reasons, kpse:<name> can't be parsed correctly if <name> contains /, : or (.

@kberry
Copy link
Author

kberry commented Feb 11, 2020 via email

@davidcarlisle
Copy link
Member

davidcarlisle commented Feb 11, 2020 via email

@kberry
Copy link
Author

kberry commented Feb 12, 2020 via email

@zauguin
Copy link
Member

zauguin commented Feb 12, 2020

Karl I find your terminology confusing here,

I find your confusion confusing!

A filename lookup uses the system filename of the font file

I don't know what the "system filename of the font file" is, but no, that is not my understanding.

The "system filename of the font file" is the name of the file in which the font is stored.

a fontname lookuop uses the internal font name as specified inside the font.

I guess. The reality, as far as I've seen, is that a "fontname" lookup uses fontconfig (on Unix). No one seems to know what that really means or how to control it precisely. I have tried pretty hard to understand why fontconfig returns font x for request y, and failed. There is no clear documentation. The source is unreadable. Etc.

You can find the logic used by luaotfload in luaotfload-database.lua.It is a bit chaotic but with some effort readable and tries to be mostly compatible with fontconfig. Basically what it does is: Every font has a fontname, a (preferred) familyname and additional metadata set (in the OpenType name table). When a name is given, it is matched against the familynames. If a familyname matches, a font from that family is used (The precise font depends on whether regular/italic/bold has been requested, optical sizes etc). Otherwise we match against the fontname. If a fontname matches, the matching font is used. (fontconfig allows some additional lookup variants which are mostly irrelevant in a TeX context)

That distinction is separate from the distinction of whether the system font path

System fonts (on Unix anyway) do not exactly have a "path". They are in some weird database with all kinds of tricky features.

??? If there are fonts on Unix stored in some weird database then luaotfload can't find them. As far as we are concerned, the fontconfig configuration files translate to a list of directories (mostly /usr/share/fonts on a typical system). System fonts are the font files found in this directory. (fontconfig also has some index files, but they are more of an implementation detail.) The file names of the files in this directories are the filenames which are relevant when doing a filename lookup in luaotfload.

or the texlive font search path is used, isn't it?

This is all news to me. My understanding of fontspec (and xetex) ever since day one was that a filename request (foo.otf) meant looking it up with kpse, as in "kpsewhich foo.otf", and did not involve system fonts in any way whatsoever. That is certainly what the documentation implies. It does not talk about the "system filename of the font file".

What David describes is pretty much the model of luaotfload (XeTeX is a bit different): There are two distinctions:

  • Lookups by filename: A file with the requested name is requested. The font file with the requested name can be either in the system font path or in texmf.
    This also corresponds to the documentation of fontspec:

    When selecting fonts by file name, any font that can be found in the default search paths
    may be used directly

    Of course the question is what default search paths are, but as far as fonts are concerned I would definitly describe the default system font path as default search paths.

  • Lookups by fontname: A font with the requested familyname or fontname (as described above) is requested. Again, this can find system fonts or fonts in texmf.

Hans implemented all kinds of crazy caching of system fonts in luatex which obscured (and still obscures, I guess) the issue. I hated this but have no influence over what hapens.

All relevant caching happens in luaotfload, luatex (the engine) itself never deals with system font related stuff. This caching is pretty much necessary to get performant font name lookup because we can't use fontconfig directly and they don't have a documented (and there probably not stable) format for their cache files, so we can't reuse them either.

@davidcarlisle
Copy link
Member

davidcarlisle commented Feb 12, 2020 via email

@kberry
Copy link
Author

kberry commented Feb 12, 2020 via email

@wspr
Copy link
Collaborator

wspr commented Feb 13, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants