Skip to content

Commit 578f0ac

Browse files
committed
fix: fix first line indent for multiple elements
Signed-off-by: Juntong Chen <[email protected]>
1 parent 177ab41 commit 578f0ac

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

layouts/mainmatter.typ

+25-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
justify: true,
1919
first-line-indent: 2em,
2020
// 浮动于页顶或页底的上下间距
21-
figure-clearance: 32pt,
21+
figure-clearance: 24pt,
2222
figure-caption-spacing: 0.4em,
2323
numbering: custom-numbering.with(first-level: "第一章 ", depth: 4, "1.1 "),
2424
// 正文字体与字号参数
@@ -27,8 +27,8 @@
2727
heading-font: auto,
2828
heading-size: (字号.三号, 字号.四号,),
2929
heading-weight: ("regular",),
30-
heading-above: (2 * 15.6pt - 0.7em, 2 * 15.6pt - 0.7em),
31-
heading-below: (2 * 15.6pt, 2 * 15.6pt - 0.7em),
30+
heading-above: (1.0em, 2.0em, 1.5em),
31+
heading-below: (1.5em, 1.5em, 1.25em),
3232
heading-pagebreak: (true, false),
3333
heading-align: (center, auto),
3434
// 页眉
@@ -110,29 +110,26 @@
110110
show figure: show-figure
111111
// 3.4 设置 equation 的编号和假段落首行缩进
112112
show math.equation.where(block: true): show-equation
113-
show math.equation.where(block: true): it => {
114-
it
115-
fake-par
116-
}
117113
// 3.5 表格表头置顶 + 不用冒号用空格分割 + 样式
118114
show figure.where(
119115
kind: table
120116
): set figure.caption(position: top)
121117
set figure.caption(separator: separator)
122118
show figure.caption: caption-style
123119
show figure.caption: set text(size: caption-size, font: fonts.楷体)
124-
show figure.caption: set par(leading: 1.25em)
120+
show figure.caption: set par(leading: 1em)
125121

126122
show figure.caption: c => block(inset: (top: figure-caption-spacing, bottom: figure-caption-spacing))[
127-
#text(font: fonts.黑体, weight: "bold", style: "normal")[
123+
#set align(left)
124+
#text(font: fonts.黑体, weight: "regular", style: "normal")[
128125
#c.supplement #context c.counter.display(c.numbering)
129126
]
130127
#h(0.3em)#c.body
131128
]
132129
show figure.where(placement: none): it => {
133130
v(figure-clearance / 6)
134131
it
135-
fake-par
132+
v(figure-clearance / 6)
136133
}
137134
set place(clearance: figure-clearance)
138135
// 3.6 优化列表显示
@@ -170,7 +167,6 @@
170167
below: array-at(heading-below, it.level),
171168
)
172169
it
173-
fake-par
174170
}
175171
// 4.3 标题居中与自动换页
176172
show heading: it => context {
@@ -231,6 +227,24 @@
231227

232228
set underline(stroke: 0.5pt + black, offset: 0.35em)
233229

230+
// 处理一些元素后第一段文本的首行缩进
231+
show selector.or(heading, figure, list, enum, quote, terms): it => {
232+
it
233+
fake-par
234+
}
235+
236+
// 处理一级标题的引用格式
237+
show ref: it => {
238+
let el = it.element
239+
if (el != none and el.func() == heading and el.level == 1) {
240+
link(el.location(), text(fill: color.black,
241+
numbering(..counter(heading).at(el.location())).trim()
242+
))
243+
} else {
244+
it
245+
}
246+
}
247+
234248
// 字数统计(正文 + 附录)
235249
// typst query main.typ '<total-words>' 2>/dev/null --field value --one
236250
context [

typst.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
entrypoint = "lib.typ"
55
authors = ["Juntong Chen <@jtchen2k>"]
66
license = "MIT"
7-
description = "华东师范大学学位论文模板。Modern East China Normal University Thesis Template."
7+
description = "华东师范大学本科 / 研究生学位论文模板。Modern East China Normal University Thesis Template."
88
repository = "https://github.com/jtchen2k/modern-ecnu-thesis"
99
keywords = ["East China Normal University", "thesis"]
1010
categories = ["thesis"]

utils/fix-cjk-linebreak.typ

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @project: modern-ecnu-thesis
55
* @author: Juntong Chen ([email protected])
66
* @created: 2025-01-12 15:12:15
7-
* @modified: 2025-01-12 22:12:32
7+
* @modified: 2025-01-14 20:27:32
88
*
99
* Copyright (c) 2025 Juntong Chen. All rights reserved.
1010
*/
@@ -13,7 +13,7 @@
1313
// 详见:https://github.com/typst/typst/issues/792#issuecomment-2310139085
1414
#let fix-cjk-linebreak(body, debug: false) = [
1515
// 不去除章后的字符
16-
#let cjk-char = "[\p{Han},。;:!?‘’“”()「」【】…—&&[^章节]]"
16+
#let cjk-char = "[\p{Han},。;:!?‘’“”()「」『』【】…—&&[^章节]]"
1717
// 没有使用 \s 来匹配空白字符的原因是为了保留全角空格。
1818
#let cjk-re = regex("(" + cjk-char + ")([ \\t\\r]+(" + cjk-char + ")+)+")
1919
#show cjk-re: it => {

0 commit comments

Comments
 (0)