Skip to content

Commit e6be223

Browse files
EuanTopEuan
andauthored
modern-bnu-course-paper:0.1.0 (typst#1532)
Co-authored-by: Euan <autumndyer@126.com>
1 parent af023b1 commit e6be223

37 files changed

+2130
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Euan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!--
2+
* @Author: Euan euan@mail.bnu.edu.cn
3+
* @Date: 2024-11-15 11:36:36
4+
* @LastEditors: Euan euan@mail.bnu.edu.cn
5+
*
6+
* Copyright (c) 2025 by Euan, All Rights Reserved.
7+
-->
8+
# 北京师范大学大学课程论文 modern-bnu-course-paper
9+
> [!NOTE]
10+
> 可以前往[Typst Universe](https://typst.app/universe/package/modern-bnu-course-paper)快捷使用模版书写论文
11+
12+
北京师范大学大学课程论文的 Typst 模板,能够简洁、快速、持续生成 PDF 格式的课程论文。
13+
14+
不仅适用于BNU的课程论文,也适合其他学校课程课程论文(格式要求规范但未给出模板的)。
15+
16+
17+
🙋 什么是Typst?
18+
Typst格式类似于Markdown可以快速掌握,比起Word省略了非常多格式调整工作,比Latex更简单易用。
19+
20+
## 使用方法
21+
1. [推荐🧑‍🎓] Typst可以使用[线上WebApp](https://typst.app/universe/search/?kind=templates)
22+
> 如果是 Web App 上编辑,你应该手动上传这些字体文件(见 [nju模版](https://github.com/nju-lug/modern-nju-thesis/tree/main/fonts/FangZheng) 里的所有字体),否则不能正常使用「楷体」和「仿宋」,导致显示错误。
23+
2. [推荐一定代码基础的👩‍💻]本地下载[相关资源]()后进行编写。
24+
- Typst Universe:从Typst Universe中使用这个模板非常简单和容易。如果您更喜欢使用本地编辑器和typst-cli,您可以使用以下命令使用此模板创建新的求职信项目。
25+
26+
```typst init @preview/modern-bnu-course-paper```
27+
- download from GitHub:您可以克隆此存储库并将其作为普通项目使用
28+
29+
```git clone https://github.com/EuanTop/modern-bnu-course-paper```
30+
31+
32+
33+
34+
> [!tip]
35+
> 本模板是基于[北京师范大学毕业论文(设计)的typst模板](https://github.com/MosRat/modern-bnu-thesis)进行的二次开发
36+
37+
38+
39+
## License
40+
41+
This project is licensed under the MIT License.

packages/preview/modern-bnu-course-paper/0.1.0/assets/vi/bnu-name.svg

Lines changed: 211 additions & 0 deletions
Loading

packages/preview/modern-bnu-course-paper/0.1.0/assets/vi/old_bnu-name.svg

Lines changed: 9 additions & 0 deletions
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#import "@preview/i-figured:0.2.4"
2+
#import "../utils/custom-numbering.typ": custom-numbering
3+
4+
// 后记,重置 heading 计数器
5+
#let appendix(
6+
numbering: custom-numbering.with(first-level: "", depth: 4, "1.1 "),
7+
// figure 计数
8+
show-figure: i-figured.show-figure.with(numbering: "1.1"),
9+
// equation 计数
10+
show-equation: i-figured.show-equation.with(numbering: "(1.1)"),
11+
// 重置计数
12+
reset-counter: false,
13+
it,
14+
) = {
15+
set heading(numbering: numbering)
16+
if reset-counter {
17+
counter(heading).update(0)
18+
}
19+
// 设置 figure 的编号
20+
show figure: show-figure
21+
// 设置 equation 的编号
22+
show math.equation.where(block: true): show-equation
23+
it
24+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// 文稿设置,可以进行一些像页面边距这类的全局设置
2+
#let doc(
3+
// documentclass 传入参数
4+
info: (:),
5+
// 其他参数
6+
fallback: false, // 字体缺失时使用 fallback,不显示豆腐块
7+
lang: "zh",
8+
margin: (left:2.5cm, right:2cm, top:2.5cm, bottom:3.5cm,),
9+
it,
10+
) = {
11+
// 1. 默认参数
12+
info = (
13+
title: ("基于 Typst 的", "北京师范大学学位论文"),
14+
author: "张三",
15+
) + info
16+
17+
// 2. 对参数进行处理
18+
// 2.1 如果是字符串,则使用换行符将标题分隔为列表
19+
if type(info.title) == str {
20+
info.title = info.title.split("\n")
21+
}
22+
23+
// 3. 基本的样式设置
24+
set text(fallback: fallback, lang: lang)
25+
set page(
26+
margin: margin,
27+
// 添加页码设置
28+
numbering: "1", // 从1开始的阿拉伯数字
29+
number-align: center, // 页码居中
30+
)
31+
32+
// 4. PDF 元信息
33+
set document(
34+
title: (("",)+ info.title).sum(),
35+
author: info.author,
36+
)
37+
38+
it
39+
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#import "@preview/anti-matter:0.0.2": anti-front-end
2+
#import "@preview/i-figured:0.2.4"
3+
#import "../utils/style.typ": 字号, 字体
4+
#import "../utils/custom-numbering.typ": custom-numbering
5+
#import "../utils/custom-heading.typ": heading-display, active-heading, current-heading
6+
#import "../utils/indent.typ": fake-par
7+
#import "../utils/unpairs.typ": unpairs
8+
#import "../utils/custom-cuti.typ":*
9+
#import "../utils/custom-algo.typ":*
10+
11+
#let mainmatter(
12+
// documentclass 传入参数
13+
twoside: false,
14+
fonts: (:),
15+
// 其他参数
16+
leading: 1.5 * 15.6pt - 0.7em,
17+
spacing: 1.5 * 15.6pt - 0.7em,
18+
justify: true,
19+
first-line-indent: 2em,
20+
numbering: custom-numbering.with(first-level: "1 ", depth: 4, "1.1 "),
21+
// 正文字体与字号参数
22+
text-args: auto,
23+
// 标题字体与字号
24+
heading-font: auto,
25+
heading-size: (16pt, 15pt, 14pt, 12pt,),
26+
heading-weight: ("bold",),
27+
heading-above: (2 * 15.6pt - 0.7em, 2 * 15.6pt - 0.7em),
28+
heading-below: (2 * 15.6pt - 0.7em, 1.5 * 15.6pt - 0.7em),
29+
heading-pagebreak: (false, false),
30+
heading-align: (left, auto),
31+
// 页眉
32+
header-render: auto,
33+
header-vspace: 0em,
34+
display-header: false,
35+
skip-on-first-level: true,
36+
stroke-width: 0.5pt,
37+
reset-footnote: true,
38+
// caption 的 separator
39+
separator: " ",
40+
// caption 样式
41+
caption-style: text,
42+
caption-size: 字号.五号,
43+
// figure 计数
44+
show-figure: i-figured.show-figure,
45+
// equation 计数
46+
show-equation: i-figured.show-equation,
47+
..args,
48+
it,
49+
) = {
50+
// 0. 标志前言结束
51+
anti-front-end()
52+
v(1.6em)
53+
54+
show: show-cn-fakebold
55+
56+
// 1. 默认参数
57+
fonts = 字体 + fonts
58+
if (text-args == auto) {
59+
text-args = (font: ("Times New Roman", "SimSun", ..fonts.宋体), size: 字号.小四)
60+
}
61+
// 1.1 字体与字号
62+
if (heading-font == auto) {
63+
heading-font = (("Times New Roman", "SimHei", ..fonts.黑体),)
64+
}
65+
// 1.2 处理 heading- 开头的其他参数
66+
let heading-text-args-lists = args.named().pairs()
67+
.filter((pair) => pair.at(0).starts-with("heading-"))
68+
.map((pair) => (pair.at(0).slice("heading-".len()), pair.at(1)))
69+
70+
// 2. 辅助函数
71+
let array-at(arr, pos) = {
72+
arr.at(calc.min(pos, arr.len()) - 1)
73+
}
74+
75+
// 3. 设置基本样式
76+
// 3.1 文本和段落样式
77+
set text(..text-args)
78+
set par(leading: leading, justify: justify, first-line-indent: first-line-indent, spacing: spacing)
79+
show raw: set text(font: fonts.等宽)
80+
// 3.2 脚注样式
81+
show footnote.entry: set text(font: fonts.宋体, size: 字号.五号)
82+
// 3.3 设置 figure 的编号
83+
show heading: i-figured.reset-counters
84+
show figure: show-figure
85+
// 3.4 设置 equation 的编号和假段落首行缩进
86+
show math.equation.where(block: true): show-equation
87+
// 3.5 表格表头置顶 + 不用冒号用空格分割 + 样式
88+
show figure.where(kind: table): set figure.caption(position: top)
89+
set figure.caption(separator: separator)
90+
show figure.caption: caption-style
91+
show figure.caption: set text(font: fonts.宋体, size: 字号.五号)
92+
// 3.6 优化列表显示
93+
// 术语列表 terms 不应该缩进
94+
show terms: set par(first-line-indent: 0pt)
95+
// 3.7 处理算法结构
96+
show figure.where(kind: "algo"):show-algo
97+
98+
// 4. 处理标题
99+
// 4.1 设置标题的 Numbering
100+
set heading(numbering: numbering)
101+
// 4.2 设置字体字号并加入假段落模拟首行缩进
102+
show heading: it => {
103+
set text(
104+
font: array-at(heading-font, it.level),
105+
size: array-at(heading-size, it.level),
106+
weight: array-at(heading-weight, it.level),
107+
..unpairs(heading-text-args-lists
108+
.map((pair) => (pair.at(0), array-at(pair.at(1), it.level)))),
109+
)
110+
set block(above: array-at(heading-above, it.level), below: array-at(heading-below, it.level))
111+
it
112+
fake-par
113+
}
114+
// 4.3 标题居中与自动换页
115+
show heading: it => {
116+
if (array-at(heading-pagebreak, it.level)) {
117+
// 如果打上了 no-auto-pagebreak 标签,则不自动换页
118+
if ("label" not in it.fields() or str(it.label) != "no-auto-pagebreak") {
119+
// pagebreak(weak: true)
120+
}
121+
}
122+
if (array-at(heading-align, it.level) != auto) {
123+
set align(array-at(heading-align, it.level))
124+
it
125+
} else {
126+
it
127+
}
128+
}
129+
130+
it
131+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#import "@preview/anti-matter:0.0.2": anti-matter
2+
3+
// 前言,重置页面计数器
4+
#let preface(
5+
// documentclass 传入的参数
6+
twoside: false,
7+
// 其他参数
8+
spec: (front: "I", inner: "1", back: "I"),
9+
..args,
10+
it,
11+
) = {
12+
// 分页
13+
if (twoside) {
14+
pagebreak(weak: true) + " "
15+
counter(page).update(0)
16+
}else{
17+
counter(page).update(1)
18+
}
19+
20+
anti-matter(spec: spec, ..args, it)
21+
}

0 commit comments

Comments
 (0)