Typst makes big strides

Typst makes big strides

Typst 取得重大进展

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 是一个用于将文档排版为多种格式(如 PDF、SVG、PNG,以及正在开发中的 HTML)的系统。它擅长处理技术文档,常被视为 LaTeX 的潜在替代者。我们上一次关注 Typst 还是在一年前,当时它发布了 0.13 版本。今年 6 月发布的 0.15 新版本带来了许多新特性,包括对可变字体(Variable Fonts)、MathML、多重参考文献等的支持。Typst 是一款基于 Rust 编写的免费开源软件,采用 Apache-2.0 许可证。

Variable Fonts

可变字体

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.

Typst 现在支持可变字体。大多数字体通常以一组文件的形式分发,分别包含不同字重、斜体、粗体等变体。排版领域最近的一项进展是可变字体的出现,它将所有变体整合在单个文件中。这不仅节省了空间,还为作者或设计师提供了更大的灵活性。

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.

字体特性和变体通过设置“轴”(axis)的值来选择;每个轴都会改变渲染字形的一个方面。通常有多个轴可以设置离散值(用于开启或关闭各种特性)或两个限制之间的连续值。后者可用于在连续范围内选择字体粗细等属性。

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.

为了测试 Typst 的这项新功能,我下载了两款开源可变字体:Roboto Flex(一款拥有 13 个轴的通用字体)和 Zycon(一款不含字母,仅包含 17 个小型装饰性图案的字体)。Zycon 的六个连续轴可以平滑地改变图案的各个方面,使该字体在动画制作中非常有用。

MathML

MathML

HTML export is still an experimental feature of Typst, but this release shows significant progress. The main new HTML feature is the translation of mathematics into MathML. The previous article on Typst showed the markup for a certain definite integral and displayed its output when rendered into a PDF by Typst. The same Typst code, when rendered into HTML, produces a long string of MathML markup that almost all reasonably current web browsers know how to interpret.

HTML 导出仍然是 Typst 的一项实验性功能,但此版本显示出了显著进展。HTML 的主要新特性是将数学公式转换为 MathML。上一篇关于 Typst 的文章展示了某个定积分的标记代码及其渲染为 PDF 的输出结果。同样的 Typst 代码在渲染为 HTML 时,会生成一长串 MathML 标记,几乎所有现代主流网页浏览器都能正确解析。

The ability to use Typst to produce TeX-quality mathematics in web browsers, without requiring a JavaScript library such as MathJax or having to resort to images, is a boon for scientific communication. To enable the experimental HTML output, Typst requires a special flag: typst c --features html integral.typ integral.html.

能够使用 Typst 在网页浏览器中生成 TeX 品质的数学公式,且无需依赖 MathJax 等 JavaScript 库或使用图片,这对科学交流来说是一大福音。要启用实验性的 HTML 输出,Typst 需要一个特殊的标志:typst c --features html integral.typ integral.html

“Bundle” output

“捆绑包”(Bundle)输出

The typical use case for software such as Typst is the creation of single files, usually papers or books in the form of PDFs. The new “bundle” feature allows the author to specify a collection of output files, in any of the formats that Typst supports, in a single source file. These files can share data and contain both intra-document and inter-document links.

Typst 这类软件的典型用途是创建单个文件,通常是 PDF 格式的论文或书籍。新的“捆绑包”功能允许作者在单个源文件中指定一组输出文件,并支持 Typst 支持的任何格式。这些文件可以共享数据,并包含文档内和文档间的链接。

The feature is ideal for the creation of web sites, which consist of an interlinked network of HTML files. It should also be of interest to academics who might want to generate a slide deck for a conference talk along with the associated preprint from a single source file.

该功能非常适合创建由相互链接的 HTML 文件组成的网站。对于那些希望从单个源文件同时生成会议演示幻灯片和相关预印本论文的学者来说,这也极具吸引力。