Skip to content

build: bump typst to v0.13.1 and shiroa to v0.3.1-rc2 #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- run: git submodule update --init --recursive
- name: Download & install shiroa
run: |
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.2.0/shiroa-installer.sh | sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.3.1-rc2/shiroa-installer.sh | sh
- name: Build Book
run: |
shiroa build --font-path ./assets/typst-fonts/ --font-path ./assets/fonts/ --path-to-root /tutorial/ -w . src
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh_pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
curl -L https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.1.2/font-assets.tar.gz | tar -xvz -C assets/fonts
- name: Download & install shiroa
run: |
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.2.0/shiroa-installer.sh | sh
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/Myriad-Dreamin/shiroa/releases/download/v0.3.1-rc2/shiroa-installer.sh | sh
- name: Build Book
run: |
shiroa build --font-path ./assets/typst-fonts/ --font-path ./assets/fonts/ --path-to-root /tutorial/ -w . src
Expand Down
60 changes: 0 additions & 60 deletions src/basic/png.typ

This file was deleted.

1 change: 1 addition & 0 deletions src/basic/reference-calculation.typ
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@

// calc.*

#todo-box[不再需要等待了]
等待#link("https://github.com/typst/typst/pull/3489")[PR: Begin migration of calc functions to methods]
4 changes: 2 additions & 2 deletions src/basic/reference-grammar.typ
Original file line number Diff line number Diff line change
Expand Up @@ -754,14 +754,14 @@
),
(
[获取位置],
refs.content-scope-style.with(reference: <grammar-locate>),
refs.content-scope-style.with(reference: <grammar-here>),
````typ
#context here().position()
````,
),
(
[检测当前页面是否为偶数页(位置相关计算)],
refs.content-scope-style.with(reference: <grammar-locate-calc>),
refs.content-scope-style.with(reference: <grammar-here-calc>),
````typ
#context [ 页码是偶数:#calc.even(here().page()) ]
````,
Expand Down
8 changes: 4 additions & 4 deletions src/basic/reference-math-symbols.typ
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
[$plus.minus$], [`plus.minus`], [$minus.plus$], [`minus.plus`], [$lt.tri$], [`lt.tri`],
[$dot$], [`dot`], [$div$], [`div`], [$gt.tri$], [`gt.tri`],
[$times$], [`times`], [$without$], [`without`], [$star$], [`star`],
[$union$], [`union`], [$sect$], [`sect`], [$*$], [`*`],
[$union.sq$], [`union.sq`], [$sect.sq$], [`sect.sq`], [$circle.stroked.tiny$], [`circle.stroked.tiny`],
[$union$], [`union`], [$inter$], [`inter`], [$*$], [`*`],
[$union.sq$], [`union.sq`], [$inter.sq$], [`inter.sq`], [$circle.stroked.tiny$], [`circle.stroked.tiny`],
[$or$], [`or`], [$and$], [`and`], [$bullet$], [`bullet`],
[$xor$], [`xor`], [$minus.circle$], [`minus.circle`], [$dot.circle$], [`dot.circle`],
[$union.plus$], [`union.plus`], [$times.circle$], [`times.circle`], [$circle.big$], [`circle.big`],
Expand All @@ -100,7 +100,7 @@
table(
columns: 6,
[$sum$], [`sum`], [$union.big$], [`union.big`], [$or.big$], [`or.big`],
[$product$], [`product`], [$sect.big$], [`sect.big`], [$and.big$], [`and.big`],
[$product$], [`product`], [$inter.big$], [`inter.big`], [$and.big$], [`and.big`],
[$product.co$], [`product.co`], [$union.sq.big$], [`union.sq.big`], [$union.plus.big$], [`union.plus.big`],
[$integral$], [`integral`], [$integral.cont$], [`integral.cont`], [$dot.circle.big$], [`dot.circle.big`],
[$plus.circle.big$], [`plus.circle.big`], [$times.circle.big$], [`times.circle.big`],
Expand Down Expand Up @@ -138,7 +138,7 @@
[$dots.down$], [`dots.down`], [$planck.reduce$], [`planck.reduce`], [$dotless.i$], [`dotless.i`],
[$dotless.j$], [`dotless.j`], [$ell$], [`ell`], [$Re$], [`Re`],
[$Im$], [`Im`], [$aleph$], [`aleph`], [$forall$], [`forall`],
[$exists$], [`exists`], [$ohm.inv$], [`ohm.inv`], [$partial$], [`partial`],
[$exists$], [`exists`], [$Omega.inv$], [`Omega.inv`], [$partial$], [`partial`],
[$prime$], [`', prime`], [$emptyset$], [`emptyset`], [$infinity$], [`infinity`],
[$nabla$], [`nabla`], [$triangle.stroked.t$], [`triangle.stroked.t`], [$square.stroked$], [`square.stroked`],
[$diamond.stroked$], [`diamond.stroked`], [$bot$], [`bot`], [$top$], [`top`],
Expand Down
6 changes: 3 additions & 3 deletions src/basic/scripting-block-and-expression.typ
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,8 @@ Typst脚本的核心重点就在本段。

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

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

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

// == Hello World程序
Expand Down
23 changes: 13 additions & 10 deletions src/basic/scripting-color-and-shape.typ
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Typst只有一种颜色类型,其由两部分组成。

== 色彩空间

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

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

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

#code(```typ
#path(
#curve(
stroke: blue,
((100%, 0pt), (60%, 0pt)), (0pt, 20pt),
curve.move((0pt, 20pt)),
curve.quad((40%, 0pt), (100%, 0pt)),
curve.line((100%, 20pt)),
curve.close()
)
```)

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

#code(```typ
#path(
#curve(
fill: blue.lighten(80%),
stroke: blue,
closed: true,
(0pt, 50pt),
(100%, 50pt),
((50%, 0pt), (40pt, 0pt)),
curve.move((0pt, 50pt)),
curve.line((100pt, 50pt)),
curve.cubic(none, (90pt, 0pt), (50pt, 0pt)),
curve.close(),
)
```)

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

== 多边形

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

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

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

1. page,一个PDF有很多页。
2. par,一个文档中有很多段。
Expand Down
33 changes: 16 additions & 17 deletions src/basic/scripting-literal-and-variable.typ
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ Typst中所有字符串都是`utf-8`编码的,因此使用时不存在编码
```)

== 计算标准库

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

== 浮点数陷阱

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

#code(```typ
#let f = (x, y) => [#(x)和#(y)。]
#f("", "你")
#f("", "你")
```)

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

闭包以其匿名特征,很适合用作参数传入其他函数,即作为「回调」函数。我们将会在下一章经常使用「回调」函数。例如,Typst提供一个`locate`函数,其接受一个函数类型的参数:

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

```typ
#let f(loc) = [当前页码为#loc.page()。]
#locate(f)
```
#code(```typ
#let style(body) = text(blue, underline(body))
#show heading.where(level: 3): style
=== 标题
```)

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

```typ
#locate(loc => [当前页码为#loc.page()。])
```
#code(```typ
#show heading.where(level: 3): it => text(blue, underline(it))
=== 标题
```)

// #let x = 1;

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

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

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

#code(```typ
#(neko-mimi: 2, "utterance": "喵喵喵")
```)

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

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

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

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

#todo-box[写完]
todo参数解构。

== 总结
Expand Down
46 changes: 25 additions & 21 deletions src/basic/scripting-scope-and-style.typ
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ CeTZ利用内容树制作“内嵌的DSL”。CeTZ的`canvas`函数接收的不
例如它的`line`函数的返回值,就完全不是一个内容,而是一个无法窥视的函数。

#code(```typ
#import "@preview/cetz:0.3.1"
#import "@preview/cetz:0.3.4"
#repr(cetz.draw.line((0, 0), (1, 1), fill: blue))
```)

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

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

=== PNG.typ的树
=== curryst的「树」

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

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

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

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

== 「`show`」语法 <grammar-show>
Expand Down
Loading