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

  • No problem @user433351 glad to help
    – Cai
    Oct 6 '16 at 8:07
  • I do not have the time to test this right now, but wouldn’t this also cause problems if the space is handled by the typesetting program?
    – Wrzlprmft
    Oct 6 '16 at 20:14
  • @Wrzlprmft good point! I just did some quick tests and it works as expected in InDesign regardless of spacing, but not in Apple Pages where it only works with the default word spacing. I havn't got much else to test on at the minute but I'll do some more testing later
    – Cai
    Oct 6 '16 at 22:21

In my experience, using space in any feature (including defining context) leads to problems with many typesetting programs, as many handle the spaces themselves instead of using your font’s space character. For example, for justified texts, your typesetting program will use sligthly larger spaces instead of your font’s ones.

One way to solve this is to use a contextual lookup, which instructs the following:

  1. If ab is preceded by some glyph other than space, do nothing.
  2. Otherwise, replace ab with AB.

Note that this will also replace ab with AB if it occurs at the beginning of a line, which may or may not be desired.

In OpenType, I suppose this looks like this (note that I never coded OpenType directly and did not test this):

@all_but_space = [A B C D E …];

feature clig {
    ignore sub @all_but_space a' b';
    sub a' b' by AB;
} clig;
  • Beat me too it, I was testing this last night after you mentioned the spaces. This makes much more sense (to me at least) since it works with any kind of space, newline etc.
    – Cai
    Oct 7 '16 at 6:58
  • Small correction though, you still need mark the substitutions with single quotes.
    – Cai
    Oct 7 '16 at 7:00

Never mind, I just figured this out. For anyone else who is interested:

feature liga {
  sub space a b by _AB;
} liga;
  • 2
    So, you're including the space in your ligature? It would be better to use contextual ligatures (clig)
    – Cai
    Oct 5 '16 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.