tectonic
tectonic copied to clipboard
Fontspec cannot find fonts by name
Tectonic cannot find fonts when they are referenced by name. Referencing directly by filename works.
My first guess was that fontspec searches the system font cache when referencing fonts by name, and thus fails to find fonts in bundles. This doesn't seem to be the case, though: plain latexmk -xetex compiles both versions below perfectly well, even though I don't have the TeXlive fonts in my system font cache.
\documentclass{article}
\usepackage{fontspec}
% This sometimes breaks
\setmainfont{TeX Gyre Pagella}
%
% This works
\setmainfont{texgyrepagella}[
Extension = .otf,
UprightFont = *-regular,
ItalicFont = *-italic,
BoldFont = *-bold,
BoldItalicFont = *-bolditalic,
]
%
\begin{document}
\section*{Introduction}
This is Introduction
\end{document}
Using setmainfont by name is discouraged, but I've found that some packages in TeXlive (fithesis4, for example) use it anyway.
This bug is tangentially related to tectonic-typesetting/tectonic-texlive-bundles#15, since many conflicts are caused by font .map and .enc files.
This is essentially https://github.com/tectonic-typesetting/tectonic/issues/9 once again. See also my comment here: https://github.com/tectonic-typesetting/tectonic/issues/965#issuecomment-1317865762.
It's reassuring that even Will Robertson calls the font file name the better way of specifying the fonts to load. However, unfortunately many packages use font names. We can always patch packages, but, because it seems simpler, I assume that also many users use font names. Hence we need to do something about it.
Tectonic here is based on XeTeX in that for font names it uses only fontconfig (on Linux and Windows(?)) or system functions(?) on macOS. It doesn't ever use any fonts from the TeX search paths (or Tectonic bundle). With font file names it's the opposite - only TeX search paths are searched. LuaTeX is a bit more flexible in this regard IIRC.
In terms of reproducibility I think that Tectonic should preferably support only searching for fonts in TeX font paths. This is also encouraged now by emitting warnings for access of files with absolute paths (https://github.com/tectonic-typesetting/tectonic/issues/8) which also uncovered #8 for people who didn't notice before, because they just installed the fonts to their system, when Tectonic was unable to find them in the bundles. Not using fontconfig would also allow us to (in theory) to get rid of a C dependency. But realistically we would need to allow people to use system fonts - perhaps with something like a -Z unreproducible-system-fonts unstable flag?
However I think we still should allow font file names to be used and make things mostly "just work". A lot of fonts are included on CTAN and hence in Tectonic bundles. If, while generating the bundle, we can construct a mapping of font names to font file names, then we could put such mapping into the bundle (with a known unconflicting name, like TECTONIC-FONT-NAME-MAP). When a font name would be specified, Tectonic would consult the mapping of the used bundle and try to just use the CTAN font. I think this covers a lot of the common use cases.
I think that I've written about this issue before, but I don't quite remember where. I believe that the best approach would basically the idea mentioned by @vlasakm, of having a per-bundle magic file named something like TECTONIC-FONT-NAME-MAP that provides a precomputed mapping. The actual implementation of this would require a bit of care (and some more smarts in the bundle-generation tooling), but it would definitely be doable.
A related issue is that I would love to replace the gnarly multi-platform font-loading C++ code from XeTeX with a more nicely designed Rust version. I think that it could probably be made a lot cleaner and easier to extend with this sort of functionality, and it might not even be that hard.