A Visual Studio Code extension that provides language, preview and debugging support for METAFONT.
You can install the extension from within VSCode (ID:
Alternatively, you can manually download the
.vsix file of each release here.
You can also package the extension yourself:
- clone this repository, change to the new directory
code --install-extension vscode-metafont-x.y.z.vsix
Note: Many features are still under development.
syntax highlighting, semantic highlighting, hover, code indentation, code folding, token definition, etc.
METAFONT file management
In the MF Files view,
.mf files can be grouped in different categories. Parameter files can be marked as default job file for easy reference in other features.
This extension provides commands to run METAFONT or generate proof sheet PDFs.
- Current glyph (glyph preview)
Shows a preview of a glyph depending on your caret's (text cursor's) position. You can lock the reference to keep showing a specific glyph when editing other parts of your code.
- All glyphs (glyph overview)
Provides an overview of all glyphs of the font.
- Font (font preview)
Test the font including kerning and ligatures.
- Glyph box dimensions (table)
Table of all glyph box dimensions
- Kerning pairs (table)
Table of all kerning pairs
- Ligatures (table)
Table of all ligatures
For all those previews, you can specify a first line and a job file to preview the output with different parameter files, modes/resolutions, etc. You can also move many previews to separate windows.
Set breakpoints to pause METAFONT on a specific line and inspect variables. Besides showing the values of
transform variables, the debugger also provides a visualization of
picture variables and expressions.
Currently, debugging inside definitions/macros or loops is not supported.
Note: The previews should update every time you save a METAFONT file or change a preview option. Note that METAFONT needs to re-run in many cases which might take a few seconds. To speed this up, comment out code you are not working on (e.g. all but one program file
input in the driver file or characters you are not editing).
The screenshot(s) may be outdated as they are not updated with every update of the extension.
Motivation and Purpose
While METAFONT provides an interface for
displaying characters, it's author acknowledges that other programs are helpful in creating a good font:
[...] a font must be seen to be believed. Moreover, if some characters of a font are faulty, the best way to fix them is to look at diagrams that indicate what went wrong. Therefore METAFONT is incomplete by itself; additional programs are needed to convert
the output of METAFONT into graphic form.
— Donald E. Knuth, The METAFONTbook, p. 327
In appendix H of The METAFONTbook, Donald E. Knuth discusses two programs,
GFtoDVI and $\TeX$, to generate proof sheets. While these are great for generating large scale proofs and font samples, you may want to get a more detailed view of a character's anatomy while designing it. This was the original motivation for this extension.
The development of this extension started in 2019, with the preview based on the
mf2vec concept (see the explanations in
mf2ff's README). Starting in October 2023, some parts of the extension were re-implemented and many features were added. While it is relatively easy to use METAFONT as an interpreter to provide previews as a special feature of a language extension, it is much more difficult to correctly implement standard language features such as syntax highlighting, semantic highlighting, go to definition, etc. due to the flexibility of the METAFONT language, e.g.
a.b can be a variable or the use of a macro that takes an undelimited parameter. The macro could be defined in another file that the current file doesn't reference. In other languages you have to
import everything you want to use. In METAFONT it is much harder to know where and how a symbolic token was defined. Therefore these basic language features may not be as robust as you are used to in other languages.
The developer of this extension hopes that it will help font designers to design and debug fonts and glyphs more easily. Although this may not be an ideal solution, it could be a small step towards Dave Crossland's vision to help METAFONT to catch on:
Perhaps if there was a graphical user interface
to visualize METAFONT code in near real-time, type
designers who feel writing code is unintuitive could
be more confident about doing so.
— Dave Crossland, Why didn't METAFONT catch on?, TUGboat, Volume 29 (2008), No. 3, p. 419
- Code quality
- Fixes and improvements
There is still a lot of room for improvement in some of the language features, both in terms of functionality and performance.
There are some major and many minor bugs in the debugger.
The GUI of the previews could also be improved.
- Better efficiency and speed
Running METAFONT less frequently for previews and updating them based on unsaved files, may allow for near real-time previews.
- Notebook-like METAFONT interface [maybe]
This might be useful for learning METAFONT, experiments, etc. with included interactive output of evaluated expressions, paths, pictures and maybe more.
- Interactive function testing [maybe]
It would be great to be able to test macros interactively, e.g. move around points passed as input (pair value or point suffix) and see how a computed path or filled/drawn picture changes.
- Interactive editing [maybe]
This is more challenging, and I'm not sure how it could be done. In many cases, METAFONT's result is based on a combination of parameters, equations, factors or even numerical solutions of nonlinear equations. When the user modifies the visualization, what should be changed? A mechanism to specify what should be changed may be too complicated and some constraints may not be met during editing in the visualizations.