I’d like to write a script that replaces the 26 letters of the alphabet with numbers, then calculates the summ of the numbers that are connected. For instance:

If I type “ABC” or “Abc” or “Abc” the font should display "6"
If I type “I am abc.” it should display “9 14 9.”

I was thinking about doing it with the dliga feature, first creating numbers up until 1000, calling them “eleven” “twelve” “thirteen” etc, and then just substitute letter combinations with

sub aa by two;
sub ab by three;
etc

and

one one by two
one two by three
etc

but the rules become exceedingly complex without variables. Is there a way to use variables and algorithms with the dliga sub feature?

No. You will have to substitute all possible combinations. And your GSUB table could exceed 64k if you do, and the font will not compile in that case. So, the problem is not complexity, but the quantity of substitutions you have to make.

Birthday present for my aunt. She’s into http://en.wikipedia.org/wiki/Isopsephia. It’s easy to do it in Java Script, but I wanted to make a font for her that does in on the fly as she types in any environment.

If you know how to do it, perhaps JS is indeed the best option for you.

As described, you have to really write every possible sum. You could put it in lookups. Each lookup can build on the previous ones:

lookup SINGLELETTER {
sub a by one;
sub b by two;
…
} SINGLELETTER;

lookup CONSECUTIVELETTERS {
sub one one by two;
sub one two by three;
sub one three by four;
…
} CONSECUTIVELETTERS;

… and so on. You could write a script that produces this code. But again, the danger is that it can become too large to compile if you really want to go to a thousand. So, a JavaScript is probably the best solution after all.

I don’t want to bother you with this but it has become kind of a puzzle and a challenge that I don’t want to just let go. I figured that:

For two letters there are 26*26 = 676 basic single combinations, but the combinations result in 52 numbers that equalize each other, for instance, 26 can stand for AZ, BY CW etc.

For three letters here are 52*26 combinations = 78 numbers

For four letters there are 52*52 combinations = 112 numbers

For eight letters there are 112*112 combinations = 224 numbers

For sixteen letters, there are 224*224 combinations, 448 numbers.

With 8 letters, a big part of the English language would be covered. (the average length is 5). With 16 letters you’re at 99.99%. If a script could fit 8 or even 16 letters that would be simply awesome.

Now, in a simple routine, one could group the letters 4 times. For example:

c + o + m + b + i + n + a + t + i + o + n
3 +15+13 + 2+9 + 14+1 +20+9+15+14

—> sub a by one, b by two etc.

co+mb+in+at+io+n
(18+15)+(23+21)+(24+14)

----> lookup CONSECUTIVELETTERS sub eighteen fifteen by thirtythree etc.

comb+inat+ion
(33 + 44) + 38

----> lookup CONSECUTIVELETTERS sub thirtythree fourtyfour by seventyseven etc.

combinat ion
77 + 38

----> lookup CONSECUTIVELETTERS sub seventyseven thirtyeight by 115

combination
115

At this point my mathematical skills come to an end. I’m not sure how, but it seems to me that if we can loop the routines, with this method one could significantly reduce the amount of possibilities. Not sure how to do it exactly and if we stay within 64k though. It’s a puzzle, maybe insolvable.

It is trickier than I thought. You need to specify the max wordlength for which the feature should work. You can use this Python script for creating the feature (set the wordlength at the beginning):

In the end, you get a comment with the names of the number glyphs you must create: copy them into your clipboard, and paste them into the Add Glyphs dialog (Cmd-Shift-G).

EDIT: And I get a subtable overflow with a word length of seven.

Weird. I made a completely new font. Bare of anything but numbers and the dlig definition. Still get a subtable overflow at five. Since we’re so close to solving the puzzle, am I doing something wrong? Isn’t it supposed to go into the dlig Features? Where did you put it? I put the compiled code in Features > dlig Is that correct?