Metafont is a program written by Donald Knuth for generating fonts for use by TeX.
It is written in the WEB language and today it is distributed as part of TeX Live suite, together with other programs from the TeX ecosystem (TeX and friends) such as GFtoDVI, BibTeX, Tangle, MetaPost, etc.
In the TeX Live distribution, Metafont is compiled to a native executable by first translating the WEB source into C source code using the Web2c program and then compiling the generated C code with a generic C compiler.
To bring Metafont to the web, I compiled it to WebAssembly (WASM) so that it can be executed in the browser. The demo below shows the compiled version of Metafont running entirely in the browser.
It's actually long been my dream to bring the Metafont program to the web. I've been intrigued by the idea of parametric (variable, programmatic, algorithmic) fonts for a long time and Knuth's work on Metafont is the most well-known and influential work in this area.
In the virtual terminal, you can run the mf,gftodvi, and dvipng commands to generate fonts and see them in the virtual file explorer.
You can get help on how to use Metafont by running mf -help in the virtual terminal. You can also check out The METAFONTbook by Donald Knuth for more information on how to use Metafont. To dig deeper into the internals of Metafont, you can read the Metafont: The Program book by Donald Knuth.
I've included an example Metafont file called example.mf that you can use to start experimenting with Metafont right away. Before running it, you can view and edit the example.mf file in the virtual file explorer.
There are multiple options for running Metafont scripts. You can run any of the following commands to run Metafont on example.mf:
All of the above commands will generate a file called example.2602gf (generic font at 2602 pixels per inch). You can preview this font by following these two steps:
Thanks for stopping by my digital playground! If you want to say hi, you can reach out to me on LinkedIn or via email. I'm always keen to chat and connect.
If you really-really like my work, you can support me by buying me a coffee.