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

Fontspec cannot find fonts by name #1118

Open
rm-dr opened this issue Nov 18, 2023 · 2 comments
Open

Fontspec cannot find fonts by name #1118

rm-dr opened this issue Nov 18, 2023 · 2 comments
Labels
bundles and files Bundle issues, finding fonts, etc.

Comments

@rm-dr
Copy link
Contributor

rm-dr commented Nov 18, 2023

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.

@vlasakm
Copy link
Contributor

vlasakm commented Nov 18, 2023

This is essentially #9 once again. See also my comment here: #965 (comment).

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 (#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.

@pkgw
Copy link
Collaborator

pkgw commented Nov 28, 2023

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.

@rm-dr rm-dr added the bundles and files Bundle issues, finding fonts, etc. label Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bundles and files Bundle issues, finding fonts, etc.
Projects
None yet
Development

No branches or pull requests

3 participants