Automate .case between numbers

Hello, what is the best way to program an automatic replacement of punctuation, for instance swapping from colon, to colon.case between lining figures?

The short answer is to use contextual alternate feature.

To do it (assuming you haven’t done OpenType coding before), go to Font Info > Features, and add a feature and rename it to calt. In that, you type the code as follows:

@figures = [zero one two three four five six seven eight nine];
@caseBefore = [colon hyphen];
@caseAfter = [colon.case hyphen.case];
sub @figures @caseBefore' @figures by @caseAfter;

You declare three OpenType classes (groups), one for numbers, the other two for glyph that actually substitute. In the final line, you sub (short for substitute) @caseBefore with @caseAfter when it’s sandwiched by two numbers. The marking with ' quote indicates the class you want to substitute. The name and content of each class is up to you, but in the before and after classes, the number and order of the glyphs should match. And there are lots of ways that essentially do the same (for example, those @xxx classes are usually made in the Classes subsection instead of inside the feature, for better readability/management of the code).

1 Like