zh-CN

Typst 0.13.0, RC 1 released

Published At: 2025-02-06 Tags: update

Typst 0.13.0, RC 1 版本发布了. changelog 见 这里.

以下是一份中文的简要更新日志:

#4273 feature Support Greek Numbering

支持希腊字母 numbering.

#4581 feature Add calc.norm() function to compute euclidean norms

添加 calc.norm() 用于计算范数.

typ
1
positional 参数为各分量 \
2
#calc.norm(1, 1)
3
4
可以指定 `p` 参数 \
5
#calc.norm(p: 3, 1, 1, 1)

#4729 feature Add support for page references through new ref.form property

现在可以用 ref(label, from: "page") 引用内容的页码, 类似于 LaTeX 中的 \pageref.

需要注意的是, 目前该 ref 的中文 supplement 还有待改进(如下图中的 supplement 仍为 page). 修复本问题可能需要对 ref 做更多改进, 相关 issue 有 #2485, #5102.

typ
1
#set page(numbering: "1")
2
= 你好 <hello>
3
#ref(<hello>, form: "page")

#4889 fix Disable justification in raw(block: true, ...)

默认情况下关闭行间 raw 中文本的两端对齐, 可以保证代码块的文字等宽.

#4985 fix Top and bottom (⊤ and ⊥) have different spacing around them

把 “⊤” 和 “⊥” 的默认 math class 修改为 normal 以修复其两侧的空格表现异常的问题.

#5008 breaking feature Better math argument parsing

对数学模式中函数调用的参数解析进行了一些调整, 包括:

typ
1
#let func(my-body: none) = my-body
2
$ func(my-body: a) $
曾经
现在
typ
1
$ mat(..#range(4).chunks(2)) $
曾经
现在
typ
1
#let func(my: none) = my
2
$ func(my: a, my: b) $
曾经
现在

#5202 feature fix Add math.accent support for flac and dtls OpenType features

让数学模式的 accent 支持 OpenType 特性 flac 和 dtls. 具体来说, 在使用支持这些特性的字体排版数学公式时, 如果公式中出现较大的上下标, 或者部分 accent 符号时, 字符会按字体设计的方式略微变形, 提供更好的视觉效果.

typ
1
$
2
f'(x)
3
$
曾经
现在

#5221 feature Embed files associated with the document as a whole

实现了 PDF 输出中无可见注释的文件嵌入功能.

typ
1
下面的代码会向 PDF 中嵌入一些附件.
2
#pdf.embed("hello.txt")
3
4
可以手动设置多项参数.
5
#pdf.embed("changelog.typ", description: "Source code of this document.", mime-type: "text/plain", relationship: "source")
6
7
也可以从 `bytes` 插入, 并且自定义文件名.
8
#let data = read("hello.txt", encoding: none)
9
#pdf.embed("hello2.txt", data)

#5229 feature Add a warning for is to anticipate using it as a keyword

现在用 is 做变量名的时候会被警告.

typ
1
#let is = 1
WARN:
`is` will likely become a keyword in future versions and will not be allowed as an identifier

Hint: rename this variable to avoid future errors

Hint: try `is_` instead

#5258 breaking fix Space between function name and parameter list should not be allowed in set rule

set 不再允许在函数名和括号之间加空格了.

typ
1
#set page (numbering: "1.")
ERR:
expected argument list
Hint: there may not be any spaces before the argument list

#5295 fix Fix clipping with outset

修复了 box 和 block 同时使用 outset 和 clip: true 时裁剪区域偏右下的问题.

typ
1
#block(
2
clip: true,
3
outset: 1em,
4
fill: yellow,
5
width: 2cm,
6
height: 2cm,
7
)[
8
#place(dx: -2em, dy: -2em, top + left, square())
9
#place(dx: +2em, dy: -2em, top + right, square())
10
#place(dx: -2em, dy: +2em, bottom + left, square())
11
#place(dx: +2em, dy:+ 2em, bottom + right, square())
12
]

#5305 feature Support for defining which charset should be covered by a font

现在可以手动指定哪些字符使用什么字体.

typ
1
// 只改变数字的字体
2
#set text(font: (
3
(name: "BlexMono Nerd Font Mono", covers: regex("[0-9]")),
4
"Libertinus Serif"
5
))
6
等宽: 110088 \
7
不等宽: Xyzwls
typ
1
// 中英文字体分别设置 (不需要手动 show 或者 re)
2
#set text(font: (
3
(name: "Libertinus Serif", covers: "latin-in-cjk"),
4
"Noto Sans CJK SC"
5
))
6
中文字体和 Latin Font 可以分别设置.

#5310 fix Refactor Parser

重构 parser, 主要解决了标记模式下 list 的一些问题和某些情况下编译器崩溃的问题.

typ
1
9. foo
2
- bar
3
10. foo
4
- bar
曾经
现在
typ
1
- foo
2
/**/- bar
3
/**/- baz
曾经
现在
typ
1
- foo
2
- bar
3
/**/ - baz
曾经
现在
typ
1
- foo
2
- bar
3
- baz
曾经
现在
typ
1
- foo
2
- bar
3
- baz
曾经
现在

#5316 fix Make math.bold compatible with Greek digamma

数学环境中的 bold 现在可以加粗希腊字母 digamma (Ϝ, ϝ) 了.

typ
1
$ Ϝ ϝ bold(Ϝ ϝ) $

#5323 feature New curve element that supersedes path

新添加了 curve 元素替代之前的 path.

新的 curve 元素支持一条 curve 中包含多段不同的 subcurve, 并且可以方便地调整闭合方式, 填充方式等.

typ
1
#set curve(fill: yellow)
2
#curve(
3
fill-rule: "even-odd",
4
stroke: black,
5
curve.move((10mm, 10mm)),
6
curve.line((20mm, 10mm)),
7
curve.line((20mm, 20mm)),
8
curve.close(),
9
curve.move((0mm, 5mm)),
10
curve.line((25mm, 5mm)),
11
curve.line((25mm, 30mm)),
12
curve.close(),
13
)
14
15
#curve(
16
stroke: black,
17
curve.move((10mm, 10mm)),
18
curve.cubic((5mm, 20mm), (15mm, 20mm), (20mm, 0mm), relative: true),
19
// 第一个控制点 auto 相当于前一条曲线的最后一个控制点
20
curve.cubic(auto, (15mm, -10mm), (20mm, 0mm), relative: true),
21
curve.close(mode: "straight")
22
)
23
24
#curve(
25
// 默认起点, 也可以手动指定
26
// curve.move(start: (0mm, 0mm)),
27
curve.quad((10mm, 0mm), (10mm, 10mm)),
28
curve.quad(auto, (10mm, 10mm), relative: true),
29
curve.close()
30
)

#5354 fix Fix unstoppable empty footnote loop

修复了之前给 footnote.entry 写 show 会导致编译器卡死的问题.

#5394 fix Fix unnecessary hyphenation

修复了布局时的某个计算精度问题, 防止某些时候出现错误的断行.

typ
1
#set par(justify: true)
2
#table(columns: 1, [Formal])
曾经
现在

#5411 feature Timings for state.at and state.get

现在 state.at 和 state.get 添加了计时数据, 便于观察使用了很多 state 的包或者文档的编译性能.

#5414 breaking Convert unopened square-brackets into a hard error

现在在标记模式下直接使用 ] 会报错.

typ
1
]
ERR:
unexpected closing bracket

Hint: try using a backslash escape: \]

#5444 fix Handle SIGPIPE

Typst CLI 现在可以输出到管道了(之前会直接 panic).

#5451 fix Fix sizing of quadratic shapes (square/circle)

修复了 square 和 circle 的 height 或者 width 参数超出其 size 时, 大小仍为 size 的值的问题.

typ
1
#square(height: 2cm)
2
#square(size: 2cm)
曾经
现在

#5457 fix Fix path with infinite length causing panic

修复了无穷长度的 path 会导致编译器崩溃的问题(现在会报错, 而不是直接崩溃).

typ
1
#path((0pt, 0pt), (float.inf * 1pt, 0pt))
ERR:
cannot create path with infinite length

#5458 fix Tags shouldn’t affect row height in equations

修复了在数学公式中插入 metadata 会轻微影响元素高度的问题.

typ
1
#box($ - - $, fill: silver)
2
#box($ #metadata(none) - - $, fill: silver) \
3
#box($ a \ - - $, fill: silver)
4
#box($ a \ #metadata(none) - - $, fill: silver)
5
#box($ - - \ a $, fill: silver)
6
#box($ #metadata(none) - - \ a $, fill: silver)
曾经
现在

#5459 fix Fix multiline annotations in over- elems in math changing the baseline

修复数学模式下 overbrace 等 over- 函数的多行标注导致基线偏移的问题.

typ
1
$ S = overbrace(beta (alpha) S I, "one line") - overbrace(mu (N), "two" \ "line") $
曾经
现在

#5473 fix Ignore leading and trailing ignorant fragments in math.lr

修复 math.lr 无法正常调整被套起来(比如用 box 或者 context)的括号大小的问题.

typ
1
#show "(": it => context it
2
$ (1 / 2) $
曾经
现在

#5477 fix Fix weak spacing being ignored unconditionally in math.lr

修复 math.lr 会吞掉其内部的某些 weak h 的问题.

typ
1
$ lr(\[x #h(1em, weak: true)a) $
曾经
现在

#5480 feature Add support for interpreting f32 in float.{from-bytes, to-bytes}

现在 float.from-bytes 和 float.to-bytes 支持 f32 了.

typ
1
#range(4).map(x => float.to-bytes(1.5, size: 4).at(x)) \
2
#float.from-bytes(bytes((0, 0, 192, 63)))

#5481 feature Let decimal constructor accept decimal values

现在可以用 decimal 创建 decimal 了.

typ
1
#decimal(decimal(3))

#5483 fix Use extended shape information for glyph text_like-ness

修复了 math.lr 的上下标在某些情况下位置没有被拉伸的问题.

typ
1
$ lr(|,size: #3em)_a^b $
曾经
现在

#5492 fix Make math.italic compatible with ħ

math.italic 现在也能让 ħ 变成斜体(ℏ)了.

typ
1
$ ħ $
曾经
现在

#5497 fix Forbid footnote migration in pending floats

修复了待定浮动元素中的脚注迁移导致的编译器崩溃问题.

#5498 fix Fix infinite loop with footnote which never fits

修复了过大的 footnote 在布局时导致死循环和 OOM 的问题.

#5502 fix Fix text fill within clip: true blocks in PNG export

修复了在 clip 为 true 的 block 内的半透明文本填充色无法正确设置的问题.

typ
1
#block(clip: false, {
2
text(fill: blue.transparentize(50%), "Hello, World")
3
})
4
#block(clip: true, {
5
text(fill: blue.transparentize(50%), "Hello, World")
6
})
曾经
现在

#5505 feature Improve symbol repr

改进了 symbol 的 repr, 现在会显示更多信息.

typ
1
#repr(sym.amp) \
2
#repr(sym.amp.inv) \
3
#repr(sym.smash)
曾经
现在

#5513 feature HTML foundation 等

HTML 导出相关功能, 具体支持情况见 Tracking issue for HTML export.

与 HTML 导出相关的 PR 还有 #5522, #5524, #5525, #5530, #5532, #5533, #5594, #5619, #5661, #5665, #5666, #5673, #5676, #5744, #5745.

此外, 还添加了 set document(description: str), 用于为 PDF 和 HTML 输出设置文档描述.

typ
1
以下代码可以给文档设置描述
2
#set document(description: "简单的 0.13.0-rc1 更新日志")

#5526 fix Ensure par and align interrupt cite groups and lists

确保对 par 和 align 样式的更改不仅会中断段落, 还会中断列表和引用. 用于修复嵌套在 align 或者 par 内的 cite 和 list 导致样式错误, 现在这样做会导致警告, 且隐藏嵌套的元素.

typ
1
+ a
2
#par[+ b]
3
+ c
曾经
现在

#5528 feature Add missing functions to the gradient object

给 radial 和 conic 渐变添加了多个获取属性的函数, 包括 gradient.center(), gradient.radius(), gradient.focal_center(), gradient.focal_radius().

typ
1
#let rad = gradient.radial(..color.map.viridis)
2
#rad.center() \
3
#rad.radius() \
4
#rad.focal-center() \
5
#rad.focal-radius() \
6
7
#let con = gradient.conic(..color.map.viridis)
8
#con.center()

#5545 fix Fix multiple footnotes in footnote entry

修复了在 footnote 内引用多个 footnote 时, 只有第一个引用的 entry 显示的问题.

typ
1
你好#footnote[这是一个引用了#footnote[第二个脚注] 和 #footnote[第三个脚注]的脚注]
曾经
现在

#5548 breaking fix Forbid base prefix for numbers with a unit

禁止在有单位的值中使用 如 0x, 0b 等进制前缀.

typ
1
#0b0011pt
ERR:
invalid base-2 prefix

Hint: numbers with a unit cannot have a base prefix

#5550 fix Fix language-dependant figure caption separator in outline

现在目录中的 figure 条目中, caption 和 numbering 的分隔符(对于中文来说, 就是空格)也会跟随语言改变.

typ
1
#set text(lang: "zh")
2
#outline(target: selector(figure))
3
#figure(rect(), caption: [A rectangle])
曾经
现在

#5562 fix Fix crash due to consecutive weak spacing

修复某些情况下连续弱空格导致的崩溃.

typ
1
#set par(justify: true)
2
#set heading(numbering: "I.")
3
= #h(0.3em, weak: true) test
曾经
现在

#5563 feature Add reversed numbering

支持 enum 的反向编号.

typ
1
#set enum(reversed: true)
2
+ 你好
3
+ 你好吗
4
+ 你好哦

#5564 feature Add timezone to PDF’s default timestamp

添加了一个 CLI 参数 --creation-timestamp:

  1. 如果 document.date 被设置为 none 或者 datetime(...), 输出 PDF 的元数据会使用设置的值
  2. 如果document.date 为默认值 auto

    1. 如果设置了 --creation-timestamp, 输出 PDF 的时区将设置为 UTC
    2. 否则, 将被设置为本地时区

#5571 fix Change error when accessing non-existent label

优化了某些情况下访问不存在的字段的错误提示.

typ
1
#[].foo
曾经
现在

#5575 fix Derivation comment for calculation in repeat

通过对 repeat 逻辑的一些改进修复了使用 repeat 创建 link 时造成的 PDF 体积过大的问题.

相关的 PR 还有 5732.

#5581 fix Fix sticky blocks at the top of blocks and pages

修复了在 block 或 page 顶部的 sticky block 不 sticky 的问题.

typ
1
#set page(height: 3cm, fill: luma(230))
2
#v(1.6cm)
3
#block(height: 2cm, breakable: true)[
4
#block(sticky: true)[*A*]
5
6
b
7
]
曾经
现在

#5587 breaking fix Error on duplicate symbol variant with modifiers in different orders

现在在 symbol 中定义两个 modifiers 相同但是顺序不同的符号会导致编译错误.

typ
1
#let s = symbol(
2
("foo.bar", "A"),
3
("bar.foo", "B"),
4
)
5
6
#s.foo
7
#s.bar
8
#s.foo.bar
9
#s.bar.foo
曾经
现在

#5589 feature Get numbering of page counter from style chain

现在 Typst 可以自动处理 page.numbering 为 none 时的 counter(page).display(). 所以我们可以不需要再写

typ
1
#set page(footer: context {
2
let page-numbering = if page.numbering != none { page.numbering } else { "1" }
3
counter(page).display(page-numbering)
4
})

而是可以直接

typ
1
#set page(footer: context counter(page).display())

#5590 Rename pattern to tiling

把 pattern 改为 tiling.

#5591 breaking Remove deprecated things and compatibility behaviours

彻底删除上个版本就已经警告 deprecated 的内容, 具体来说, 包含:

#5596 fix Fix math size resolving

修复数学模式中某些情况下的文字大小解析.

typ
1
#let size = context [#text.size.to-absolute() #(1em).to-absolute()]
2
$ a^size $
曾经
现在

#5610 fix Fix crash when block or text have negative sizes

修复 block 或者 text 的大小为负时的编译器崩溃.

#5613 fix Fix arbitrarily nested equations in the base of math.attach

修复 math.attach 在处理多层嵌套的 math.equation 不能正常工作的问题.

typ
1
#{
2
let body = $stretch(=)$
3
body = $body$
4
$ body^"long text" $
5
}
曾经
现在

#5632 feature Include images from raw pixmaps and more

image 现在可以用 pixmap 创建, 并且可以指定编码方式, ICC 等. 此外, 现在还可以使用 scaling 参数指示查看器应该如何缩放图片(平滑或像素化).

typ
1
#image(
2
bytes(range(16).map(x => x * 16)),
3
format: (
4
encoding: "luma8",
5
width: 4,
6
height: 4,
7
),
8
// auto, "pixelated", "smooth"
9
scaling: "pixelated",
10
width: 3cm,
11
icc: auto,
12
)

#5651 feature Allow adding and joining arguments

现在 arguments 也可以 add 和 join 了.

typ
1
#{ arguments(1) + arguments(2) } \
2
#{ (arguments(1), arguments(2)).join() }

#5652 feature Improve repr for arguments

现在 arguments 的 repr 会显示类似于 constructor 的格式.

typ
1
#repr(arguments(1))
曾经
现在

#5655 feature Add support for c2sc OpenType feature in smallcaps

给 smallcaps 添加了 OpenType 的 c2sc 特性支持.

c2sc 特性可以将大写字母转换为小型大写字母, 之前 smallcaps 的默认行为是使用 smcp 特性将小写字母转换为小型大写字母).

typ
1
#set text(font: "Libertinus Serif")
2
#smallcaps("Hello World", all: true) \
3
#smallcaps("Hello World", all: false)

#5659 fix Avoid stripping url prefixes multiple times or multiple prefixes

防止多次删除 URL 前缀.

typ
1
#link("mailto:foo") \
2
#link("mailto:tel:foo") \
3
#link("mailto:mailto:foo")
曾经
现在

#5671 feature Revamp data loading and deprecate decode functions

重构了多种支持传入路径的函数的 API, 具体为:

#5702 feature Ignore shebang at start of file

.typ 文件首行的 shebang (#! 开头的一行文字, 用于指定该文件的解释器) 会被 Typst 编译器忽略.

typ
1
#!/usr/bin/typst c
2
运行此文件会直接产生 PDF 输出

#5728 feature Support syntactically directly nested list, enum, and term list

优化了嵌套 list, enum, terms 的写法.

之前, 为了产生嵌套的上述元素, 我们必须使用换行和缩进, 比如

typ
1
+ first main
2
+
3
- first sub
4
- second sub

现在不需要额外的换行了.

typ
1
+ first main
2
+ - first sub
3
- second sub

#5733 feature Methods on elements

现在可以通过 element.func() 的语法调用元素的函数, 目前仅用于下一条.

#5735 feature fix Rework outline

对 outline 进行了多项改良, 具体包括:

#5738 fix Add SymbolElem to improve math character styling and fix $"a"$ vs. $a$

修复 $"a"$ 不是斜体的问题.

typ
1
$ "a" $
曾经
现在

#5739 fix Fix delimiter unparen syntax

修复某些情况下手动 $lr([])$ 和 $[]$ 的不同.

typ
1
#let item = $limits(sum)_i$
2
$
3
1 / lr([item]) quad
4
1 / [item]
5
$
曾经
现在

#5746 feature Semantic paragraphs

引入了一些区分语义段落和普通文本的规则, 主要用于 HTML 输出和首行缩进的修复, 具体来说

#5753 fix Disable cjk_latin_spacing in raw by default

默认情况下在 raw 中关闭 CJK 文字和拉丁文字间的空格.

#5768 feature Support first-line-indent for every paragraph

支持对所有段落设置首行缩进.

typ
1
#set par(first-line-indent: (amount: 2em, all: true))
2
= 标题
3
标题下首段也能缩进了.

#5773 breaking Resolve bound name of bare import statically

改变了无导入列表, 无重命名的 import 解析绑定名称的行为, 具体来说, 现在的绑定名不再动态解析, 而是必须在 AST 中静态地已知.

typ
1
#import "te" + "st.typ"
2
这是一个不静态的 `import`
ERR:
cannot determine binding name for this import

Hint: the name must be statically known
Hint: you can rename the import with `as`
Hint: to import specific items from a dynamic source, add a colon followed by an import list

#5779 breaking feature Modular, multi-threaded, transitioning plugins

对插件系统做了一些改进, 具体包括:

typ
1
#import plugin("mycalc.wasm"): myadd, mymut
2
#myadd(3, 5) \
3
#mymut.with(3)(5)
typ
1
#let base = plugin("mut.wasm")
2
变化前的 `base`: #base.get() \
3
4
#let mutated = plugin.transition(base.add, "hello")
5
变化后的 `base`: #base.get() \
6
变化后的返回值 `mutated`: #mutated.get()

#5788 fix Change type repr to short name

现在 repr 某个类型会显示较短的那个名字, 和代码中使用的标识符更统一. 但是, 把类型转为 str 仍然会显示较长的那个名字.

typ
1
#repr(int)
2
#str(int)
曾经
现在

breaking feature 符号变动

类型 代码 符号 类型 代码 符号
添加 $eq.triple.not$
添加 $asymp$
添加 $asymp.not$
添加 $lcm$
添加 $asymp$
添加 $asymp.not$
添加 $mapsto$
添加 $mapsto.long$
添加 $divides.not.rev$
添加 $divides.struck$
添加 $interleave$
添加 $interleave.big$
添加 $interleave.struck$
添加 $eq.triple.not$
添加 $eq.dots$
添加 $eq.dots.down$
添加 $eq.dots.up$
添加 $smt$
添加 $smt.eq$
添加 $lat$
添加 $lat.eq$
添加 $colon.tri$
添加 $colon.tri.op$
添加 $dagger.triple$
添加 $dagger.l$
添加 $dagger.r$
添加 $dagger.inv$
添加 sym.hourglass.stroked ⧖
添加 sym.hourglass.filled ⧗ 添加 sym.die.six ⚅
添加 sym.die.five ⚄ 添加 sym.die.four ⚃
添加 sym.die.three ⚂ 添加 sym.die.two ⚁
添加 sym.die.one ⚀ 添加 sym.errorbar.square.stroked ⧮
添加 sym.errorbar.square.filled ⧯ 添加 sym.errorbar.diamond.stroked ⧰
添加 sym.errorbar.diamond.filled ⧱ 添加 sym.errorbar.circle.stroked ⧲
添加 sym.errorbar.circle.filled ⧳ 添加 sym.numero №
变更 $sect$$inter$
变更 $sect.and$$inter.and$
变更 $sect.big$$inter.big$
变更 $sect.dot$$inter.dot$
变更 $sect.double$$inter.double$
变更 $sect.sq$$inter.sq$
变更 $sect.sq.big$$inter.sq.big$
变更 $sect.sq.double$$inter.sq.double$
变更 $integral.sect$$integral.inter$
变更 $ohm.inv$$Omega.inv$
删除 $diff$
删除 $degree.c$
删除 $degree.f$
删除 $kelvin$

相关 PR 包括 #5326, #5372, #5388, #5391, #5718, 以及 typst/codex 仓库创建以来的所有 PR.