num2words: numbers to words in Typst
A Typst package that writes numbers out in words, picking the language up from the document itself.
This package started with a small itch: I wanted headings that read “Chapter one” or “First part”, written by Typst itself instead of typed by hand. Once I ran into that little gap, it struck me as the kind of thing a typesetting tool ought to handle anyway, the sort of touch you reach for in contracts, invoices, or certificates, where an amount is expected in words as well as in digits. Essentially, num2words is a single function that does exactly that step, turning a number into its written form.
The idea is hardly new. Python has a well-travelled num2words library, and most ecosystems carry some equivalent. This one brings the same convenience to Typst.
Usage
The package exposes a single function of the same name. In its fullest form it takes a language and an integer and hands back the number written out, so the same call reads naturally in either tongue:
#import "@preview/num2words:0.2.0": num2words
#num2words(42, lang: "en") // forty-two
#num2words(42, lang: "es") // cuarenta y dos
The language can be left out, and then the function reads text.lang from the document. A paper set in Spanish spells
its numbers in Spanish with nothing more to say:
#num2words(42) // forty-two, under Typst's default English
#set text(lang: "es")
#num2words(42) // cuarenta y dos
Languages can also carry their own variants. English offers ordinals, and Spanish adds grammatical gender:
#num2words(1, form: "ordinal") // first
#num2words(1, lang: "es", gender: "feminine") // una
Design
Under the hood each language lives in its own module behind a shared entry point, and the dispatcher does little more than pick the right one. The whole repository is arranged around that grain, so that a new language, its tests, and its slice of the manual all land in the same small, self-contained place. The aim is that adding one is an easy contribution to make.
Status
Version 0.2.0 is published on Typst Universe with English, Spanish, and Catalan. More languages are planned, and the per-language layout keeps each one small enough to be a reasonable first contribution. Licensed under the LGPL, with the full interface documented in the manual.