Skip to content

Commit cdb9817

Browse files
dev: changes
1 parent 933f608 commit cdb9817

28 files changed

+303
-331
lines changed

src/basic/png.typ

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/basic/reference-calculation.typ

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919

2020
// calc.*
2121

22+
#todo-box[不再需要等待了]
2223
等待#link("https://github.com/typst/typst/pull/3489")[PR: Begin migration of calc functions to methods]

src/basic/reference-grammar.typ

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,14 +754,14 @@
754754
),
755755
(
756756
[获取位置],
757-
refs.content-scope-style.with(reference: <grammar-locate>),
757+
refs.content-scope-style.with(reference: <grammar-here>),
758758
````typ
759759
#context here().position()
760760
````,
761761
),
762762
(
763763
[检测当前页面是否为偶数页(位置相关计算)],
764-
refs.content-scope-style.with(reference: <grammar-locate-calc>),
764+
refs.content-scope-style.with(reference: <grammar-here-calc>),
765765
````typ
766766
#context [ 页码是偶数:#calc.even(here().page()) ]
767767
````,

src/basic/reference-math-symbols.typ

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@
7777
[$plus.minus$], [`plus.minus`], [$minus.plus$], [`minus.plus`], [$lt.tri$], [`lt.tri`],
7878
[$dot$], [`dot`], [$div$], [`div`], [$gt.tri$], [`gt.tri`],
7979
[$times$], [`times`], [$without$], [`without`], [$star$], [`star`],
80-
[$union$], [`union`], [$sect$], [`sect`], [$*$], [`*`],
81-
[$union.sq$], [`union.sq`], [$sect.sq$], [`sect.sq`], [$circle.stroked.tiny$], [`circle.stroked.tiny`],
80+
[$union$], [`union`], [$inter$], [`inter`], [$*$], [`*`],
81+
[$union.sq$], [`union.sq`], [$inter.sq$], [`inter.sq`], [$circle.stroked.tiny$], [`circle.stroked.tiny`],
8282
[$or$], [`or`], [$and$], [`and`], [$bullet$], [`bullet`],
8383
[$xor$], [`xor`], [$minus.circle$], [`minus.circle`], [$dot.circle$], [`dot.circle`],
8484
[$union.plus$], [`union.plus`], [$times.circle$], [`times.circle`], [$circle.big$], [`circle.big`],
@@ -100,7 +100,7 @@
100100
table(
101101
columns: 6,
102102
[$sum$], [`sum`], [$union.big$], [`union.big`], [$or.big$], [`or.big`],
103-
[$product$], [`product`], [$sect.big$], [`sect.big`], [$and.big$], [`and.big`],
103+
[$product$], [`product`], [$inter.big$], [`inter.big`], [$and.big$], [`and.big`],
104104
[$product.co$], [`product.co`], [$union.sq.big$], [`union.sq.big`], [$union.plus.big$], [`union.plus.big`],
105105
[$integral$], [`integral`], [$integral.cont$], [`integral.cont`], [$dot.circle.big$], [`dot.circle.big`],
106106
[$plus.circle.big$], [`plus.circle.big`], [$times.circle.big$], [`times.circle.big`],
@@ -138,7 +138,7 @@
138138
[$dots.down$], [`dots.down`], [$planck.reduce$], [`planck.reduce`], [$dotless.i$], [`dotless.i`],
139139
[$dotless.j$], [`dotless.j`], [$ell$], [`ell`], [$Re$], [`Re`],
140140
[$Im$], [`Im`], [$aleph$], [`aleph`], [$forall$], [`forall`],
141-
[$exists$], [`exists`], [$ohm.inv$], [`ohm.inv`], [$partial$], [`partial`],
141+
[$exists$], [`exists`], [$Omega.inv$], [`Omega.inv`], [$partial$], [`partial`],
142142
[$prime$], [`', prime`], [$emptyset$], [`emptyset`], [$infinity$], [`infinity`],
143143
[$nabla$], [`nabla`], [$triangle.stroked.t$], [`triangle.stroked.t`], [$square.stroked$], [`square.stroked`],
144144
[$diamond.stroked$], [`diamond.stroked`], [$bot$], [`bot`], [$top$], [`top`],

src/basic/scripting-block-and-expression.typ

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ Typst脚本的核心重点就在本段。
448448

449449
```typ
450450
#[
451-
= 生活在Content树上
452-
现代社会以海德格尔的一句“一切实践传统都已经瓦解完了”为嚆矢。滥觞于家庭与社会传统的期望正失去它们的借鉴意义。但面对看似无垠的未来天空,我想循卡尔维诺“树上的男爵”的生活好过过早地振翮。
451+
= 生活在Content树上
452+
现代社会以海德格尔的一句“一切实践传统都已经瓦解完了”为嚆矢。滥觞于家庭与社会传统的期望正失去它们的借鉴意义。但面对看似无垠的未来天空,我想循卡尔维诺“树上的男爵”的生活好过过早地振翮。
453453
]
454454
```
455455

@@ -461,7 +461,7 @@ Typst脚本的核心重点就在本段。
461461
```
462462

463463
#pro-tip[
464-
实际上有区别,由于多两个换行,前后各多一个Space Element。
464+
实际上有区别,由于多两个换行和缩进,前后各多一个Space Element。
465465
]
466466

467467
// == Hello World程序

src/basic/scripting-color-and-shape.typ

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Typst只有一种颜色类型,其由两部分组成。
3434

3535
== 色彩空间
3636

37-
RGB是我们最使用的色彩空间,对应Typst的`color.rgb`函数或`rgb`函数:
37+
RGB是我们使用最多的色彩空间,对应Typst的`color.rgb`函数或`rgb`函数:
3838

3939
#code(```typ
4040
#box(square(fill: color.rgb("#b1f2eb")))
@@ -121,12 +121,15 @@ Typst不仅支持颜色填充,还支持按照固定的模式将其他图形对
121121
length: 30%, stroke: 2pt + maroon)
122122
```)
123123

124-
除了直线,Typst还支持贝塞尔曲线。贝塞尔曲线是一种光滑的曲线,由一系列点和控制点组成。
124+
除了直线,Typst还支持二次、三次贝塞尔曲线,以及它们和直线的组合。贝塞尔曲线是一种光滑的曲线,由一系列点和控制点组成。
125125

126126
#code(```typ
127-
#path(
127+
#curve(
128128
stroke: blue,
129-
((100%, 0pt), (60%, 0pt)), (0pt, 20pt),
129+
curve.move((0pt, 20pt)),
130+
curve.quad((40%, 0pt), (100%, 0pt)),
131+
curve.line((100%, 20pt)),
132+
curve.close()
130133
)
131134
```)
132135

@@ -161,13 +164,13 @@ Typst不仅支持颜色填充,还支持按照固定的模式将其他图形对
161164
填充样式(fill)是另一个重要的图形属性。如果一个路径是闭合的,那么它可以被填充。
162165

163166
#code(```typ
164-
#path(
167+
#curve(
165168
fill: blue.lighten(80%),
166169
stroke: blue,
167-
closed: true,
168-
(0pt, 50pt),
169-
(100%, 50pt),
170-
((50%, 0pt), (40pt, 0pt)),
170+
curve.move((0pt, 50pt)),
171+
curve.line((100pt, 50pt)),
172+
curve.cubic(none, (90pt, 0pt), (50pt, 0pt)),
173+
curve.close(),
171174
)
172175
```)
173176

@@ -193,7 +196,7 @@ Typst为你预定义了一些基于贝塞尔曲线的闭合图形元素。下例
193196

194197
== 多边形
195198

196-
多边形是唯一一个使用直线组合而成的闭合图形。你可以使用`polygon`函数构造一个多边形。
199+
多边形是仅使用直线组合而成的闭合图形。你可以使用`polygon`函数构造一个多边形。
197200

198201
#code(```typ
199202
#polygon(

src/basic/scripting-length-and-layout.typ

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ Typst的布局引擎仍未完成,其主要#absent[缺失]或#ng[不足]的内
237237
Typst的布局代码风格是用一系列容器函数包装的内容,再将整个内容交给布局引擎反复*迭代*求解。容器就是一类特殊的「元素」,它并不真正具备具体的内容,而仅仅容纳一个或多个「内容」,*以便布局*。这与JSX有些相似。
238238

239239
针对PDF页面模型,Typst构建了完整的容器层次。Todo:用cetz绘制层次:
240+
#todo-box[在0.13.0之后, 情况有所改变]
240241

241242
1. page,一个PDF有很多页。
242243
2. par,一个文档中有很多段。

src/basic/scripting-literal-and-variable.typ

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ Typst中所有字符串都是`utf-8`编码的,因此使用时不存在编码
243243
```)
244244

245245
== 计算标准库
246-
247-
由于该库即将废弃(本文将介绍新的计算API),如有希望使用的朋友,请参见#link("https://typst.app/docs/reference/foundations/calc")[Typst Reference - Calculation]。
246+
#todo-box[写完]
247+
请参见#link("https://typst.app/docs/reference/foundations/calc")[Typst Reference - Calculation]。
248248

249249
== 浮点数陷阱
250250

@@ -474,27 +474,25 @@ Typst中所有字符串都是`utf-8`编码的,因此使用时不存在编码
474474

475475
#code(```typ
476476
#let f = (x, y) => [#(x)和#(y)。]
477-
#f("", "你")
477+
#f("", "你")
478478
```)
479479

480480
我们可以看到其以箭头为体,两侧为参数列表和函数体。不像「函数声明」,它不需要取名。
481481

482-
闭包以其匿名特征,很适合用作参数传入其他函数,即作为「回调」函数。我们将会在下一章经常使用「回调」函数。例如,Typst提供一个`locate`函数,其接受一个函数类型的参数:
483-
484-
#todo-box[
485-
已经无法编译。
486-
]
482+
闭包以其匿名特征,很适合就地使用,让我们不必为一个暂时使用的函数起名,例如作为「回调」函数。我们将会在下一章经常使用「回调」函数。例如,Typst提供了「`show`」语法,其可以接收一个选择器和一个函数,并将其作用范围内被选择器选中的内容都使用给定函数处理:
487483

488-
```typ
489-
#let f(loc) = [当前页码为#loc.page()。]
490-
#locate(f)
491-
```
484+
#code(```typ
485+
#let style(body) = text(blue, underline(body))
486+
#show heading.where(level: 3): style
487+
=== 标题
488+
```)
492489

493490
但是,等价地,此时「函数声明」不如「闭包声明」优美:
494491

495-
```typ
496-
#locate(loc => [当前页码为#loc.page()。])
497-
```
492+
#code(```typ
493+
#show heading.where(level: 3): it => text(blue, underline(it))
494+
=== 标题
495+
```)
498496

499497
// #let x = 1;
500498

@@ -591,15 +589,15 @@ Typst提供了一系列「成员」和「方法」访问字面量、变量与函
591589

592590
== 字典字面量 <grammar-dict-literal>
593591

594-
所谓「字典」即是「键值对」的集合,其每一项是由冒号分隔的「键值对」。如下例所示,冒号左侧,“neco-mimi”等「标识符」或「字符串」是字典的「键而冒号右侧分别是对应的「值」。
592+
所谓「字典」即是「键值对」的集合,其每一项是由冒号分隔的「键值对」。如下例所示,冒号左侧,“neco-mimi”等「标识符」或「字符串」是字典的「键」,而冒号右侧分别是对应的「值」。
595593

596594
#code(```typ
597595
#(neko-mimi: 2, "utterance": "喵喵喵")
598596
```)
599597

600598
== 数组和字典的成员访问
601599

602-
为了访问数组,你可以使用`at`方法。“at”在中文里是“在”的意思,它表示对「数组」使用「索引」操作。在数组中,第0个值就是其第一个值,第 $N$ 个值就是其第 $N + 1$ 个值,以此类推。如下所示:
600+
为了访问数组,你可以使用`at`方法。“at”在中文里是“在”的意思,它表示对「数组」使用「索引」操作。`at(0)`索引到第1个值,`at(n)`索引到第 $n + 1$ 个值,以此类推。如下所示:
603601

604602
#code(```typ
605603
#let x = (1, "OvO", [一段内容])
@@ -744,6 +742,7 @@ Typst提供了一系列「成员」和「方法」访问字面量、变量与函
744742

745743
=== 参数解构 <grammar-destructing-param>
746744

745+
#todo-box[写完]
747746
todo参数解构。
748747

749748
== 总结

src/basic/scripting-scope-and-style.typ

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ CeTZ利用内容树制作“内嵌的DSL”。CeTZ的`canvas`函数接收的不
405405
例如它的`line`函数的返回值,就完全不是一个内容,而是一个无法窥视的函数。
406406

407407
#code(```typ
408-
#import "@preview/cetz:0.3.1"
408+
#import "@preview/cetz:0.3.4"
409409
#repr(cetz.draw.line((0, 0), (1, 1), fill: blue))
410410
```)
411411

@@ -414,7 +414,7 @@ CeTZ利用内容树制作“内嵌的DSL”。CeTZ的`canvas`函数接收的不
414414
使用混合语言,在Typst中可以很优雅地画多面体:
415415

416416
#code.with(al: top)(```typ
417-
#import "@preview/cetz:0.3.1"
417+
#import "@preview/cetz:0.3.4"
418418
#align(center, cetz.canvas({
419419
// 导入cetz的draw方言
420420
import cetz.draw: *; import cetz.vector: add
@@ -429,30 +429,34 @@ CeTZ利用内容树制作“内嵌的DSL”。CeTZ的`canvas`函数接收的不
429429
}))
430430
```)
431431

432-
=== PNG.typ的树
432+
=== curryst的「树」
433433

434434
我们知道「内容块」与「代码块」没有什么本质区别。
435435

436-
如果我们可以基于「代码块」描述一棵「内容」的树,那么一张PNG格式的图片似乎也可以被描述为一棵「字节」的树
436+
如果我们可以基于「代码块」描述一棵「内容」的树,那么逻辑推理的过程也可以被描述为条件、规则、结论的树
437437

438-
通过代码块语法,你可以在Typst中拼接字节,依像素地创建一张PNG格式的图片
438+
#link("https://typst.app/universe/package/curryst/")[curryst]包提供了接收条件、规则、结论参数的`rule`函数,其返回一个包含传入信息的`dict`,并且允许把`rule`函数返回的`dict`作为`rule`的部分参数。于是我们可以通过嵌套`rule`函数建立描述推理过程的树,并通过该包提供的`prooftree`函数把包含推理过程的`dict`树画出来
439439

440-
#code.with(al: top)(```typ
441-
// Origin: https://typst.app/project/r0SkRmsZYIYNxjs6Q712aP
442-
#import "png.typ": *
443-
#let prelude = (0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A)
444-
#let ihdr(w, h) = chunk("IHDR", be32(w) + be32(h) + (8, 2, 0, 0, 0))
445-
#let idat(lines) = chunk("IDAT", {
446-
let data = lines.map(line => (0x00,) + line).flatten()
447-
let len = le32(data.len()).slice(0, 2)
448-
(0x08, 0x1D, 0x01); len; len.map(xor.with(0xFF)); data; be32(adler32(data))
449-
})
450-
#align(center, box(width: 25%, image.decode(bytes({
451-
let (w, h) = (8, 8)
452-
prelude; ihdr(w, h); idat( for y in range(h) {( for x in range(w) {
453-
(calc.floor(256 * x / w), 128, calc.floor(256 * y / h))
454-
}, )} ); chunk("IEND", ())
455-
}))))
440+
#code(```typ
441+
#import "@preview/curryst:0.5.0": rule, prooftree
442+
#let tree-dict = rule(
443+
name: $R$,
444+
$C_1 or C_2 or C_3$,
445+
rule(
446+
name: $A$,
447+
$C_1 or C_2 or L$,
448+
rule(
449+
$C_1 or L$,
450+
$Pi_1$,
451+
),
452+
),
453+
rule(
454+
$C_2 or overline(L)$,
455+
$Pi_2$,
456+
),
457+
)
458+
`tree-dict`的类型:#type(tree-dict) \
459+
`tree-dict`代表的树:#prooftree(tree-dict)
456460
```)
457461

458462
== 「`show`」语法 <grammar-show>

0 commit comments

Comments
 (0)