diff --git a/packages/preview/simple-handout/0.2.0/LICENSE b/packages/preview/simple-handout/0.2.0/LICENSE new file mode 100644 index 0000000000..0592470ab6 --- /dev/null +++ b/packages/preview/simple-handout/0.2.0/LICENSE @@ -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. diff --git a/packages/preview/simple-handout/0.2.0/README.md b/packages/preview/simple-handout/0.2.0/README.md new file mode 100644 index 0000000000..866d705926 --- /dev/null +++ b/packages/preview/simple-handout/0.2.0/README.md @@ -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`](https://github.com/chillcicada/simple-handout-template/tree/webapp/example) 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. diff --git a/packages/preview/simple-handout/0.2.0/src/font.typ b/packages/preview/simple-handout/0.2.0/src/font.typ new file mode 100644 index 0000000000..8f80c6bd49 --- /dev/null +++ b/packages/preview/simple-handout/0.2.0/src/font.typ @@ -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) +} diff --git a/packages/preview/simple-handout/0.2.0/src/imports.typ b/packages/preview/simple-handout/0.2.0/src/imports.typ new file mode 100644 index 0000000000..b302109348 --- /dev/null +++ b/packages/preview/simple-handout/0.2.0/src/imports.typ @@ -0,0 +1 @@ +#import "@preview/tntt:0.5.1" diff --git a/packages/preview/simple-handout/0.2.0/src/lib.typ b/packages/preview/simple-handout/0.2.0/src/lib.typ new file mode 100644 index 0000000000..2d7edfd301 --- /dev/null +++ b/packages/preview/simple-handout/0.2.0/src/lib.typ @@ -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), + ) +} + diff --git a/packages/preview/simple-handout/0.2.0/src/pages/cover.typ b/packages/preview/simple-handout/0.2.0/src/pages/cover.typ new file mode 100644 index 0000000000..be50dbdf26 --- /dev/null +++ b/packages/preview/simple-handout/0.2.0/src/pages/cover.typ @@ -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) +} diff --git a/packages/preview/simple-handout/0.2.0/src/pages/preface.typ b/packages/preview/simple-handout/0.2.0/src/pages/preface.typ new file mode 100644 index 0000000000..72372dc418 --- /dev/null +++ b/packages/preview/simple-handout/0.2.0/src/pages/preface.typ @@ -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))) +} diff --git a/packages/preview/simple-handout/0.2.0/template/main.typ b/packages/preview/simple-handout/0.2.0/template/main.typ new file mode 100644 index 0000000000..a067a37090 --- /dev/null +++ b/packages/preview/simple-handout/0.2.0/template/main.typ @@ -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() diff --git a/packages/preview/simple-handout/0.2.0/template/refs.bib b/packages/preview/simple-handout/0.2.0/template/refs.bib new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/preview/simple-handout/0.2.0/thumbnail.png b/packages/preview/simple-handout/0.2.0/thumbnail.png new file mode 100644 index 0000000000..f6e571e979 Binary files /dev/null and b/packages/preview/simple-handout/0.2.0/thumbnail.png differ diff --git a/packages/preview/simple-handout/0.2.0/typst.toml b/packages/preview/simple-handout/0.2.0/typst.toml new file mode 100644 index 0000000000..97e5359921 --- /dev/null +++ b/packages/preview/simple-handout/0.2.0/typst.toml @@ -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"