Glyphs from @class replacement problem

Hi,

I’m trying to make the following work, but can’t find a solution so far.

There is a glyphs sequence in class A that needs to be replaced with glyphs from class B in case if a glyph from @A is followed by two hyphens.

sub @A hyphen hyphen by @B;
Doesn’t seem to work.
sub @A’ hyphen’ hyphen’ by @B;
doesn’t seem to work either

A couple of more variations that doesn’t work as well:
sub @A @hyphen by @B (class @hyphen is created with the only glyph there - hyphen)
sub @A’ hyphen’ by @B;

In all these cases I’m getting an error: “Invalid ligature sub-rule replacement”

The following one works like a charm but I have too many glyphs and would reeeeaaaly like to use classes instead of individual glyphs:

sub A’ hyphen’ hyphen’ by B;

Any advise would be very much appreciated!

sub @A’ hyphen hyphen by @B;

The tick mark marks the sub run, the stuff you want to replace, in your case @A. I assume you do not want to replace the hyphens? So they are not marked. Make sure @A and @B have the same number and order of glyphs. And this style of substitution (contextual) does not go very well together with other kinds of substitutions in the same lookup. So if you have problems compiling it, put it in a lookup statement:

lookup BLABLA {
sub @A’ hyphen hyphen by @B;
} BLABLA;

However, if you do want to replace the hyphens too, i.e. @B being the ligature for @A hyphen hyphen, you cannot do it with classes. But it could easily be automated with a line or two of Python code.

Thank you, , mekkablue. I do need to replace the hyphens with “nothing” and they do disappear when i’m using glyph substitution. But it doesn’t work with classes for some reason.

In other words I need to replace a glyph from class A + hyphen+hypen with a glyph from class B only

Any idea how to solve this?

OK. That would not be a contextual substitution then, but a ligature, and you cannot have a class as target for a ligature substitution.

The most correct way to do this would be renaming the glyphs in the @B class to what they are replacing: x_hyphen_hyphen (or x_hyphen_hyphen.liga), then Glyphs can autogenerate the code.

You can probably do a simple search and replace (cmd-shift-F).

Thank you. It works!

One more question/issue

I have “a” and “a.ss01” glyphs
so for the “hyphen” feature I have a_hyphen_hyphen.liga and a_hyphen_hyphen.ss01.liga accordingly

the first one is added to the liga feature automatically based on the name I guess. but it doesn’t work for the second one (a_hyphen_hyphen.ss01.liga).

Is there any way to name the glyph properly so it is added to the liga feature too?

Or, if there is no way to add it automatically (just read a couple of post re this issue), what feature i should add this replacement to?
I tried liga, salt - neither works. For some reason it replaces a.ss01 + hyphen + hyphen with a_hyphen_hyphen.liga, not with a_hyphen_hyphen.ss01.liga