FontCreator Tutorials
Fractions Using Reverse Chaining Substitution
written by Erwin Denissen, published June 26, 2026
You'll need: FontCreator (Windows and macOS), numerator (.numr) and denominator (.dnom) figure glyphs plus a fraction glyph in your font, and comfort with the OpenType Designer's Code Editor.
the OpenType Designer Code Editor in FontCreator with the frac feature open, and a preview line below showing "1/2 123/456 4 5/8 m/s" rendered correctly.
OpenType fractions let a font editor turn typed figures and a slash into proper diagonal fractions — handy for recipes, measurements, and mathematical expressions. The frac feature replaces figures separated by a slash (U+002F) or a fraction slash (U+2044) with diagonal fractions built from numerator and denominator forms. The catch is doing it precisely: a naive frac feature also mangles units like m/s and stray digits that were never meant to be a fraction. This tutorial shows the common approach, why it misfires, and a sharper version built on reverse chaining single substitution (rsub) that only touches real fractions.
Implementing fractions in OpenType fonts
Fractions are essential in typography for displaying mathematical expressions, measurements, and more. The frac feature in OpenType fonts replaces figures (digits) separated by a slash (U+002F) or a fraction slash (U+2044) with "common" (diagonal) fractions.
The common method for implementing fractions
One of the more common ways to implement the frac feature is as follows:
``` @figures = [zero one two three four five six seven eight nine]; @figuresNumerator = [zero.numr one.numr two.numr three.numr four.numr five.numr six.numr seven.numr eight.numr nine.numr]; @figuresDenominator = [zero.dnom one.dnom two.dnom three.dnom four.dnom five.dnom six.dnom seven.dnom eight.dnom nine.dnom]; @slash = [slash fraction];
feature frac { sub @figures by @figuresNumerator; sub [@slash @figuresDenominator] @figuresNumerator' by @figuresDenominator; sub slash by fraction; } frac; ```
#### Issues with the common method
While this method effectively formats fractions, it can inadvertently affect non-fractional digits and slashes within text blocks. For example:
`` 1/2 123/456 4 5/8 m/s ``
a text preview where the common frac method has wrongly converted the "4" in "4 5/8" and the slash in "m/s".
#### Potential problems
- The slash in "m/s" would be substituted with the fraction slash.
- Digits not intended to be part of a fraction (like the "4") would be converted to numerator forms.
- This leads to incorrect rendering and affects readability.
New approach using reverse chaining single substitution (rsub)
To address these issues, we can use a more precise method that only affects actual fractions, leaving other parts of the text untouched. One effective approach is using GSUB LookupType 8 (Reverse Chaining Contextual Single Substitution), a technique we developed in June 2021.
Here is the proposed solution:
``` @figures = [zero one two three four five six seven eight nine]; @figuresNumerator = [zero.numr one.numr two.numr three.numr four.numr five.numr six.numr seven.numr eight.numr nine.numr]; @figuresNumeratorEx = [fraction @figuresNumerator]; @figuresDenominator = [zero.dnom one.dnom two.dnom three.dnom four.dnom five.dnom six.dnom seven.dnom eight.dnom nine.dnom]; @figuresDenominatorEx = [fraction @figuresDenominator];
feature frac { sub @figures slash' @figures by fraction; rsub @figures' @figuresNumeratorEx by @figuresNumerator; sub @figuresDenominatorEx @figures' by @figuresDenominator; sub @figures space' @figuresNumerator by space.frac; } frac; ```
the same "1/2 123/456 4 5/8 m/s" preview, now rendered correctly with the rsub method — fractions diagonal, "m/s" and stray digits untouched.
Note: The rsub keyword is reverse chaining single substitution (GSUB LookupType 8). The font editor processes a reverse-chained lookup from the end of the run backwards, which is exactly what lets it decide, with the right context, whether a figure belongs to a fraction.
How the rsub method works, line by line
sub @figures slash' @figures by fraction;— turns the slash into a fraction slash only when it sits between two figures. The slash inm/sis left alone because it isn't bracketed by figures.rsub @figures' @figuresNumeratorEx by @figuresNumerator;— looking backwards, a figure followed by a fraction slash or another numerator becomes a numerator. This is what spreads numerator forms leftward across the whole top of the fraction.sub @figuresDenominatorEx @figures' by @figuresDenominator;— a figure preceded by a fraction slash or another denominator becomes a denominator, spreading denominator forms rightward.sub @figures space' @figuresNumerator by space.frac;— handles the mixed-number case (for example4 5/8) by swapping the space before a numerator for a tighter fraction space, so the whole and fractional parts read as one number.
Tip: Add the feature in the OpenType Designer (Font menu → OpenType Designer), open the Code Editor at the bottom, and paste the feature. Use the live preview line to type real-world strings like 4 5/8 m/s and confirm only the intended glyphs change.
Watch out: This feature assumes your font actually contains .numr, .dnom, a fraction glyph, and (for mixed numbers) a space.frac glyph. Missing glyphs make the substitutions silently fail, so confirm the names match before you compile.
The good news is that the names aren't arbitrary — they follow FontCreator's recognised suffix convention. The automatic feature generator looks for figure glyphs suffixed .numr (numerators), .dnom (denominators), .frac (precomposed fractions), .sups (superiors) and .subs (inferiors), among others, and wires up the matching features for you. Stick to those suffixes and FontCreator can scaffold a basic frac from your glyph names; the rsub version below then refines it into the precise one.
App support: rsub (reverse chaining single substitution, GSUB LookupType 8) is part of the OpenType spec and works in modern HarfBuzz-based shapers — browsers, Office, Adobe apps. Coverage isn't guaranteed everywhere, though: a few older or lightweight layout engines apply it inconsistently or skip it. Always test your fractions in the apps your users actually use, and keep the simpler frac rules as a graceful fallback.
Advantages of the new method
- Contextual precision — only affects digits and slashes that are part of actual fractions, leaving other digits and slashes in the text untouched.
- Preservation of non-fraction content — units like "m/s" remain correctly formatted, and measurements not intended as fractions display as intended.
- Better reading experience — fractions are formatted appropriately without affecting surrounding text, so the font behaves predictably for professional typography.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Nothing changes when frac is on | Numerator/denominator/fraction glyphs missing or misnamed | Check glyph names match the classes in the feature code |
m/s still turns into a fraction | Using the common method, not the rsub method | Switch to the rsub feature code above |
Mixed number 4 5/8 looks too loose | No space.frac glyph, or the last rule omitted | Add a space.frac glyph and keep the final sub … space' … rule |
| Feature compiles but does nothing in an app | The app doesn't enable frac by default | Turn on fractions in the app, or test in FontCreator's preview |
Frequently asked questions
What does the frac feature do? The frac OpenType feature replaces figures separated by a slash or fraction slash with diagonal fractions built from numerator and denominator figure forms. It is how a font editor produces proper fractions like ½ from typed text.
Why use reverse chaining substitution instead of the common method? The common method converts every digit and slash it sees, which breaks units like m/s and stray numbers in running text. The reverse chaining (rsub) method only substitutes figures and slashes that are genuinely part of a fraction, so the rest of the text is left intact.
What is rsub in OpenType feature code? rsub is reverse chaining single substitution (GSUB LookupType 8). It is evaluated from the end of the text run backwards, which lets the lookup use following context to decide whether a figure should become a numerator.
Do I need special glyphs in my font? Yes. You need numerator (.numr) and denominator (.dnom) versions of the figures, a fraction glyph, and a space.frac glyph for mixed numbers. The feature references these by name.
What to read next
- Enrich Your Fonts with OpenType Features — the broader tour of GSUB/GPOS features you can add in the OpenType Designer.
- Add Missing Characters and Codepoints — make sure your figure, slash, and fraction glyphs exist before wiring up the feature.
- Test and Validate — confirm the feature behaves the same across apps before you ship.