fix(render): per-level heading numbering via numbly; config-driven, offline (WU-C)

Fixes the numbering bug (single pattern "一、" reused across levels → level-2
rendered "二、一、…"). display now takes a `config` dict; heading numbering uses
numbly per level — framework default ("{1:一}、","{1:1}.{2:1}","{1:1}.{2:1}.{3:1}")
→ 一、 / 1.1 / 1.1.1 — overridable via config.numbering.heading from the
engineering file (ADR-0009's file-resident override path, the layer whose absence
caused the bug). Verified: grep "二、一" = 0 across all smoke PDFs.

Adds @preview/numbly:0.1.0 (pure typst, zero transitive deps), VENDORED in-repo
at render/vendor/typst-packages/preview/numbly/0.1.0/ for network-free CI;
resolve via --package-cache-path render/vendor/typst-packages. parts contract +
student/teacher field visibility unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-22 08:42:15 +08:00
parent b5bf9d60d1
commit 6f46aa708a
9 changed files with 187 additions and 10 deletions
+24 -6
View File
@@ -1,18 +1,36 @@
// Base document styling: CJK fonts, headings, math, paragraph layout, page.
//
// Zero external dependencies. Heading numbering uses builtin `numbering`
// strings (no @preview/numbly) so the package compiles with no network.
// Heading numbering is PER-LEVEL and built from a numbly pattern array passed
// in by the caller (lib.typ resolves it from config + framework default). This
// fixes the old single-pattern bug where one `numbering: "一、"` was reused for
// every level (a level-2 heading rendered as `二、一、…`). The only @preview
// dependency is `@preview/numbly`, vendored under `render/vendor/...` for
// network-free CI; see render/typst.toml's note.
#import "@preview/numbly:0.1.0": numbly
#import "fonts.typ"
/// Apply the base style to a document body. Used as `show: base-style`.
#let base-style(doc) = {
/// Framework-default per-level heading numbering patterns (numbly syntax).
/// Level 1 -> `一、`, level 2 -> `1.1`, level 3 -> `1.1.1`. This is the
/// correct-by-default scheme; `config.numbering.heading` overrides it.
#let default-heading-numbering = (
"{1:一}、",
"{1:1}.{2:1}",
"{1:1}.{2:1}.{3:1}",
)
/// Apply the base style to a document body. Used as `show: base-style(..)`.
///
/// `heading-numbering` is an array of per-level numbly pattern strings; it is
/// spread into `numbly(..)` to build the per-level heading numbering function.
#let base-style(heading-numbering: default-heading-numbering, doc) = {
// Language / region drive CJK line-breaking and punctuation.
set text(lang: "zh", region: "cn", size: 12pt, font: fonts.serif)
set text(cjk-latin-spacing: auto)
// Heading numbering: 一、 / 1.1 / 1.1.1 — builtin numbering, no deps.
set heading(numbering: "一、")
// Per-level heading numbering via numbly: each level gets its own pattern,
// so level 2 renders `1.1`, not the old buggy `二、一、`.
set heading(numbering: numbly(..heading-numbering))
show heading: set text(font: fonts.sans)
// Number display equations.