Allows the rendering of digit grouping (thousand separators) in contexts where you have some control over the font but don't want to (or can't) edit the text inline. It looks a bit like this:
This is achieved by adding font features to font files which enable outboard configuration of number formatting. The 'inserted' characters are baked into the font, so they don't affect copy/paste, syntax highlighting, etc.
Attribution: This project is primarily sh1boot
's numderspace
, which is based substantially on Numderline. My (paulirish) updates are adding dgun
, auto-monospace detection, better test page and docs.
Feature Name | Example | Digit Grouping with… |
---|---|---|
dgsp |
125 603.1415965 |
spaces within whole numbers |
dgco |
125,603.1415965 |
commas within whole numbers |
dgun |
125_603.141_596_5 |
underscores within whole numbers and decimals |
dgdo |
125.603,1415965 |
dots within whole numbers (and replacing literal dot with comma, use with caution) |
dgdd |
125.603,141.596.5 |
dots within whole numbers and decimals (and replacing literal dot with comma, use with caution) |
Patch a font to add the extra stuff:
python3 patcher.py SomeFont.ttf
python3 patcher.py --help # see available options
If you have CSS control with font-feature-settings
over the font, apply this to the selectors you want formatted as such:
font-feature-settings: 'dgsp';
Various editors/tools allow enabling these font-features; see https://github.com/tonsky/FiraCode/wiki/How-to-enable-stylistic-sets (just change ss01
to dgsp
, etc.)
To use it in a terminal (if you have one which supports ligation), you can use
a monospaced font and pass --monospace
to the patcher so that it will
squeeze glyphs appropriately.
Usage might be configured with a line like: font=My Font with DigitGrouping:fontfeatures=dgsp
or font_features My-Font-with-DigitGrouping dgsp
, or, in fontconfig:
<match target="pattern">
<test name="family" compare="contains"><string>DigitGrouping</string></test>
<edit name="fontfeatures" mode="append">
<string>dgsp</string>
</edit>
</match>
Or… if all of that is too much hassle or isn't working out right, just bake
in dgsp
as the default, by passing --feature-name=calt
to the patcher.