Skip to content

Commit 177ab41

Browse files
committed
feat: add fonts
Signed-off-by: Juntong Chen <[email protected]>
1 parent c103828 commit 177ab41

13 files changed

+37
-24
lines changed

Diff for: README.md

+19-14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
![1736643710702](https://jtchen.s3.ap-northeast-1.amazonaws.com/v1/img/2025/01/11/1736643710702.png)
2020

2121
示例文档:
22+
2223
- 本科学位论文 [modern-ecnu-thesis-bachelor.pdf](https://github.com/jtchen2k/modern-ecnu-thesis/releases/latest/download/modern-ecnu-thesis-bachelor.pdf)
2324
- 硕士学位论文,学术学位 [modern-ecnu-thesis-master-academic.pdf](https://github.com/jtchen2k/modern-ecnu-thesis/releases/latest/download/modern-ecnu-thesis-master-academic.pdf)
2425
- 硕士学位论文,专业学位 [modern-ecnu-thesis-master-professional.pdf](https://github.com/jtchen2k/modern-ecnu-thesis/releases/latest/download/modern-ecnu-thesis-master-professional.pdf)
@@ -41,6 +42,8 @@ Typst 是一个基于 Rust 的现代化的排版引擎。它具备类似 Markdow
4142

4243
1. 在 VSCode 中安装 [Tinymist Typst](https://marketplace.visualstudio.com/items?itemName=myriad-dreamin.tinymist) 插件。
4344
2. 按下 `Cmd / Ctrl + Shift + P` 打开命令界面,输入 `Typst: Show available Typst templates (gallery) for picking up a template` 打开 Tinymist 提供的 Template Gallery。在列表中搜索 `modern-ecnu-thesis`,点击 `` 按钮收藏,点击 `+` 来创建论文模板。
45+
46+
![1736800054020](https://jtchen.s3.ap-northeast-1.amazonaws.com/v1/img/2025/01/13/1736800054020.png)
4447
3. 用 VS Code 打开生成的目录,打开 `thesis.typ` 文件,按下 `Ctrl / Cmd + K V` 或者是点击文档顶部的 Preview 来实时预览。
4548

4649
#### 从 git 获取模板
@@ -73,9 +76,12 @@ ln -s </path/to/modern-ecnu-thesis> $DATA_DIR/typst/packages/preview/modern-ecnu
7376

7477
### 在线编辑
7578

76-
在 Typst Web App 中选择 `Start from template`,随后搜索 `modern-ecnu-thesis` 即可开始使用。
79+
[Typst Web App](https://typst.app/app/) 中选择 `Start from template`,随后搜索 `modern-ecnu-thesis` 即可开始使用。
7780

78-
为了在 Web 编辑器中正确显示字体,你需要将[这里](https://github.com/jtchen2k/modern-ecnu-thesis/tree/main/fonts)的字体文件上传到 Typst Web App。
81+
![1736800622590](https://jtchen.s3.ap-northeast-1.amazonaws.com/v1/img/2025/01/13/1736800622590.png)
82+
83+
> [!IMPORTANT]
84+
> 为了在 Web 编辑器中正确显示字体(宋体、黑体、楷体、仿宋、Times、Arial 等),你需要将[该文件夹](https://github.com/jtchen2k/modern-ecnu-thesis/tree/main/fonts)内的字体文件**全部**上传到 Typst Web App。将整个 fonts 文件夹上传到工程任意位置即可。
7985
8086
## Tips
8187

@@ -103,19 +109,18 @@ context state("total-characters").final()
103109

104110
- Typst 支持的图片格式包括 png, jpeg, gif 与 svg,不支持 pdf 与 eps。你可以使用 InkSpace 或 [pdf2svg](https://github.com/dawbarton/pdf2svg) 等工具将 pdf 转换为 svg 格式:
105111

106-
```bash
107-
pdf2svg input.pdf output.svg
108-
```
109-
112+
```bash
113+
pdf2svg input.pdf output.svg
114+
```
110115
- Typst 现在已经支持图片的浮动排版了。你可以使用 `figure``placement` 属性来控制图片位置,可以实现类似 LaTeX 的 `[htbp]` 功能:
111116

112-
```typst
113-
figure {
114-
placement: "top";
115-
caption: "image caption";
116-
...
117-
}[#image("...)] <label>
118-
```
117+
```typst
118+
figure {
119+
placement: "top";
120+
caption: "image caption";
121+
...
122+
}[#image("...)] <label>
123+
```
119124
- Typst 有一套自己的公式语法,与 LaTeX 大同小异且更加简洁。如果你已经十分熟悉 LaTeX 的语法并希望继续使用,可以引入 [MiTeX](https://github.com/mitex-rs/mitex),它将允许你在 Typst 中使用 LaTeX 数学语法。
120125
- Typst 原生兼容了 biblatex 引用格式,直接修改 ref.bib 即可。
121126

@@ -146,4 +151,4 @@ context state("total-characters").final()
146151

147152
## License
148153

149-
This project is licensed under the MIT License.
154+
This project is licensed under the MIT License.

Diff for: fonts/Arial/Arial.otf

-749 KB
Binary file not shown.

Diff for: fonts/Arial/Arial.ttf

359 KB
Binary file not shown.

Diff for: fonts/SinoType/STHeiti.ttf

13 MB
Binary file not shown.

Diff for: fonts/SinoType/STSongti-SC-Bold.ttf

2.82 MB
Binary file not shown.

Diff for: fonts/SinoType/STSongti-SC-Regular.ttf

12.8 MB
Binary file not shown.

Diff for: layouts/doc.typ

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
fallback: false, // 字体缺失时使用 fallback,不显示豆腐块
1010
lang: "zh",
1111
fix-cjk: true,
12+
fix-cjk-debug: false,
1213
margin: (top: 3cm, bottom: 2.5cm, left: 3.18cm, right: 3.18cm),
1314
it,
1415
) = {
@@ -36,7 +37,7 @@
3637

3738

3839
show: if fix-cjk {
39-
fix-cjk-linebreak
40+
fix-cjk-linebreak.with(debug: fix-cjk-debug)
4041
} else {
4142
it
4243
}

Diff for: layouts/mainmatter.typ

+2
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@
229229
show quote: set text(font: fonts.楷体)
230230
show quote: set pad(x: 2em)
231231

232+
set underline(stroke: 0.5pt + black, offset: 0.35em)
233+
232234
// 字数统计(正文 + 附录)
233235
// typst query main.typ '<total-words>' 2>/dev/null --field value --one
234236
context [

Diff for: pages/master-cover.typ

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
info-key("学位申请人"),
240240
info-value-cn("author", info.author),
241241
info-key("指导教师"),
242-
info-value-cn("supervisor", info.supervisor.intersperse(" ").sum()),
242+
info-value-cn("supervisor", info.supervisor.intersperse(h(0.5em)).sum()),
243243
..(
244244
if info.supervisor-ii != () { (info-key-indent(), info-value-cn("supervisor-ii", info.supervisor-ii.intersperse(" ").sum()),) } else { () }
245245
),

Diff for: template/thesis.typ

+5-4
Original file line numberDiff line numberDiff line change
@@ -228,17 +228,18 @@ int main() {
228228

229229
== 中文字符的换行
230230

231-
模板默认启用了 CJK 字符的换行修复。启用该修复后,你可以在源代码中
232-
233-
231+
模板启用了 CJK 字符的换行修复。启用该修复后,你
232+
可以在源
233+
代码中
234+
任意
234235
235236
236237
237238
// 或插入注释。只有两个连续的换行会被视为段落分割。
238239
模板输出时不会把中文源码里的换行转为空格,而只把西文内的换行转换为空格(this
239240
is
240241
an
241-
example)。在启用该修复后,Tinymist 的定位功能可能会失效,你可以将 `#show: doc.with(fix-cjk: true)` 一行修改为 `#show: doc.with(fix-cjk: false)`。来临时禁用该修复
242+
example)。这是一个实验性的功能,在启用该修复后,Tinymist 的定位功能会失效,在少数情况下也可能去除不应去掉的空格。你可以将 `#show: doc.with(fix-cjk: true)` 一行修改为 `#show: doc.with(fix-cjk: false)` 来禁用该修复
242243

243244
== 字数统计
244245

Diff for: utils/fix-cjk-linebreak.typ

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44
* @project: modern-ecnu-thesis
55
* @author: Juntong Chen ([email protected])
66
* @created: 2025-01-12 15:12:15
7-
* @modified: 2025-01-12 15:54:13
7+
* @modified: 2025-01-12 22:12:32
88
*
99
* Copyright (c) 2025 Juntong Chen. All rights reserved.
1010
*/
1111

1212
// 截止 Typst 0.12.0 版本,CJK 字符的换行处理还不够完善,可能会插入不必要的空格。这里提供一个 workaround。
1313
// 详见:https://github.com/typst/typst/issues/792#issuecomment-2310139085
14-
#let fix-cjk-linebreak(body) = [
14+
#let fix-cjk-linebreak(body, debug: false) = [
1515
// 不去除章后的字符
1616
#let cjk-char = "[\p{Han},。;:!?‘’“”()「」【】…—&&[^章节]]"
1717
// 没有使用 \s 来匹配空白字符的原因是为了保留全角空格。
18-
#let cjk-re = regex("[ \\t\\n\\r]*(" + cjk-char + ")[ \\t\\n\\r]*")
18+
#let cjk-re = regex("(" + cjk-char + ")([ \\t\\r]+(" + cjk-char + ")+)+")
1919
#show cjk-re: it => {
20-
it.text.match(cjk-re).captures.at(0)
20+
if debug {
21+
highlight(fill: color.red, it.text)
22+
} else {
23+
it.text.replace(regex("[ \\t\\r]+"), "")
24+
}
2125
}
2226
#show: rest => {
2327
let ends-with-cjk = it => {

0 commit comments

Comments
 (0)