How to account for a space in OpenType ligature?

Let’s say that I want to replace the character’s ” ab” with a new character (“_AB”); is it possible to account for this space so that the word “cab” would not include this new character?

feature liga {
  sub _ a b by _AB;
} liga;


Creating a ligature that actually includes a space isn’t ideal since spaces are often handled independently of your font (think word-spacing). The liga feature is for ligatures that should be used in normal conditions too, so what you’re doing is a bit of a workaround.

A better option is to use contextual ligatures (feature: clig). This means you can design a normal ab ligature without worrying about the space, but tell the font only to use it when proceeded by a space.

You write the feature exactly the same as a normal ligature, except you write the whole context string and mark the glyphs to be substituted with a single straight quote. In your case that would look like this:

feature clig {
  sub space a' b' by AB;
} clig;

There is a good explination of contextual alternates here (they use calt as an example but the concept is the same): Glyphs App — Contextual Substitutions

EDIT: As pointed out by @Wrzlprmft the fact that spaces are handled independently can cause problems (in my limited testing it seems everything works fine in design programs, not so much in others). A better option may be to use the ignore keyword to create an exception (as explained by @Wrzlprmft).

There are more techniques described here (including more complex methods using lookups to account for swashes etc): The OpenType Cookbook — Common Techniques

Source : Link , Question Author : user433351 , Answer Author : Community

Leave a Comment