Repeating lookups

It’s an OpenType question, and probably a basic one. I have written a lookup that I want to reuse multiple times in a feature. It doesn’t seem that I can simply repeat lookup to do the job.

lookup doStuff {
sub something by something.else;
} doStuff;

lookup doStuff;
lookup doStuff;
lookup doStuff;

In my mind, this doStuff should be executed four times but that’s not happening. And my actual lookups are pretty long and I do want to reuse the first one. Any ideas how to do this?

A lookup can only be called once.

There are two ways to look at this:

You begin with feature code, which looks like a computer program. This is translated into a GSUB, which not a computer program, but more like a collection of lists. So you can check by decompiling the GSUB with PyFontChef to see if the translation of computer program into lists gives the intended result or if you are trying to do something outside the assumptions of how the feature code is interpreted. Does this code create 4 identical lookups, or does the feature table lists the same lookup 4 times, or does it something else?

It is possible to call a lookup more than once. But I only have experience doing that with contextual lookups. It is possible that within a substitution rule, to apply the same lookup to more than one element, to call it from different rules within a lookup, or to call it from different lookups.
Without knowing what stuff doStuff does, my best guess is that you should define a lookup with context rules that call doStuff, rather than calling it several times as a lookup assigned to a feature.

The features do not contain the lookups itself. They just have a list of lookup indexes that should be applied when the feature is a selected. So even if you ‘call’ a lookup from different features, it will only be activated once (at least for simple scripts like Latin).

That is correct. From the feature table the shaper gets a list of lookups, to be applied in the order in which they are stored in the lookup table.
For example: if we have a liga and rlig definition pointing to the same ligature lookup, it will be applied once. But if you have the two pointing to different context lookups, with different context sequences, these can call the same ligature lookup and then this lookup is applied more than once. Probably not a very practical method for these two features. But using a context lookup to call other lookups, which can be context lookups, makes it possible to share data and to optimise processing.

Thanks, that worked! My lookups are heavily contextual and your suggestion was perfect.

Hey Toshe, how did you achieve that?
I want to call the same lookup within two features (rlig and rvrn)

Write the lookup in a Prefix section. Then it can be referenced from both features.

Or write the lookup in one of the features and reference it from the other feature.

1 Like

Thanks, that worked.