-
Notifications
You must be signed in to change notification settings - Fork 969
simple-handout:0.2.0 #4348
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
Merged
Merged
simple-handout:0.2.0 #4348
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2025 chillcicada | ||
|
|
||
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Simple Handout Template | ||
|
|
||
| This is a simple typst handout template for Chinese typesetting based on [TnTT](https://github.com/chillcicada/tntt), **original made for my course 'Polymer Molding and Processing' at the Tsinghua University.** It is designed to be easy to use and modify, with a focus on simplicity and clarity. | ||
|
|
||
| ## Example | ||
|
|
||
| See the [`example`](example/README.md) folder for an example handout, which is made for the course 'Polymer Molding and Processing' at Tsinghua University. | ||
|
|
||
| ## LICENSE | ||
|
|
||
| For the source code of the template, it's released under the [MIT](LICENSE) license. And the example handout under the `example` folder is released under the CC BY-NC-SA 4.0 license. You can use them for non-commercial purposes, but please give credit to the original author and share any derivative works under the same license. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| //! Currently, there are already many related packages available to implement similar functions. | ||
| //! So you should explore and use them instead of relying on this built-in implementation. | ||
| //! since the current implementation is not perfect. All inherits from tntt and is not exported. | ||
|
|
||
| #let _builtin-font-family = ("SongTi", "HeiTi", "KaiTi", "FangSong", "Mono", "Math") | ||
|
|
||
| /// Get the font configuration from the fonts dictionary by font family name. | ||
| /// | ||
| /// - fonts (dict): the fonts configuration dictionary. | ||
| /// - name (str): the font family name, must be one of fonts. | ||
| /// -> array | ||
| #let _use-fonts(fonts, name) = { | ||
| assert( | ||
| _builtin-font-family.all(k => k in fonts), | ||
| message: "Required font families: " + _builtin-font-family.filter(k => k not in fonts).join(", "), | ||
| ) | ||
| assert(name in fonts, message: "Unsupported font family for fonts: " + name) | ||
| fonts.at(name) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| #import "@preview/tntt:0.5.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #import "imports.typ": tntt | ||
| #import tntt: cuti, use-size | ||
|
|
||
| #let define-config( | ||
| info: (:), | ||
| fonts: (:), | ||
| twoside: false, | ||
| bibliography: none, | ||
| ) = { | ||
| import "font.typ": _use-fonts | ||
|
|
||
| import tntt.exports: * | ||
| import "pages/cover.typ": cover | ||
| import "pages/preface.typ": preface | ||
|
|
||
| if type(info.title) == str { info.title = info.title.split("\n") } else { | ||
| assert(type(info.title) == array, message: "标题(info.title)必须是字符串或字符串数组") | ||
| } | ||
|
|
||
| return ( | ||
| /// ------ /// | ||
| /// config /// | ||
| /// ------ /// | ||
| info: info, | ||
| fonts: fonts, | ||
| twoside: twoside, | ||
| /// --------- /// | ||
| /// utilities /// | ||
| /// --------- /// | ||
| use-fonts: _use-fonts.with(fonts), | ||
| /// ------- /// | ||
| /// layouts /// | ||
| /// ------- /// | ||
| meta: meta.with(info: (..info, author: info.authors.map(a => a.name))), | ||
| doc: doc.with(default-fonts: fonts), | ||
| front-matter: front-matter, | ||
| main-matter: main-matter.with(twoside: twoside), | ||
| back-matter: back-matter.with(twoside: twoside), | ||
| /// ----- /// | ||
| /// pages /// | ||
| /// ----- /// | ||
| fonts-display: fonts-display.with(fonts: fonts), | ||
| cover: cover.with(info: info, default-fonts: fonts), | ||
| preface: preface.with(twoside: twoside, default-fonts: fonts), | ||
| outline-wrapper: outline-wrapper.with(twoside: twoside, default-fonts: fonts), | ||
| notation: notation.with(twoside: twoside), | ||
| master-list: master-list.with(twoside: twoside), | ||
| figure-list: figure-list.with(twoside: twoside), | ||
| table-list: table-list.with(twoside: twoside), | ||
| equation-list: equation-list.with(twoside: twoside), | ||
| bilingual-bibliography: bilingual-bibliography.with(bibliography), | ||
| ) | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #let cover( | ||
| // from entry | ||
| info: (:), | ||
| fonts: (:), | ||
| // options | ||
| default-fonts: (:), | ||
| display-version: false, | ||
| ) = { | ||
| import "../font.typ": _use-fonts | ||
| import "../imports.typ": tntt | ||
| import tntt: space-text, use-size | ||
|
|
||
| let use-fonts = _use-fonts.with(fonts + default-fonts) | ||
|
|
||
| let parse-semver-major(version) = numbering("一", int(version.split(".").at(0))) | ||
|
|
||
| set text(font: use-fonts("SongTi")) | ||
|
|
||
| /// Render the cover page | ||
| // Title | ||
| v(1fr) | ||
|
|
||
| block(width: 100%, align(center, [ | ||
| #text(size: use-size("小初"), weight: "bold", spacing: 200%, space-text(info.title.sum())) | ||
|
|
||
| #text(size: use-size("一号"), weight: "regular", info.subtitle) | ||
|
|
||
| #text(size: use-size("三号"), weight: "regular", [(第#parse-semver-major(info.version)版)]) | ||
| ])) | ||
|
|
||
| v(3fr) | ||
|
|
||
| // Author | ||
| block(width: 100%, { | ||
| set text(font: use-fonts("FangSong")) | ||
|
|
||
| let author-chunk = range(info.authors.len()).chunks(2) | ||
|
|
||
| for author-pair in author-chunk { | ||
| grid( | ||
| columns: (1fr,) * author-pair.len(), column-gutter: -2em, | ||
| ..author-pair.map(index => align(center)[ | ||
| #text(size: use-size("四号"), weight: "bold")[ #info.authors.at(index).name \ ] | ||
| #text(size: use-size("小四"), weight: "regular", link("mailto:" + info.authors.at(index).email)) | ||
| #v(1em) | ||
| ]) | ||
| ) | ||
| } | ||
| }) | ||
|
|
||
| v(4fr) | ||
|
|
||
| // Date | ||
| block(width: 100%, text(size: use-size("小四"), align(center, info.date.display("[year] 年 [month] 月 [day] 日")))) | ||
|
|
||
| if display-version { | ||
| block(width: 100%, text(size: use-size("小四"), gray, align(center, [version #info.version]))) | ||
| } | ||
|
|
||
| v(1fr) | ||
| } |
34 changes: 34 additions & 0 deletions
34
packages/preview/simple-handout/0.2.0/src/pages/preface.typ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #let preface( | ||
| // from entry | ||
| fonts: (:), | ||
| twoside: false, | ||
| // options | ||
| default-fonts: (:), | ||
| date: datetime.today(), | ||
| date-display: "[year] 年 [month] 月 [day] 日", | ||
| title: [前 言], | ||
| outlined: false, | ||
| body-font: "FangSong", | ||
| back-font: "KaiTi", | ||
| // self | ||
| it, | ||
| ) = { | ||
| import "../font.typ": _use-fonts | ||
| import "../imports.typ": tntt | ||
| import tntt: twoside-pagebreak, use-size | ||
|
|
||
| let use-fonts = _use-fonts.with(fonts + default-fonts) | ||
|
|
||
| /// Render the preface page | ||
| twoside-pagebreak(twoside) | ||
|
|
||
| heading(level: 1, outlined: outlined, bookmarked: true, title) | ||
|
|
||
| // body | ||
| set text(font: use-fonts(body-font), size: use-size("小四")) | ||
|
|
||
| it | ||
|
|
||
| // back | ||
| align(right, text(font: use-fonts(body-font), size: use-size("小四"), date.display(date-display))) | ||
| } |
109 changes: 109 additions & 0 deletions
109
packages/preview/simple-handout/0.2.0/template/main.typ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| #import "@preview/simple-handout:0.2.0": define-config | ||
|
|
||
| /// 以下字体配置适用于安装了 Windows 10/11 字体及 Windows 10/11 简体中文字体扩展的设备, | ||
| /// 请勿修改 font-family 中定义的键值,一般情况下,其含义为: | ||
| /// - SongTi: 宋体,正文字体,通常对应西文中的衬线字体 | ||
| /// - HeiTi: 黑体,标题字体,通常对应西文中的无衬线字体 | ||
| /// - KaiTi: 楷体,用于说明性文本和主观性的表达 | ||
| /// - FangSong: 仿宋,通常用于注释、引文及权威性阐述 | ||
| /// - Mono: 等宽字体,对于代码,会优先使用此项,推荐中文字体使用黑体或楷体,或者一些流行的中文等宽字体 | ||
| /// - Math: 数学字体,通常用于数学公式和符号,中文字体默认使用楷体 | ||
| #let font-family = ( | ||
| SongTi: ((name: "Times New Roman", covers: "latin-in-cjk"), "NSimSun"), | ||
| HeiTi: ((name: "Arial", covers: "latin-in-cjk"), "SimHei"), | ||
| KaiTi: ((name: "Times New Roman", covers: "latin-in-cjk"), "KaiTi"), | ||
| FangSong: ((name: "Times New Roman", covers: "latin-in-cjk"), "FangSong"), | ||
| Mono: ((name: "DejaVu Sans Mono", covers: "latin-in-cjk"), "SimHei"), | ||
| Math: ("New Computer Modern Math", "KaiTi"), | ||
| ) | ||
|
|
||
| #let ( | ||
| ..config, | ||
| /// entry options | ||
| twoside, | ||
| use-fonts, | ||
| /// layouts | ||
| meta, | ||
| doc, | ||
| front-matter, | ||
| main-matter, | ||
| back-matter, | ||
| /// pages | ||
| fonts-display, | ||
| cover, | ||
| preface, | ||
| outline-wrapper, | ||
| notation, | ||
| master-list, | ||
| figure-list, | ||
| table-list, | ||
| equation-list, | ||
| bilingual-bibliography, | ||
| ) = define-config( | ||
| info: ( | ||
| title: "标题", | ||
| subtitle: "副标题", | ||
| authors: ( | ||
| (name: "作者", email: "mail@example.com"), | ||
| ), | ||
| version: "0.0.0", | ||
| date: datetime.today(), | ||
| ), | ||
| fonts: font-family, | ||
| twoside: false, | ||
| bibliography: read("refs.bib"), | ||
| ) | ||
|
|
||
| /// Document Configuration | ||
| #show: it => meta(it) | ||
|
|
||
| /// Font Display Page | ||
| #fonts-display() | ||
|
|
||
| /// Cover Page | ||
| #cover() | ||
|
|
||
| /// After Cover Layout, basical layout for Front Matter, Main Matter and Back Matter | ||
| #show: doc | ||
|
|
||
| /// ------------ /// | ||
| /// Front Matter /// | ||
| /// ------------ /// | ||
|
|
||
| #show: front-matter | ||
|
|
||
| // Preface Page | ||
| #preface[] | ||
|
|
||
| // Outline Page | ||
| #outline-wrapper() | ||
|
|
||
| /// ----------- /// | ||
| /// Main Matter /// | ||
| /// ----------- /// | ||
|
|
||
| #show: main-matter | ||
|
|
||
| = 第一部分 | ||
|
|
||
| == 第1.1章 | ||
|
|
||
| === 第1.1.1节 | ||
|
|
||
| /// ----------- /// | ||
| /// Back Matter /// | ||
| /// ----------- /// | ||
|
|
||
| #show: back-matter | ||
|
|
||
| #notation[ | ||
| / D#sub[m]: 预混通道外径 (mm) | ||
| ] | ||
|
|
||
| #figure-list() | ||
|
|
||
| #table-list() | ||
|
|
||
| #equation-list() | ||
|
|
||
| #bilingual-bibliography() |
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [package] | ||
| name = "simple-handout" | ||
| version = "0.2.0" | ||
| entrypoint = "src/lib.typ" | ||
| authors = ["chillcicada"] | ||
| license = "MIT" | ||
| description = "A simple handout template for Chinese typesetting based on TnTT." | ||
| repository = "https://github.com/chillcicada/simple-handout-template" | ||
| keywords = ["book", "handout", "template", "cjk", "tntt"] | ||
| categories = ["book"] | ||
| exclude = [".*", "example"] | ||
| compiler = "0.14.0" | ||
|
|
||
| [template] | ||
| path = "template" | ||
| entrypoint = "main.typ" | ||
| thumbnail = "thumbnail.png" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.