# LuaLaTeX font chainsubstitution works only for the first font loaded

Here is an extremely simplified version of my code from this answer, where I finally found a workaround to this problem:

\documentclass{article}
\tracinglostchars=3 % Panic if a font does not contain the character we need.
\usepackage{ luacode, luatexbase }
\usepackage{fontspec}

\begin{luacode*}
name = "xalt",
type = "chainsubstitution",
lookups = {
{
type = "substitution",
data = {
["sheva"] = "sheva_for_finalkaf",
["qamats"] = "qamats_for_finalkaf",
},
},
},
data = {
rules = {
{
before = { {"finalkaf"} },
current = { {"sheva", "qamats"} },
lookups = { 1 },
},
},
},
}
\end{luacode*}

% Taamey Ashkenaz and other Culmus fonts with Taamim are available, libre, at:
% https://culmus.sourceforge.io/taamim/index.html
% If you want Hebrew letters that slant from left to right rather than right
% to left, replace the ItalicFont= and BoldItalicFont= features with
% AutoFakeSlant = 0.15
\defaultfontfeatures[TaameyAshkenaz]{
UprightFont = *-Medium,
BoldFont = *-Bold,
ItalicFont = *-MediumOblique,
BoldItalicFont = *-BoldOblique,
Extension = .ttf }

% Uncommenting this line enables RawFeature={+xalt}:
%\setmainfont{TaameyAshkenaz}
\setmainfont{Latin Modern Roman}
\newfontfamily\AshkenazCustom{TaameyAshkenaz}[Script=Hebrew, RawFeature={-ccmp, +xalt}]
\newfontfamily\AshkenazDefault{TaameyAshkenaz}[Script=Hebrew, RawFeature={+ccmp, -xalt}]

\begin{document}

\begingroup\noindent
\AshkenazCustom
^^^^05da^^^^05b0 ^^^^05da^^^^05b8
\endgroup

\begingroup\noindent
\AshkenazDefault
^^^^05da^^^^05b0 ^^^^05da^^^^05b8
\endgroup

\end{document}


The bottom row is correct. The xalt font feature is meant to replace some of the substitutions from the ccmp (contextual composition and decomposition) feature, which I needed to turn off.

However, xalt only works when the font is the first one that the document loads. It does not matter whether it is loaded as \setmainfont or \newfontfamily, or whether \setmainfont changes after it loaded, but the chainsubstitution feature only works if it is the first one loaded. The other feature types I tested with, ligature and pair, do not have this problem. Eta: but multiple does as well.

I wasn’t able to find any warning about this in the documentation I am aware of. Is this a bug, and if so, whose bug is it?

• Likely font-related, if I've understood my (5-minute) experiment correctly: all permutations and combinations occurred in a random sample of half a dozen fonts - with +xalt first or second, with +/-xalt making no difference, with or without HarfBuzz. e.g., David and David Libre give different results under the same conditions, and Alef and FreeSerif identical in all their permutations, but cannot rule out font design for the latter pair (meaning that the marks are halfway up the stems). ?Perhaps it depends on glyph anchor points. Feb 5 at 12:01