Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modern-bnu-course-paper:0.1.0 #1532

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/preview/modern-bnu-course-paper/0.1.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Euan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions packages/preview/modern-bnu-course-paper/0.1.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
* @Author: Euan [email protected]
* @Date: 2024-11-15 11:36:36
* @LastEditors: Euan [email protected]
*
* Copyright (c) 2025 by Euan, All Rights Reserved.
-->
# 北京师范大学大学课程论文 modern-bnu-course-paper
> [!NOTE]
> 可以前往[Typst Universe](https://typst.app/universe/package/modern-bnu-course-paper)快捷使用模版书写论文

北京师范大学大学课程论文的 Typst 模板,能够简洁、快速、持续生成 PDF 格式的课程论文。

不仅适用于BNU的课程论文,也适合其他学校课程课程论文(格式要求规范但未给出模板的)。


🙋 什么是Typst?
Typst格式类似于Markdown可以快速掌握,比起Word省略了非常多格式调整工作,比Latex更简单易用。

## 使用方法
1. [推荐🧑‍🎓] Typst可以使用[线上WebApp](https://typst.app/universe/search/?kind=templates);
> 如果是 Web App 上编辑,你应该手动上传这些字体文件(见 [nju模版](https://github.com/nju-lug/modern-nju-thesis/tree/main/fonts/FangZheng) 里的所有字体),否则不能正常使用「楷体」和「仿宋」,导致显示错误。
2. [推荐一定代码基础的👩‍💻]本地下载[相关资源]()后进行编写。
- Typst Universe:从Typst Universe中使用这个模板非常简单和容易。如果您更喜欢使用本地编辑器和typst-cli,您可以使用以下命令使用此模板创建新的求职信项目。

```typst init @preview/modern-bnu-course-paper```
- download from GitHub:您可以克隆此存储库并将其作为普通项目使用

```git clone https://github.com/EuanTop/modern-bnu-course-paper```




> [!tip]
> 本模板是基于[北京师范大学毕业论文(设计)的typst模板](https://github.com/MosRat/modern-bnu-thesis)进行的二次开发



## License

This project is licensed under the MIT License.
211 changes: 211 additions & 0 deletions packages/preview/modern-bnu-course-paper/0.1.0/assets/vi/bnu-name.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#import "@preview/i-figured:0.2.4"
#import "../utils/custom-numbering.typ": custom-numbering

// 后记,重置 heading 计数器
#let appendix(
numbering: custom-numbering.with(first-level: "", depth: 4, "1.1 "),
// figure 计数
show-figure: i-figured.show-figure.with(numbering: "1.1"),
// equation 计数
show-equation: i-figured.show-equation.with(numbering: "(1.1)"),
// 重置计数
reset-counter: false,
it,
) = {
set heading(numbering: numbering)
if reset-counter {
counter(heading).update(0)
}
// 设置 figure 的编号
show figure: show-figure
// 设置 equation 的编号
show math.equation.where(block: true): show-equation
it
}
39 changes: 39 additions & 0 deletions packages/preview/modern-bnu-course-paper/0.1.0/layouts/doc.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 文稿设置,可以进行一些像页面边距这类的全局设置
#let doc(
// documentclass 传入参数
info: (:),
// 其他参数
fallback: false, // 字体缺失时使用 fallback,不显示豆腐块
lang: "zh",
margin: (left:2.5cm, right:2cm, top:2.5cm, bottom:3.5cm,),
it,
) = {
// 1. 默认参数
info = (
title: ("基于 Typst 的", "北京师范大学学位论文"),
author: "张三",
) + info

// 2. 对参数进行处理
// 2.1 如果是字符串,则使用换行符将标题分隔为列表
if type(info.title) == str {
info.title = info.title.split("\n")
}

// 3. 基本的样式设置
set text(fallback: fallback, lang: lang)
set page(
margin: margin,
// 添加页码设置
numbering: "1", // 从1开始的阿拉伯数字
number-align: center, // 页码居中
)

// 4. PDF 元信息
set document(
title: (("",)+ info.title).sum(),
author: info.author,
)

it
}
131 changes: 131 additions & 0 deletions packages/preview/modern-bnu-course-paper/0.1.0/layouts/mainmatter.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#import "@preview/anti-matter:0.0.2": anti-front-end
#import "@preview/i-figured:0.2.4"
#import "../utils/style.typ": 字号, 字体
#import "../utils/custom-numbering.typ": custom-numbering
#import "../utils/custom-heading.typ": heading-display, active-heading, current-heading
#import "../utils/indent.typ": fake-par
#import "../utils/unpairs.typ": unpairs
#import "../utils/custom-cuti.typ":*
#import "../utils/custom-algo.typ":*

#let mainmatter(
// documentclass 传入参数
twoside: false,
fonts: (:),
// 其他参数
leading: 1.5 * 15.6pt - 0.7em,
spacing: 1.5 * 15.6pt - 0.7em,
justify: true,
first-line-indent: 2em,
numbering: custom-numbering.with(first-level: "1 ", depth: 4, "1.1 "),
// 正文字体与字号参数
text-args: auto,
// 标题字体与字号
heading-font: auto,
heading-size: (16pt, 15pt, 14pt, 12pt,),
heading-weight: ("bold",),
heading-above: (2 * 15.6pt - 0.7em, 2 * 15.6pt - 0.7em),
heading-below: (2 * 15.6pt - 0.7em, 1.5 * 15.6pt - 0.7em),
heading-pagebreak: (false, false),
heading-align: (left, auto),
// 页眉
header-render: auto,
header-vspace: 0em,
display-header: false,
skip-on-first-level: true,
stroke-width: 0.5pt,
reset-footnote: true,
// caption 的 separator
separator: " ",
// caption 样式
caption-style: text,
caption-size: 字号.五号,
// figure 计数
show-figure: i-figured.show-figure,
// equation 计数
show-equation: i-figured.show-equation,
..args,
it,
) = {
// 0. 标志前言结束
anti-front-end()
v(1.6em)

show: show-cn-fakebold

// 1. 默认参数
fonts = 字体 + fonts
if (text-args == auto) {
text-args = (font: ("Times New Roman", "SimSun", ..fonts.宋体), size: 字号.小四)
}
// 1.1 字体与字号
if (heading-font == auto) {
heading-font = (("Times New Roman", "SimHei", ..fonts.黑体),)
}
// 1.2 处理 heading- 开头的其他参数
let heading-text-args-lists = args.named().pairs()
.filter((pair) => pair.at(0).starts-with("heading-"))
.map((pair) => (pair.at(0).slice("heading-".len()), pair.at(1)))

// 2. 辅助函数
let array-at(arr, pos) = {
arr.at(calc.min(pos, arr.len()) - 1)
}

// 3. 设置基本样式
// 3.1 文本和段落样式
set text(..text-args)
set par(leading: leading, justify: justify, first-line-indent: first-line-indent, spacing: spacing)
show raw: set text(font: fonts.等宽)
// 3.2 脚注样式
show footnote.entry: set text(font: fonts.宋体, size: 字号.五号)
// 3.3 设置 figure 的编号
show heading: i-figured.reset-counters
show figure: show-figure
// 3.4 设置 equation 的编号和假段落首行缩进
show math.equation.where(block: true): show-equation
// 3.5 表格表头置顶 + 不用冒号用空格分割 + 样式
show figure.where(kind: table): set figure.caption(position: top)
set figure.caption(separator: separator)
show figure.caption: caption-style
show figure.caption: set text(font: fonts.宋体, size: 字号.五号)
// 3.6 优化列表显示
// 术语列表 terms 不应该缩进
show terms: set par(first-line-indent: 0pt)
// 3.7 处理算法结构
show figure.where(kind: "algo"):show-algo

// 4. 处理标题
// 4.1 设置标题的 Numbering
set heading(numbering: numbering)
// 4.2 设置字体字号并加入假段落模拟首行缩进
show heading: it => {
set text(
font: array-at(heading-font, it.level),
size: array-at(heading-size, it.level),
weight: array-at(heading-weight, it.level),
..unpairs(heading-text-args-lists
.map((pair) => (pair.at(0), array-at(pair.at(1), it.level)))),
)
set block(above: array-at(heading-above, it.level), below: array-at(heading-below, it.level))
it
fake-par
}
// 4.3 标题居中与自动换页
show heading: it => {
if (array-at(heading-pagebreak, it.level)) {
// 如果打上了 no-auto-pagebreak 标签,则不自动换页
if ("label" not in it.fields() or str(it.label) != "no-auto-pagebreak") {
// pagebreak(weak: true)
}
}
if (array-at(heading-align, it.level) != auto) {
set align(array-at(heading-align, it.level))
it
} else {
it
}
}

it
}
21 changes: 21 additions & 0 deletions packages/preview/modern-bnu-course-paper/0.1.0/layouts/preface.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#import "@preview/anti-matter:0.0.2": anti-matter

// 前言,重置页面计数器
#let preface(
// documentclass 传入的参数
twoside: false,
// 其他参数
spec: (front: "I", inner: "1", back: "I"),
..args,
it,
) = {
// 分页
if (twoside) {
pagebreak(weak: true) + " "
counter(page).update(0)
}else{
counter(page).update(1)
}

anti-matter(spec: spec, ..args, it)
}
Loading