Skip to content

Commit

Permalink
feat: remove anti-matter dependency, fix cjk line breaks
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 fc4a33f commit c103828
Show file tree
Hide file tree
Showing 18 changed files with 159 additions and 78 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- 优化段落缩进
- 优化对多行标题 / 院系的处理逻辑
- 优化开启 `twoside` 参数后的页码逻辑
- 修复中文文字断行的问题
- 增加字数统计功能

对于研究生,我们参考华东师范大研究生院于 2023 年发布的[华东师范大学博士、硕士学位论文基本格式要求](https://yjsy.ecnu.edu.cn/8e/62/c42090a429666/page.htm);对于本科生,我们参考华东师范大学教务处于 2021 年更新的[华东师范大学本科生毕业论文(设计)格式要求](http://www.jwc.ecnu.edu.cn/d4/be/c40573a513214/page.htm)。格式适配于 2025 年初,后续使用的同学请留意参考校方的最新通知。
Expand All @@ -28,13 +29,13 @@

> 天下苦 LaTeX 久矣。
Typst 是一个基于 Rust 的现代化的排版引擎。它具备类似 Markdown 的简洁语法、清晰的错误提示、实时预览级的编译性能,又同时具备和 LaTeX 一样精准的排版控制和图灵完备的脚本能力。自 2023 年 4 月开源发布以来,已获得 ![](https://img.shields.io/github/stars/typst/typst?style=flat)。现代化的 Typst 可以让你更加专注于论文内容本身,而不被 LaTeX 漫长的编译时间与难以阅读的输出日志困扰。
Typst 是一个基于 Rust 的现代化的排版引擎。它具备类似 Markdown 的简洁语法、清晰的错误提示、实时预览级的编译性能,又同时具备和 LaTeX 一样精准的排版控制和图灵完备的脚本能力。自 2023 年 4 月开源发布以来,已获得 ![](https://img.shields.io/github/stars/typst/typst?style=flat)。现代化的 Typst 可以让你更加专注于论文内容本身,而不被 LaTeX 漫长的编译时间与难以阅读的输出日志困扰。当然,Typst 作为一个年轻的工具还在快速发展,生态远没有 LaTeX 丰富,也有大量的 issue 正在解决的路上。欢迎加入这个社区来共建现代排版生态。

## Usage

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

首先请确保安装的 typst 版本 >= 0.12.0
请确保本地安装的 typst 版本 >= 0.12.0

#### 从 Typst Universe 获取模板

Expand Down Expand Up @@ -128,6 +129,7 @@ context state("total-characters").final()
- **本科**
- [ ] 中英双语图片标题
- [ ] 本科学位论文的诚信承诺页
- **研究生**
- 暂无
Expand All @@ -136,6 +138,8 @@ context state("total-characters").final()
- [modern-nju-thesis](https://github.com/nju-lug/modern-nju-thesis) by [OrangeX4](https://github.com/Orangex4)
- [ECNU-Undergraduate-LaTeX](https://github.com/YijunYuan/ECNU-Undergraduate-LaTeX) by [YijunYuan](https://github.com/YijunYuan)
- [华东师范大学硕士论文模板-2023](https://www.overleaf.com/latex/templates/hua-dong-shi-fan-da-xue-shuo-shi-lun-wen-mo-ban-2023/ctvnwyqtsbbz) by ivyee17
- [ECNU_graduation_thesis_template](https://github.com/ECNU-ICA/ECNU_graduation_thesis_template) by [ECNU-ICA](https://github.com/ECNU-ICA)
- [ECNU-Dissertations-Latex-Template](https://github.com/DeepTrial/ECNU-Dissertations-Latex-Template) by [Karl Xing](https://github.com/DeepTrial)
- [关于2023-2024学年第二学期学术型学位硕士研究生论文答辩及学位申请工作的通知](https://yjsy.ecnu.edu.cn/c1/7a/c42079a573818/page.htm) by 华东师范大学研究生院
- [毕业论文常用下载材料](http://www.jwc.ecnu.edu.cn/d4/be/c40573a513214/page.htm) by 华东师范大学教务处
- [学校标识](https://www.ecnu.edu.cn/wzcd/xxgk/xxbs.htm) by 华东师范大学
Expand Down
10 changes: 10 additions & 0 deletions layouts/doc.typ
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#import "../utils/str.typ": to-normal-str
#import "../utils/fix-cjk-linebreak.typ": fix-cjk-linebreak

// 文稿设置,可以进行一些像页面边距这类的全局设置
#let doc(
// documentclass 传入参数
info: (:),
// 其他参数
fallback: false, // 字体缺失时使用 fallback,不显示豆腐块
lang: "zh",
fix-cjk: true,
margin: (top: 3cm, bottom: 2.5cm, left: 3.18cm, right: 3.18cm),
it,
) = {
Expand All @@ -31,5 +34,12 @@
author: info.author,
)


show: if fix-cjk {
fix-cjk-linebreak
} else {
it
}

it
}
52 changes: 28 additions & 24 deletions layouts/mainmatter.typ
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#import "@preview/anti-matter:0.1.1": fence, step, core
#import "@preview/i-figured:0.2.4"
#import "../utils/style.typ": 字号, 字体
#import "../utils/custom-numbering.typ": custom-numbering
Expand Down Expand Up @@ -53,28 +52,23 @@
it,
) = {

// 0. 标志前言结束
{
// TODO: 用了一个很 tricky 的方式防止前言最后一页的页码打印出来,可能有更优解
set page(footer: { text(size: 0pt, ".") })
v(-1pt)
fence()
}
pagebreak-from-odd(twoside: twoside)
// // 0. 标志前言结束
counter(page).update(1)
set page(numbering: "1")

set page(footer: context {
set text(size: 字号.五号)
let p = core.inner-counter().get().at(0)
let p = counter(page).get().at(0)
let pagealign = center
if doctype == "bachelor" {
align(center)[
#core.inner-counter().display()
]
pagealign = center
} else if calc.rem(p, 2) == 1 {
h(1fr)
text(core.inner-counter().display())
pagealign = right
} else {
text(core.inner-counter().display())
h(1fr)
pagealign = left
}
align(pagealign, counter(page).display())
})


Expand Down Expand Up @@ -103,6 +97,7 @@
set par(
leading: leading,
justify: justify,
linebreaks: "optimized",
first-line-indent: first-line-indent
)
// show par: set block(spacing: spacing)
Expand All @@ -127,11 +122,12 @@
show figure.caption: caption-style
show figure.caption: set text(size: caption-size, font: fonts.楷体)
show figure.caption: set par(leading: 1.25em)

show figure.caption: c => block(inset: (top: figure-caption-spacing, bottom: figure-caption-spacing))[
#text(font: fonts.黑体, weight: "bold", style: "normal")[
#c.supplement #context c.counter.display(c.numbering)
]
#c.separator#c.body
#h(0.3em)#c.body
]
show figure.where(placement: none): it => {
v(figure-clearance / 6)
Expand Down Expand Up @@ -201,11 +197,10 @@
set page(..(if display-header {
(
header: {
// needed by anti-matter
if header-render == auto {
heading-content(doctype: doctype, fonts: fonts)
} else {
header-render(loc)
header-render()
}
v(header-vspace)

Expand All @@ -222,19 +217,28 @@
)
}))

// 字数统计(正文 + 附录)
// typst query main.typ '<total-words>' 2>/dev/null --field value --one
// 斜体文字使用楷体
show emph: set text(font: fonts.楷体)

// 列表样式
set enum(indent: 0.9em, body-indent: 0.35em)
set list(indent: 1em, body-indent: 0.55em)

// 引述文本样式
set quote(block: true)
show quote: set text(font: fonts.楷体)
show quote: set pad(x: 2em)

// 字数统计(正文 + 附录)
// typst query main.typ '<total-words>' 2>/dev/null --field value --one
context [
#metadata(state("total-words-cjk").final()) <total-words>
#metadata(state("total-characters").final()) <total-chars>
]

// 用于本科毕业论文控制标题样式
let s = state("in-mainmatter", true)
context s.update(true)

it
// 正文结束标志,不可缺少
// 这里放在附录后面,使得页码能正确计数
fence()
}
30 changes: 15 additions & 15 deletions layouts/preface.typ
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
#import "@preview/anti-matter:0.1.1": anti-matter, core
#import "../utils/style.typ": 字号

// 前言,重置页面计数器
#let preface(
doctype: "master",
// documentclass 传入的参数
twoside: false,
// 其他参数
numbering: ("I", "1", "I"),
..args,
it,
) = {
counter(page).update(0)
set page(footer: context {
set text(size: 字号.五号)
let p = core.outer-counter().get().at(0)
let p = counter(page).get().at(0)
let pagealign = center
if doctype == "bachelor" {
align(center)[
#core.outer-counter().display("I")
]
pagealign = center
} else if twoside == true {
align(right)[
#core.outer-counter().display("I")
]
let preal = here().position().page
if calc.rem(preal, 2) == 1 {
pagealign = right
} else {
pagealign = left
}
} else {
if calc.rem(p, 2) == 1 {
h(1fr)
core.outer-counter().display("I")
pagealign = right
} else {
core.outer-counter().display("I")
h(1fr)
pagealign = left
}
}
align(pagealign, counter(page).display("I"))
})
anti-matter(numbering: numbering, ..args, it)
set par(linebreaks: "optimized")
it
}
5 changes: 2 additions & 3 deletions lib.typ
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @project: modern-ecnu-thesis
* @author: OrangeX4, Juntong Chen ([email protected])
* @created: 2025-01-06 22:37:34
* @modified: 2025-01-11 16:46:35
* @modified: 2025-01-12 14:38:55
*
* 华东师范大学学位论文模板
* Repo: https://github.com/jtchen2k/modern-ecnu-thesis
Expand All @@ -13,7 +13,6 @@
* Copyright (c) 2025 Juntong Chen. All rights reserved.
*/

#import "@preview/anti-matter:0.1.1": fence as mainmatter-end
#import "layouts/doc.typ": doc
#import "layouts/preface.typ": preface
#import "layouts/mainmatter.typ": mainmatter
Expand Down Expand Up @@ -123,7 +122,7 @@
heading-below: (1.8em, 1.5em),
..args, fonts: fonts + args.named().at("fonts", default: (:)))
} else {
mainmatter(doctype: doctype, twoside: twoside, display-header: true, ..args, fonts: fonts + args.named().at("fonts", default: (:)))
mainmatter(doctype: doctype, twoside: twoside, display-header: true, ..args, fonts: fonts + args.named().at("fonts", default: (:)))
}
},
mainmatter-end: (..args) => {
Expand Down
4 changes: 2 additions & 2 deletions pages/bachelor-abstract-en.typ
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
}

set page(header: {
heading-content(doctype: "bachelor", fonts: fonts)
heading-content(doctype: "bachelor", twoside: twoside, fonts: fonts)
})

// 4. 正式渲染
Expand All @@ -61,7 +61,7 @@
#invisible-heading(level: 1, outlined: outlined, outline-title)

#align(center)[
#set text(font: fonts.黑体, size: 字号.小三)
#set text(font: fonts.黑体, size: 字号.小三, weight: "bold")
Abstract
]

Expand Down
2 changes: 1 addition & 1 deletion pages/bachelor-abstract.typ
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

set page(
header: {
heading-content(doctype: "bachelor", fonts: fonts)
heading-content(doctype: "bachelor", twoside: twoside, fonts: fonts)
}
)

Expand Down
2 changes: 1 addition & 1 deletion pages/bachelor-outline-page.typ
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

set page(..(if show-heading {
(header: {
heading-content(doctype: doctype, fonts: fonts)
heading-content(doctype: doctype, twoside: twoside, fonts: fonts)
})
} else { () }))

Expand Down
2 changes: 1 addition & 1 deletion pages/list-of-figures.typ
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

set page(..(if show-heading {(
header: {
heading-content(doctype: doctype, fonts: fonts)
heading-content(doctype: doctype, twoside: twoside, fonts: fonts)
}
)} else {()}))

Expand Down
2 changes: 1 addition & 1 deletion pages/list-of-tables.typ
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

set page(..(if show-heading {(
header: {
heading-content(doctype: doctype, fonts: fonts)
heading-content(doctype: doctype, twoside: twoside, fonts: fonts)
}
)} else {()}))

Expand Down
2 changes: 1 addition & 1 deletion pages/master-abstract-en.typ
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

set page(
header: {
heading-content(doctype: doctype, fonts: fonts)
heading-content(doctype: doctype, twoside: twoside, fonts: fonts)
}
)

Expand Down
2 changes: 1 addition & 1 deletion pages/master-abstract.typ
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

set page(
header: {
heading-content(doctype: doctype, fonts: fonts)
heading-content(doctype: doctype, twoside: twoside, fonts: fonts)
}
)

Expand Down
2 changes: 1 addition & 1 deletion pages/notation.typ
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

set page(..(if show-heading {(
header: {
heading-content(doctype: doctype, fonts: fonts)
heading-content(doctype: doctype, twoside: twoside, fonts: fonts)
}
)} else {()}))

Expand Down
Loading

0 comments on commit c103828

Please sign in to comment.