Skip to content

Commit 3650cba

Browse files
committed
feat: compatible with typst 0.13.0
Signed-off-by: Juntong Chen <[email protected]>
1 parent 2dccfa5 commit 3650cba

11 files changed

+72
-79
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,13 @@ Typst 是一个基于 Rust 的现代化的排版引擎。它具备类似 Markdow
3636

3737
### 在 VSCode 中本地编辑(推荐)
3838

39-
请确保本地安装的 typst 版本 >= 0.12.0。
39+
请确保本地已安装 Typst。推荐使用最新版本,这里是 Typst 与模板版本的对应关系:
40+
41+
| typst 版本 | 模板版本 |
42+
| ---------- | -------- |
43+
| <0.12.0 | 不支持 |
44+
| 0.12.0 | 0.1.0 |
45+
| 0.13.0 | 0.2.0 |
4046

4147
#### 从 Typst Universe 获取模板
4248

layouts/mainmatter.typ

+8-7
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,14 @@
9898
leading: leading,
9999
justify: justify,
100100
linebreaks: "optimized",
101-
first-line-indent: first-line-indent
101+
first-line-indent: (amount: first-line-indent, all: true),
102102
)
103103
// show par: set block(spacing: spacing)
104104
show raw: set text(font: fonts.等宽, size: text-args.size)
105105
show raw.where(block: true): set par(leading: 1em)
106106
// 3.2 脚注样式
107107
show footnote.entry: set text(font: fonts.宋体, size: 字号.五号)
108+
show footnote.entry: set par(leading: 1em)
108109
// 3.3 设置 figure 的编号
109110
show heading: i-figured.reset-counters
110111
show figure: show-figure
@@ -167,7 +168,7 @@
167168
above: array-at(heading-above, it.level),
168169
below: array-at(heading-below, it.level),
169170
)
170-
it + fake-par + v(-0.15em)
171+
it // fake-par + v(-0.15em) // no longer needed since 0.13.0
171172
}
172173
// 4.3 标题居中与自动换页
173174
show heading: it => context {
@@ -239,7 +240,7 @@
239240

240241
// 列表样式
241242
set enum(indent: 0.9em, body-indent: 0.35em)
242-
set list(indent: 2em, body-indent: 0.55em)
243+
set list(indent: 1.2em, body-indent: 0.6em)
243244

244245
// 引述文本样式
245246
set quote(block: true)
@@ -248,10 +249,10 @@
248249

249250
set underline(stroke: 0.5pt + black, offset: 0.35em)
250251

251-
// 处理其他元素后第一段文本的首行缩进
252-
show selector.or(figure, list, enum, quote, terms): it => {
253-
it + fake-par
254-
}
252+
// 处理其他元素后第一段文本的首行缩进 (0.13.0 后不再需要)
253+
// show selector.or(figure, list, enum, quote, terms): it => {
254+
// it + fake-par
255+
// }
255256

256257
// 处理一级标题的引用格式
257258
show ref: it => {

lib.typ

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @project: modern-ecnu-thesis
55
* @author: OrangeX4, Juntong Chen ([email protected])
66
* @created: 2025-01-06 22:37:34
7-
* @modified: 2025-01-23 04:45:57
7+
* @modified: 2025-02-09 22:02:03
88
*
99
* 华东师范大学学位论文模板
1010
* Repo: https://github.com/jtchen2k/modern-ecnu-thesis
@@ -267,7 +267,7 @@
267267
bachelor-outline-page(
268268
twoside: twoside,
269269
title-text-args: (font: 字体.黑体, size: 字号.三号, weight: "bold"),
270-
vspace: (1.35em, 1.2em),
270+
vspace: (1.2em,),
271271
weight: ("regular", "regular"),
272272
indent: (0em, 2.38em, 2em, 2.8em),
273273
doctype: doctype,

pages/bachelor-outline-page.typ

+26-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#import "@preview/outrageous:0.3.0"
21
#import "../utils/invisible-heading.typ": invisible-heading
32
#import "../utils/style.typ": 字号, 字体
43
#import "../utils/custom-heading.typ": heading-content
@@ -59,39 +58,39 @@
5958

6059
{
6160
set align(center)
62-
text(..title-text-args, title)
6361
// 标记一个不可见的标题用于目录生成
6462
invisible-heading(level: 1, outlined: outlined, title)
63+
text(..title-text-args, title)
64+
6565
}
6666

6767
v(title-vspace)
6868

69-
show outline.entry: outrageous.show-entry.with(
70-
// 保留 Typst 基础样式
71-
..outrageous.presets.typst,
72-
body-transform: (level, it) => {
73-
// 设置字体和字号
74-
set text(
75-
font: font.at(calc.min(level, font.len()) - 1),
76-
size: size.at(calc.min(level, size.len()) - 1),
77-
)
78-
// 计算缩进
79-
let indent-list = indent + range(level - indent.len()).map((it) => indent.last())
80-
let indent-length = indent-list.slice(0, count: level).sum()
81-
if "children" in it.fields() and it.children.len() > 2 {
82-
set text(weight: weight.at(calc.min(level, weight.len()) - 1))
83-
let (number, space, ..text) = it.children
84-
[#h(indent-length) #box[#number] #h(if level > 1 {3pt} else {2pt}) #text.join()]
85-
} else {
86-
set text(weight: weight.at(calc.min(level, weight.len()) - 1))
87-
h(indent-length) + it
88-
}
89-
},
90-
vspace: vspace,
91-
fill: fill,
92-
..args,
69+
let array-at(arr, pos) = {
70+
arr.at(calc.min(pos, arr.len()) - 1)
71+
}
72+
73+
show outline.entry.where(level: 1): it => link(
74+
it.element.location(),
75+
it.indented(
76+
if it.prefix() != none and repr(it.prefix()).len() > 2 {
77+
text(font: fonts.黑体, size: array-at(size, 0), it.prefix())
78+
} else { none },
79+
{
80+
text(font: fonts.黑体, size: array-at(size, 0), it.body())
81+
[ ]
82+
box(width: 1fr, it.fill)
83+
[ ]
84+
it.page()
85+
})
9386
)
9487

88+
show outline.entry: it => {
89+
set block(spacing: array-at(vspace, it.level - 1))
90+
// if it.prefix() != none {it.prefix()} else { block(it) }
91+
it
92+
}
93+
9594
// 显示目录
96-
outline(title: none, depth: depth)
95+
outline(title: none, depth: depth, indent: auto)
9796
}

pages/list-of-figures.typ

+6-18
Original file line numberDiff line numberDiff line change
@@ -51,32 +51,20 @@
5151
set text(font: font, size: size)
5252

5353
{
54-
set align(center)
55-
text(..title-text-args, title)
5654
// 标记一个不可见的标题用于目录生成
5755
invisible-heading(level: 1, outlined: outlined, title)
56+
set align(center)
57+
text(..title-text-args, title)
5858
}
5959

6060
v(title-vspace)
6161

62-
show outline.entry: outrageous.show-entry.with(
63-
// 保留 Typst 基础样式
64-
..outrageous.presets.typst,
65-
body-transform: (level, it) => {
66-
// 因为好像没找到 separator 的参数,所以这里就手动寻找替换了
67-
if (it.has("children") and it.children.at(3, default: none) == [#": "]) {
68-
it.children.slice(0, 3).sum() + separator + it.children.slice(4).sum()
69-
} else {
70-
it
71-
}
72-
},
73-
vspace: (vspace,),
74-
fill: (fill,),
75-
)
62+
show outline.entry: it => {
63+
set block(spacing: vspace)
64+
it
65+
}
7666

7767
// 显示目录
7868
i-figured.outline(target-kind: image, title: none)
7969

80-
81-
8270
}

pages/list-of-tables.typ

+6-16
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,18 @@
5151
set text(font: font, size: size)
5252

5353
{
54-
set align(center)
55-
text(..title-text-args, title)
5654
// 标记一个不可见的标题用于目录生成
5755
invisible-heading(level: 1, outlined: outlined, title)
56+
set align(center)
57+
text(..title-text-args, title)
5858
}
5959

6060
v(title-vspace)
6161

62-
show outline.entry: outrageous.show-entry.with(
63-
// 保留 Typst 基础样式
64-
..outrageous.presets.typst,
65-
body-transform: (level, it) => {
66-
// 因为好像没找到 separator 的参数,所以这里就手动寻找替换了
67-
if (it.has("children") and it.children.at(3, default: none) == [#": "]) {
68-
it.children.slice(0, 3).sum() + separator + it.children.slice(4).sum()
69-
} else {
70-
it
71-
}
72-
},
73-
vspace: (vspace,),
74-
fill: (fill,),
75-
)
62+
show outline.entry: it => {
63+
set block(spacing: vspace)
64+
it
65+
}
7666

7767
// 显示目录
7868
i-figured.outline(target-kind: table, title: none)

pages/master-abstract-en.typ

+4-2
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@
6363
// #show par: set block(spacing: spacing)
6464
#set block(spacing: spacing)
6565

66+
// 标记一个不可见的标题用于目录生成
67+
#invisible-heading(level: 1, outlined: outlined, outline-title)
68+
6669
#set align(center)
6770
#block[
6871
#set text(font: fonts.黑体, size: 字号.小三, weight: "bold")
6972
Abstract
7073
]
7174

72-
// 标记一个不可见的标题用于目录生成
73-
#invisible-heading(level: 1, outlined: outlined, outline-title)
75+
7476

7577
#set align(left)
7678

pages/master-abstract.typ

+5-3
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,23 @@
6060
)
6161

6262
[
63+
6364
#set text(font: fonts.楷体, size: 字号.四号)
6465
#set par(leading: leading, justify: true)
6566

6667
// #show par: set block(spacing: spacing)
6768
#set block(spacing: spacing)
6869

70+
71+
// 标记一个不可见的标题用于目录生成
72+
#invisible-heading(level: 1, outlined: outlined, outline-title)
73+
6974
#set align(center)
7075
#block[
7176
#set text(font: fonts.黑体, size: 字号.小三, weight: "bold")
7277
#h(2em)要
7378
]
7479

75-
// 标记一个不可见的标题用于目录生成
76-
#invisible-heading(level: 1, outlined: outlined, outline-title)
77-
7880
#set align(left)
7981

8082
#set text(font: fonts.宋体, size: 字号.小四)

pages/notation.typ

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
set text(font: font, size: size)
4343

4444
{
45-
set align(center)
46-
text(..title-text-args, title)
4745
// 标记一个不可见的标题用于目录生成
4846
invisible-heading(level: 1, outlined: outlined, title)
47+
set align(center)
48+
text(..title-text-args, title)
4949
}
5050

5151
v(title-vspace)

typst.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "modern-ecnu-thesis"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
entrypoint = "lib.typ"
55
authors = ["Juntong Chen <@jtchen2k>"]
66
license = "MIT"

utils/bilingual-bibliography.typ

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Authors: csimide, OrangeX4
22
// Tested only on GB-7714-2015-Numeric
3+
#import "./style.typ": 字号
4+
35
#let bilingual-bibliography(
46
bibliography: none,
57
title: "参考文献",
@@ -9,6 +11,7 @@
911
extra-comma-before-et-al-trans: false,
1012
// 用于控制多位译者时表现为 `et al. tran`(false) 还是 `et al., tran`(true)
1113
allow-comma-in-name: false,
14+
font-size: 字号.小四,
1215
// 如果使用的 CSL 中,英文姓名中会出现逗号,请设置为 true
1316
) = {
1417
assert(bibliography != none, message: "请传入带有 source 的 bibliography 函数。")
@@ -139,6 +142,8 @@
139142

140143
context state("in-mainmatter").update(false)
141144

145+
set text(size: font-size)
146+
142147
bibliography(
143148
title: title,
144149
full: full,

0 commit comments

Comments
 (0)