latex3 / fontspec

Font selection in LaTeX for XeTeX and LuaTeX
http://latex3.github.io/fontspec/
LaTeX Project Public License v1.3c
269 stars 32 forks source link

Wishlist: support virtual fonts (at least in luatex) #428

Open callegar opened 3 years ago

callegar commented 3 years ago

Description

Please introduce a way to support virtual fonts in luatex

Check/indicate

Minimal example demonstrating the issue

Not relevant

Further details

One of the missing items moving from regular (pdf)latex to modern engines is the lack of virtual fonts when using unicode fonts. Even if for unicode fonts it is possible to support multiple languages, and different text features only a very limited number of fonts go beyond latin alphabets or provide things like small caps. Lack of virtual fonts means that if one needs to typeset a piece of text including characters that are not available in the font (e.g. a few Greek words or letters), then he/she is left with a few of alternatives that are not completely satisfactory:

  1. Move to a font that includes the missing glyphs, which may restrict the font choice significantly
  2. Include a font switching macro before using the glyphs that are not available in the main font.
  3. Use macros for the glyphs that are not available in the main font.

Items 2 and 3 are ugly and break the readability of the text in the original document. Particularly 3 looks like going back to the legacy TeX accenting or \textcomp Furthermore, they make it impossible to directly cut and paste unicode text into the latex source, which should be one advantage of using a modern engine. Item 1 on the other hand introduces a nasty restriction.

The other way round, one would really appreciate having an interface that lets one select a main font and then, if in rendering the document some glyphs are missing or ugly, easily provide a fallback or an alternative for some glyph sets. Examples:

  1. I put some text in my source that should be typeset in some way;
  2. I select a reasonable font;
  3. In compiling I realize that an acronym (e.g., ΔΣ, which is quite used in signal processing and that should not be typeset in math mode for consistency being an acronym and not a formula) is not typeset correctly due to missing glyphs;
  4. I experiment different fallbacks for the glyph set corresponding to Greek letters, until I find one that matches my main font sufficiently well.

or

  1. I put some text in my source that should be typeset in some way;
  2. I select a reasonable font;
  3. I realize that I need small caps, but my font does not include them, or it includes them, but they are not consistent with the result that I should obtain (e.g., in many fonts small caps look a bit like petite caps, and I should adhere to a format with larger small caps);
  4. I experiment different fallbacks or alternatives for the glyph set corresponding to small cap letters, until I find one that matches my main font sufficiently well.

This kind of functionality can currently be obtained in LuaTeX using the combofont package. However, the latter is not only marked as experimental and unstable, but also rather low level in its interface and not very consistent with the way in which fontspec lets things be configured. Specifically, it is not really very nice for quickly experimenting different fallbacks or alternatives.

I realize that there can be some resistance in supporting in fontspec something that needs to be done in very different ways in LuaTex and XeTeX (I have seen you answer to bug 225 that has been closed long ago). However, I wonder if anything might have been changed since 2016 (the original date when that was reported). Furthermore, I have a feeling that until fontspec starts supporting a virtual font mechanism at least at an experimental level, there will be no chance that: (i) XeTeX and LuaTeX can converge on ways of doing it; and (ii) related bugs in the LuaTeX font loader are fully unveiled and fixed. Hence, I truly hope that this can be taken in consideration.

Blaimi commented 2 years ago

luaotfload has a experimental feature for this since 3.12 but it does not seem to be implemented in fontspec.

Blaimi commented 2 years ago

Yeah, found a solution :partying_face:

\directlua
{luaotfload.add_fallback
("myfallback",
{
"DejaVuSans:mode=harf;script=grek;color=FF0000;",
}
)
}

\newfontfamily\Sen[AutoFakeSlant,NFSSFamily=Sen,RawFeature={fallback=myfallback}]{Sen}

\renewcommand{\sfdefault}{Sen}

See the documentation of the luaotfload-package for more options. You can even provide a chain of font with emoji-fonts and things like that.