Cycling through contextual alternates?

I’m working on a font that has 4 versions of each letter, and two versions of each punctuation mark.

I would like to make each letter cycle through it’s alternates in order, no matter how many characters appear in between, as the user types.

So in a word like “TENNESSEE” I would like the result to be as follows

T E N Nss.01 E.ss01 S S.ss01 E.ss02 E.ss03

Following the concepts here, even expanded for 4 versions of each letter, the result is:

T E N.ss01 N.ss02 E.ss01 S.ss03 S E E.ss01

I could achieve this by defining a feature for every single letter, but that has it’s limits.

For example, in a sentence like


I would like the first Z to be the default character and the second Z to be Z.ss01

So this cycle should be the case with all letters, no matter how many characters come in between.

Last example: If several sentences are typed, I would like the periods to swap back and forth.

Bonus: Can this work through a line break?


Well, it gets about as good as the ‘advanced contextual alternates’ tutorials. But feel free to experiment and post improvements here.

No matter how many characters? That would mean endless memory resources. But the limits in OT features are actually pretty tight.

A substitution feature cannot know anything about the next line.

You could do some letter frequency research for the languages you want to cover, and figure out a good structure with four or five cycles from that. You could put T and N in different cycles, for instance.

Besides, if you had 4 versions of each letter, and only Vowels and Consonants, it would be:
T E N.ss01 N.ss02 E.ss01 S.ss03 S E.ss02 E.ss03

I.e., no glyph repeated in your example, not even E.