Auto class based on Color, Tag, Name

Is it possible to create an automatic class (like @AllLetters, @Uppercase etc.) but based on the color or a tag? Or the name of the glyph?
For example, it could be enough that a glyph was named G.anything to be added to @Anything. Or that the color was set to blue, and it would be part of @Blue.

Yes, you can use tokens to collect glyphs into a class. For example:

@SomeClass = [$["some tag" in tags]];

See the Tokens tutorial and Glyphs Handbook for details. For tags specifically, there is also in-depth info in the Guten Tag Handbook.


Thank you very much, this is very useful!

So to answer my own question, the colors are 0-11 where 0 is Red and 11 is Dark Gray.
$[colorIndex == 11]

However, I do not get it to work. Neither the above or $["example" in tags].
I get no errors, but the result is different than from when I create a manual class which contain the same glyphs – the latter works as expected.

Can you share a screenshot of your feature code where you are using a token?

Well, I am using it in an export filter.
Like this:

customParameters = (
name = Filter;
value = "OffsetCurve; 1; 7; 0; 0; keep; exclude:@MyClass;";

Feature classes cannot be used for custom parameter filters.

Got it! Thanks again for your help.

So, “feature classes” means classes that are anything but a list of glyphs?

I guess that takes me back to square one. There is no way to create custom auto-classes? (Such as @AllLetters, @Uppercase…)

Another related question you may be able to answer:
Is it possible to include a class in a class?

@characters = [ampersand hyphen parenright parenleft @numbers @punctuation];

You can use tokens to build a all letters class:

@Letters = [$[category = "Letter"]];

or uppercase letters:

@Uppercase = [$[case = upper]];

Since a token expands to a list of glyphs, you can also combine it with additional glyph names outside the token:

@TableGlyphs = [$[category = "Number"] comma period];

And you can combine classes:

@FirstClass = [a b c];
@SecondCLass = [x y z];
@Both = [@FirstClass @SecondClass];
@More = [@FirstClass @SecondClass plus more glyph names];
1 Like

You can use classes (the ones in the sidebar, not ones that are defined in code somewhere) in Filter strings but they do not support predicate tokens, yet.

But you can use simplified queries: e.g.: exclude:category=Number;

1 Like

This does exactly what I need in many cases, since I can add custom categories.

However, as a glyphs can only belong to one category, it only works when the functions are non-overlapping. Correct?

I tried exclude:tags=example, but now my file is crashing when I go to the export tab. I sent reports.

The “simplified queries” only support properties that contain a single values, not lists like “tags” but it shouldn’t crash, of cause. I’ll have a look.