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

ori:0.2.0, theorion:0.3.0 and touying:0.6.1 #1831

Open
wants to merge 4 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
19 changes: 19 additions & 0 deletions packages/preview/ori/0.2.0/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2025 OrangeX4 <orangex4@qq.com>

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.
89 changes: 89 additions & 0 deletions packages/preview/ori/0.2.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# 🌠Ori

[Ori](https://github.com/OrangeX4/typst-ori) 是一个简单但富有表现力的自用 Typst 文档模板,适用于笔记(支持夜间模式)、报告和各类文档。同时也是我个人 Typst 中文写作的最佳实践。

## 快速开始

要使用此模板,您需要:

1. 安装必需的字体:
- [IBM Plex Sans, Mono](https://github.com/IBM/plex)
- [Noto Serif CJK SC](https://github.com/notofonts/noto-cjk)

2. 导入模板,并在文档开头设置参数,包括标题、作者、课程或主题、学期、时间;
```typ
#import "@preview/ori:0.2.0": *

#set heading(numbering: numbly("{1:一}、", default: "1.1 "))

#show: ori.with(
title: "文档标题",
author: "张三",
subject: "Ori in Typst",
semester: "2025 春",
date: datetime.today(),
// maketitle: true,
// makeoutline: true,
// theme: "dark",
// media: "screen",
)
```

## 特性

### 可配置参数

- `size`: 字体大小(默认 `11pt`)
- `screen-size`: 屏幕显示字体大小(默认 `11pt`)
- `maketitle`: 是否生成标题页(默认 `false`)
- `makeoutline`: 是否生成目录(默认 `false`)
- `outline-depth`: 目录深度(默认 `2`)
- `first-line-indent`: 首行缩进(设置为 `auto` 则为 `2em`)
- `media`: 媒体类型(`"screen"` 或 `"print"`)
- `lang`: 语言(默认 `"zh"`)
- `region`: 地区(默认 `"cn"`)

### 主要功能

1. **三线表支持**:基于 [Tablem 包](https://github.com/OrangeX4/typst-tablem),提供简单的三线表功能
2. **Markdown 渲染**:基于 [Cmarker 包](https://github.com/SabrinaJewson/cmarker.typ),支持 Markdown 语法,包括加粗、斜体、删除线等
3. **数学公式**:基于 [MiTeX 包](https://github.com/mitex-rs/mitex) 支持 LaTeX 风格的数学公式
4. **定理环境**:基于 [Theorion 包](https://github.com/OrangeX4/typst-theorion),提供多种定理环境(定义、定理、引理、命题等)
5. **提示框**:包含多种样式的提示框(强调、引用、注意、提示、重要、警告、小心)

### 自定义

#### 标题编号

可以使用 `numbly` 包自定义标题编号样式:

```typst
#set heading(numbering: numbly("{1:一}、", default: "1.1 "))
```

#### 字体设置

可以通过设置 `font` 参数自定义字体:

```typst
#let font = (
main: "IBM Plex Sans",
mono: "IBM Plex Mono",
cjk: "Noto Serif SC",
emph-cjk: "KaiTi",
math: "New Computer Modern Math",
math-cjk: "Noto Serif SC",
)
```

## 需要定制?

源码仅有两百行左右,可以复制下来轻松定制。

## 致谢

- 感谢 [hongjr03](https://github.com/hongjr03) 的 [typst-assignment-template](https://github.com/hongjr03/typst-assignment-template)

## 许可证

MIT License
202 changes: 202 additions & 0 deletions packages/preview/ori/0.2.0/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#import "@preview/numbly:0.1.0": numbly
#import "@preview/tablem:0.2.0": tablem, three-line-table
#import "@preview/mitex:0.2.5": *
#import "@preview/cmarker:0.1.2": render as cmarker-render
#import "@preview/theorion:0.3.0": *

Check failure on line 5 in packages/preview/ori/0.2.0/lib.typ

View check run for this annotation

Typst package check / @preview/ori:0.2.0

packages/preview/ori/0.2.0/lib.typ#L5

The following error was reported by the Typst compiler: failed to download package (All packages are supposed to be present in the `packages` repository, or in the local cache.)

Check failure on line 5 in packages/preview/ori/0.2.0/lib.typ

View check run for this annotation

Typst package check / @preview/ori:0.2.0

packages/preview/ori/0.2.0/lib.typ#L5

The following error was reported by the Typst compiler: failed to download package (All packages are supposed to be present in the `packages` repository, or in the local cache.)
#import cosmos.fancy: *
#let md = cmarker-render.with(math: mitex)

#let default-font = (
main: "IBM Plex Sans",
mono: "IBM Plex Mono",
cjk: "Noto Serif SC",
emph-cjk: "KaiTi",
math: "New Computer Modern Math",
math-cjk: "Noto Serif SC",
)

// Definitions for math
#let prox = math.op("prox")
#let proj = math.op("proj")
#let argmax = math.op("argmax", limits: true)
#let argmin = math.op("argmin", limits: true)


/// 模板的核心类,规范了文档的格式。
/// - media (string): 媒体类型,可选值为 `"screen"` 和 `"print"`。默认为 `"print"`。
/// - theme (string): 主题,可选值为 `"light"` 和 `"dark"`。默认为 `"light"`。
/// - size (length): 字体大小。默认为 `11pt`。
/// - screen-size (length): 屏幕字体大小。默认为 `11pt`。
/// - title (string): 文档的标题。
/// - author (string): 作者。
/// - subject (string): 课程名。
/// - semester (string): 学期。
/// - date (datetime): 时间。
/// - font (object): 字体。默认为 `default-font`。如果你想使用不同的字体,可以传入一个字典,包含 `main`、`mono`、`cjk`、`math` 和 `math-cjk` 字段。
/// - lang (string): 语言。默认为 `zh`。
/// - region (string): 地区。默认为 `cn`。
/// - body (content): 文档的内容。
/// -> content
#let ori(
media: "print",
theme: "light",
size: 11pt,
screen-size: 11pt,
title: none,
author: none,
subject: none,
semester: none,
date: none,
font: default-font,
lang: "zh",
region: "cn",
first-line-indent: (amount: 0pt, all: false),
maketitle: false,
makeoutline: false,
outline-depth: 2,
body,
) = {
assert(media == "screen" or media == "print", message: "media must be 'screen' or 'print'")
assert(theme == "light" or theme == "dark", message: "theme must be 'light' or 'dark'")
let page-margin = if media == "screen" { (x: 35pt, y: 35pt) } else { auto }
let text-size = if media == "screen" { screen-size } else { size }
let bg-color = if theme == "dark" { rgb("#1f1f1f") } else { rgb("#ffffff") }
let text-color = if theme == "dark" { rgb("#ffffff") } else { rgb("#000000") }
let raw-color = if theme == "dark" { rgb("#27292c") } else { rgb("#f0f0f0") }
let font = default-font + font

/// 设置字体。
set text(
font: ((name: font.main, covers: "latin-in-cjk"), font.cjk),
size: text-size,
fill: text-color,
lang: lang,
region: region,
)
show emph: text.with(font: ((name: font.main, covers: "latin-in-cjk"), font.emph-cjk))
show raw: set text(font: ((name: font.mono, covers: "latin-in-cjk"), font.cjk))
show math.equation: it => {
set text(font: font.math)
show regex("\p{script=Han}"): set text(font: font.math-cjk)
it
}

/// 设置段落样式。
set par(
justify: true,
first-line-indent: if first-line-indent == auto {
(amount: 2em, all: true)
} else {
first-line-indent
},
)

/// 设置标题样式。
show heading: it => {
show h.where(amount: 0.3em): none
it
}
show heading: set block(spacing: 1.2em)

/// 设置代码块样式。
show raw.where(block: false): body => box(
fill: raw-color,
inset: (x: 3pt, y: 0pt),
outset: (x: 0pt, y: 3pt),
radius: 2pt,
{
set par(justify: false)
body
},
)
show raw.where(block: true): body => block(
width: 100%,
fill: raw-color,
outset: (x: 0pt, y: 4pt),
inset: (x: 8pt, y: 4pt),
radius: 4pt,
{
set par(justify: false)
body
},
)

/// 设置链接样式。
show link: it => {
if type(it.dest) == str {
set text(fill: blue)
it
} else {
it
}
}

/// 设置 figure 样式。
show figure.where(kind: table): set figure.caption(position: top)

/// 设置列表样式。
set list(indent: 6pt)
set enum(indent: 6pt)
set enum(numbering: numbly("{1:1}.", "{2:1})", "{3:a}."), full: true)

/// 设置引用样式。
set bibliography(style: "ieee")

/// 基础设置。
set document(title: title, author: if type(author) == str { author } else { () }, date: date)

/// 标题页。
if maketitle {
// Title page
align(center + top)[
#v(20%)
#text(2em, weight: 500, subject)
#v(2em, weak: true)
#text(2em, weight: 500, title)
#v(2em, weak: true)
#author
]
pagebreak(weak: true)
}

/// 目录。
if makeoutline {
show heading: align.with(center)
show outline.entry: set block(spacing: 1.2em)

outline(depth: outline-depth, indent: 2em)
pagebreak(weak: true)
}

/// 重置页面计数器。
counter(page).update(1)

/// 设置页面。
set page(
paper: "a4",
header: {
set text(0.9em)
stack(
spacing: 0.2em,
grid(
columns: (1fr, auto, 1fr),
align(left, semester), align(center, subject), align(right, title),
),
v(0.3em),
line(length: 100%, stroke: 1pt + text-color),
v(.15em),
line(length: 100%, stroke: .5pt + text-color),
)
// reset footnote counter
counter(footnote).update(0)
},
fill: bg-color,
numbering: "1",
margin: page-margin,
)

/// 设置定理环境。
show: show-theorion

body
}
Loading