Obtaining subscript/superscript glyphs for mathematical use

Is there an OpenType mechanism that would allow a user do this in a text-editing environment with a suitably-built font:

1 Type a letter or digit, such as a or 1, then:
2 Type some kind of ‘invisible’ combining character, which …
3 Changes the preceding letter/digit into a subscript (or superscript) alternate version of the letter/digit.

The intention is to allow a wider range of characters available as superscript/subscript glyphs, since Unicode’s current allocation is a bit disorganized and restricted.

Using conventional OpenType feature code, you can already do this. Many existing fonts have used it for over a decade. Glyphs can build this for you quite easily if you follow their naming scheme,

Thanks - but doesn’t this change all of them? I tried this with the Typography panel, and it just changes all of them at once. Just want to do one at a time…

You have to apply it very selectively only to the text that you want to change.

There are several different schemes in unicode that work similar to what you are suggesting. (e.g. Variation Sequences).
You could come up with your now markup or encoding. e.g. add a ^ after the number/letter to make it superscript. But that could potentially be dangerous.

1 Like

Thanks, that’s interesting… I can make a Stylistic Set with:

sub  two' VS1  by two.subscript;

which works in Glyphs preview window - but that VS1 is easily inserted in Glyphs … How would you insert it in other text environments?

Or have I got the wrong end of this stick? :slight_smile:

I gave the variation sequences only as an example. They are used for a very specific purpose and probably don’t work in this case.

And it might not be a good idea after all. Maybe you can ask on typedrawer.com if they have an idea?

Perhaps you are looking for a solution for complicated formatting like TeX?

@GeorgSeifert Thanks Georg. Actually, your suggestion works well:


but if I’m not supposed to use variation sequences for this, then I’ll have to think again.

@Dezcom Thanks! (But I’d already found that… :))

If it works it is certainly good. But I only barely understand variation selectors. So I would still ask on typedrawers. There are several people (like @tiro_j, John Hudson) that know much more about these kind of Unicode issues then I do.

OK - thanks for the help!

Unicode Variation Sequences have to be defined as part of the Unicode Standard, you can’t just use Variation Selector characters to affect private substitutions. There are a number of math operator characters that have defined Variation Sequences, but this is not used for super- or subscript characters,

Apart from the handful of characters that have encoded super- or subscript forms in Unicode, there are two clean ways to obtain these in Unicode text using OpenType fonts. One is to use the or OpenType Layout features in any simple text environment with OTL support and with, of course, an appropriate font that contains the super- and subscript glyph variants that you want. This has the benefit that it works in most modern text environments with relatively little effort, and if you are only doing simple inline equations with single level of un-nested -script variants, this would be fine.

Things get more complicated if you are doing more complex equations, or need nested and multilevel -script variants. Then you need both an environment and a font that supports math layout. In such fonts, the -script variants are not pre-scaled and aligned as in simple OT fonts, but instead they are optical size design glyphs included in the font that are then dynamically scaled and positioned by the math layout handler. The font MATH table contains information for default scaling and vertical alignment, but the math handler also contains intelligence to adjust size and height further in some situations. The font may contain two different sets of optical size glyphs, so one can apply -script variants to -script variants for nested and multiple levels.

For more information on OT math fonts, see the Mathematical Typesetting book that we wrote for Microsoft.

In terms of input, I suggest looking at the conventions used in TeX or in MS Word, which have fairly intuitive input methods for equations.

Thanks so much for your detailed response…!

The use case is for text editors and terminals - so the need is to apply standard OpenType features but only to specific characters in a line… That’s why the variation selectors seemed promising.

I just had a look at Tex. It uses a ^ before the number (https://en.m.wikibooks.org/wiki/LaTeX/Mathematics#Powers_and_indices)

n^2 > n²

So you could add some Tex support to the font.

It would have to be escaped somehow, since ^ is already used. And that gets messy real fast. It might be that it’s easier to use some other mechanism to just insert glyphs, such as keyboard macros, rather than use something built-in to OpenType.