// HACKER NEWS — CYBERSECURITY
Typst makes big strides
LWN.net is a subscriber-supported publication; we rely on subscribers
to keep the entire operation going. Please help out by buying a subscription and keeping LWN on the
net.
Typst is a system for typesetting documents
into various formats: PDF, SVG, PNG, and, in progress, HTML. It is adept at
handling technical material, and is often considered to be an eventual LaTeX replacement. We last looked
in on Typst a year ago, when it had reached version 0.13. A new version,
0.15, was released in
June with lots of new features, including support for variable fonts,
MathML, multiple bibliographies, and more. Typst is free, Apache-2.0-licensed software, programmed in Rust.
Typst now has support for variable
fonts. Most fonts are distributed in a set of files containing their
glyphs in different weights, in variations such as italic, bold, and so
on. A recent development in the world of typography is the advent of
variable fonts, which can contain all their variations in a single
file. This both saves space and can permit greater flexibility on the part
of the author or designer.
Font features and variations are chosen by setting the value for an "axis";
each axis changes some aspect of the rendered glyphs.
There are typically multiple axes that can have discrete values, for turning on and off various features, or continuous values lying between two limits. The latter can be used, for example, for choosing the weight of the font along a continuum.
To test the new Typst feature, I downloaded two open-source variable fonts:
Roboto Flex, a
general-purpose font with 13 axes, and Zycon, a font containing no
letters but 17 small decorative pictures. Zycon's six continuous axes smoothly alter various aspects of the pictures, making the font useful in animations.
Here is a Typst document that uses both of these fonts, varying one of the axes for each of them:
In Typst, a
"#" character puts the document in "code mode", where the rest of
the line or block is interpreted as code in Typst's built-in language. Within code mode, material enclosed in square brackets is interpreted as "text mode", or text to be typeset.
The code above contains two commands to set the fonts by name,
using one of the options of the text() function.
Next we have for loops, which operate as might be expected. Inside
the loops we call the text() function to set the
variations variable. The text to be used with the Roboto Flex font
is entered directly, but the output using the Zycon font is a single
character specified with the str.from-unicode() function. It
could have been entered directly, but readers may not have been able to see it, depending on the coverage in their browser's font.
The axis that we manipulate in Roboto Flex is called YTDE. As the
figure below shows, this axis determines the length of the font's descenders,
while leaving its other characteristics unchanged. This might be useful
when typesetting tables, for example, to avoid collisions between the descenders and the table-cell boundaries.
One of Zycon's six axes, called "M1 " (the two trailing spaces are part of the name; all axis names contain four characters), does different things to different characters. The effect on the Moon glyph is to change the lunar phase.
Compiling this document with typst compile vfont.typ produces a PDF in
vfont.pdf, which is shown in the screen shot below: