Skip to content

Commit

Permalink
feat: add fonts
Browse files Browse the repository at this point in the history
Signed-off-by: Juntong Chen <[email protected]>
  • Loading branch information
jtchen2k committed Jan 13, 2025
1 parent c103828 commit 177ab41
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 24 deletions.
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
![1736643710702](https://jtchen.s3.ap-northeast-1.amazonaws.com/v1/img/2025/01/11/1736643710702.png)

示例文档:

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

1. 在 VSCode 中安装 [Tinymist Typst](https://marketplace.visualstudio.com/items?itemName=myriad-dreamin.tinymist) 插件。
2. 按下 `Cmd / Ctrl + Shift + P` 打开命令界面,输入 `Typst: Show available Typst templates (gallery) for picking up a template` 打开 Tinymist 提供的 Template Gallery。在列表中搜索 `modern-ecnu-thesis`,点击 `` 按钮收藏,点击 `+` 来创建论文模板。

![1736800054020](https://jtchen.s3.ap-northeast-1.amazonaws.com/v1/img/2025/01/13/1736800054020.png)
3. 用 VS Code 打开生成的目录,打开 `thesis.typ` 文件,按下 `Ctrl / Cmd + K V` 或者是点击文档顶部的 Preview 来实时预览。

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

### 在线编辑

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

为了在 Web 编辑器中正确显示字体,你需要将[这里](https://github.com/jtchen2k/modern-ecnu-thesis/tree/main/fonts)的字体文件上传到 Typst Web App。
![1736800622590](https://jtchen.s3.ap-northeast-1.amazonaws.com/v1/img/2025/01/13/1736800622590.png)

> [!IMPORTANT]
> 为了在 Web 编辑器中正确显示字体(宋体、黑体、楷体、仿宋、Times、Arial 等),你需要将[该文件夹](https://github.com/jtchen2k/modern-ecnu-thesis/tree/main/fonts)内的字体文件**全部**上传到 Typst Web App。将整个 fonts 文件夹上传到工程任意位置即可。
## Tips

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

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

```bash
pdf2svg input.pdf output.svg
```

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

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

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

## License

This project is licensed under the MIT License.
This project is licensed under the MIT License.
Binary file removed fonts/Arial/Arial.otf
Binary file not shown.
Binary file added fonts/Arial/Arial.ttf
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file added fonts/SinoType/STHeiti.ttf
Binary file not shown.
Binary file added fonts/SinoType/STSongti-SC-Bold.ttf
Binary file not shown.
Binary file added fonts/SinoType/STSongti-SC-Regular.ttf
Binary file not shown.
3 changes: 2 additions & 1 deletion layouts/doc.typ
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
fallback: false, // 字体缺失时使用 fallback,不显示豆腐块
lang: "zh",
fix-cjk: true,
fix-cjk-debug: false,
margin: (top: 3cm, bottom: 2.5cm, left: 3.18cm, right: 3.18cm),
it,
) = {
Expand Down Expand Up @@ -36,7 +37,7 @@


show: if fix-cjk {
fix-cjk-linebreak
fix-cjk-linebreak.with(debug: fix-cjk-debug)
} else {
it
}
Expand Down
2 changes: 2 additions & 0 deletions layouts/mainmatter.typ
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@
show quote: set text(font: fonts.楷体)
show quote: set pad(x: 2em)

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

// 字数统计(正文 + 附录)
// typst query main.typ '<total-words>' 2>/dev/null --field value --one
context [
Expand Down
2 changes: 1 addition & 1 deletion pages/master-cover.typ
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
info-key("学位申请人"),
info-value-cn("author", info.author),
info-key("指导教师"),
info-value-cn("supervisor", info.supervisor.intersperse(" ").sum()),
info-value-cn("supervisor", info.supervisor.intersperse(h(0.5em)).sum()),
..(
if info.supervisor-ii != () { (info-key-indent(), info-value-cn("supervisor-ii", info.supervisor-ii.intersperse(" ").sum()),) } else { () }
),
Expand Down
9 changes: 5 additions & 4 deletions template/thesis.typ
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,18 @@ int main() {

== 中文字符的换行

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

== 字数统计

Expand Down
12 changes: 8 additions & 4 deletions utils/fix-cjk-linebreak.typ
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
* @project: modern-ecnu-thesis
* @author: Juntong Chen ([email protected])
* @created: 2025-01-12 15:12:15
* @modified: 2025-01-12 15:54:13
* @modified: 2025-01-12 22:12:32
*
* Copyright (c) 2025 Juntong Chen. All rights reserved.
*/

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

0 comments on commit 177ab41

Please sign in to comment.