Metafont WASM

About the tool

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:

  • mf example or mf example.mf (with or without the .mf extension).
  • Run mf with no arguments and then type example (or example.mf) in the interactive prompt and hit Enter.
  • Run mf with no arguments and then type \relax + Enter followed by input example + Enter.

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:

  • Generate a proof sheet by running gftodvi example or gftodvi example.2602gf. This command will generate a file called example.dvi. (You can run gftodvi --help to see all the available options for the GFtoDVI program.)
  • Convert all pages from the DVI file to PNG images by running dvipng example or dvipng example.dvi. This command will generate a series of PNG images called example[x].png that you can open in the virtual file explorer. (You can run dvipng with no arguments or dvipng --help to see all the available options for the dvipng program.)

Demo

WASM shell
Select a file to view or edit.

See also

Open "generic font" (.gf) files online.
Metafont, generic font, GF, fonts
A WASM port of the FreeType library.
FreeType, WASM, fonts
An online tool for parsing font files.
fonts, WASM
Execute Metafont code online.
Metafont, TeX
A WASM port of pdfTeX.
pdfTeX, WASM, LaTeX, TeX
Running RDKit in the browser with WebAssembly.
RDKit, WASM, cheminformatics, chemistry
A WASM port of Phonetisaurus.
IPA, g2p, WASM
Execute MetaPost code online.
MetaPost, Metafont
Convert TeX to SVG online.
TeX, SVG
A WASM port of Ghostscript.
Ghostscript, WASM, PostScript, PDF
Convert fonts between different formats.
fonts
An online font viewer.
fonts

Made by Anton Vasetenkov.

If you want to say hi, you can reach me on LinkedIn or via email. If you like my work, you can support me by buying me a coffee.