forked from bai/curriculum-project-hub
feat(cph): implement nested outline manifest and batch/combined export
ADR-0029 — nested outline manifest, supersedes ADR-0008's flat [[parts]]:
- cph-model: recursive loader over manifest.toml containers / element.toml
leaves; Lesson.parts (pure elements, DFS order) + Lesson.outline (elements
interleaved with section headings at their DFS-open position); rejects
ambiguous/incomplete folders and root-vs-container table misplacement
- cph-diag: new DiagCode::ManifestMalformed for carrier-document structure
errors (discharges an existing TODO)
- cph-typst: augmented manifest now serializes the outline (element/section
entries) instead of a flat parts array
- render/lib.typ: render-lesson renders section headings at their depth
- examples/TH-141 migrated to 5 nested section containers + 3 root segments,
byte-identical element order; smoke-verified via cph check/build + pdftotext
ADR-0030 — batch & combined export, extends ADR-0009/0011:
- cph build with no --target batches every declared target (repeatable
--target for an explicit subset); any target failure => non-zero exit,
per-target ledger, independent per-target execution
- cph-model: bundle.toml loader (directory + [info]/[targets.*]/ordered
lessons with per-lesson target overrides)
- cph-typst: augmented bundle manifest (path-prefixed member outlines),
Engine::{compile_check_bundle,build_bundle_pdf}
- render/lib.typ: render-bundle assembles member lessons under per-lesson
headings, depth-shifts their own section headings, resets example/lemma
counters at each lesson boundary by default
- cph-cli: `cph bundle <path> --target <name>` subcommand, same batching
contract as `cph build`
- new bundle fixtures/tests (cph-model unit + cph-typst through-template PDF
compile), smoke-verified via a real 2-lesson merged PDF
Verification: cargo fmt/clippy/test clean across the workspace (68 tests);
real cph check/build/bundle runs against TH-141 and a bundle fixture, PDF
content inspected via pdftotext.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// DEFAULT STUDENT TEMPLATE (framework default; ADR-0011).
|
||||
// DEFAULT STUDENT TEMPLATE (framework default; ADR-0011, outline shape ADR-0029).
|
||||
//
|
||||
// This is a *real, editable* file that lives in an engineering file at
|
||||
// `exports/student.typ`. The framework compiles it AS THE MAIN FILE with the
|
||||
@@ -15,15 +15,16 @@
|
||||
// its own virtual root — an include inside cph-render would resolve against the
|
||||
// PACKAGE, not the engineering root. A `/<part.path>/<field>.typ` written HERE
|
||||
// (this template lives under `--root`) resolves against `--root`. So the
|
||||
// template loads content and hands cph-render an already-assembled `parts` array.
|
||||
// template loads content and hands cph-render an already-assembled `outline`
|
||||
// array (elements interleaved with section headings, ADR-0029).
|
||||
//
|
||||
// OPEN CONTRACT POINT — optional-content presence. typst has no "does this file
|
||||
// exist" primitive (a missing `include` is a hard compile error). So the
|
||||
// template CANNOT probe disk the way the old Rust driver did for lemma `proof`.
|
||||
// It relies on the manifest declaring which optional content fields are present,
|
||||
// via a per-part `fields` array listing the content fields that exist on disk
|
||||
// via a per-element `fields` array listing the content fields that exist on disk
|
||||
// (the engine knows this — it walks the part dir). Required fields are loaded
|
||||
// unconditionally; optional fields load only if listed in `fields`. If a part
|
||||
// unconditionally; optional fields load only if listed in `fields`. If an element
|
||||
// omits `fields`, optional content is skipped (conservative). The exact shape of
|
||||
// this declaration is for the manifest/Rust contract to pin.
|
||||
|
||||
@@ -35,38 +36,51 @@
|
||||
// Read the injected manifest (a path string relative to typst --root).
|
||||
#let manifest = toml(sys.inputs.manifest)
|
||||
#let info = manifest.at("info", default: (:))
|
||||
#let raw-parts = manifest.at("parts", default: ())
|
||||
#let raw-outline = manifest.at("outline", default: ())
|
||||
|
||||
// Assemble each part: include its content fields (computed absolute paths,
|
||||
// resolved against --root) and read scalar fields from <path>/element.toml.
|
||||
// `part-fields` (from cph-render) is the single source of truth for kind->fields.
|
||||
#let parts = raw-parts.map(raw => {
|
||||
let kind = raw.at("kind", default: none)
|
||||
let path = raw.at("path", default: none)
|
||||
let spec = part-fields.at(kind, default: (content: (), optional-content: (), scalars: ()))
|
||||
// Which optional content fields are present on disk (manifest-declared).
|
||||
let present = raw.at("fields", default: ())
|
||||
let part = (kind: kind)
|
||||
// Assemble each outline entry:
|
||||
// - an "element" entry: include its content fields (computed absolute paths,
|
||||
// resolved against --root) and read scalar fields from <path>/element.toml.
|
||||
// `part-fields` (from cph-render) is the single source of truth for
|
||||
// kind->fields.
|
||||
// - a "section" entry (ADR-0029): pass its title/depth straight through — no
|
||||
// content to load, it is a heading.
|
||||
#let outline = raw-outline.map(raw => {
|
||||
if raw.at("type", default: "element") == "section" {
|
||||
(
|
||||
entry-type: "section",
|
||||
kind: raw.at("kind", default: none),
|
||||
title: raw.at("title", default: ""),
|
||||
depth: raw.at("depth", default: 1),
|
||||
)
|
||||
} else {
|
||||
let kind = raw.at("kind", default: none)
|
||||
let path = raw.at("path", default: none)
|
||||
let spec = part-fields.at(kind, default: (content: (), optional-content: (), scalars: ()))
|
||||
// Which optional content fields are present on disk (manifest-declared).
|
||||
let present = raw.at("fields", default: ())
|
||||
let entry = (entry-type: "element", kind: kind)
|
||||
|
||||
// Required content fields: <path>/<field>.typ (absolute, root-relative).
|
||||
for field in spec.content {
|
||||
part.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
// Optional content fields: only when the manifest says the file exists.
|
||||
for field in spec.optional-content {
|
||||
if field in present {
|
||||
part.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
// Required content fields: <path>/<field>.typ (absolute, root-relative).
|
||||
for field in spec.content {
|
||||
entry.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
}
|
||||
// Scalar fields come from <path>/element.toml.
|
||||
if spec.scalars.len() > 0 {
|
||||
let element = toml("/" + path + "/element.toml")
|
||||
for field in spec.scalars {
|
||||
let v = element.at(field, default: none)
|
||||
if v != none and v != "" { part.insert(field, v) }
|
||||
// Optional content fields: only when the manifest says the file exists.
|
||||
for field in spec.optional-content {
|
||||
if field in present {
|
||||
entry.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
}
|
||||
// Scalar fields come from <path>/element.toml.
|
||||
if spec.scalars.len() > 0 {
|
||||
let element = toml("/" + path + "/element.toml")
|
||||
for field in spec.scalars {
|
||||
let v = element.at(field, default: none)
|
||||
if v != none and v != "" { entry.insert(field, v) }
|
||||
}
|
||||
}
|
||||
entry
|
||||
}
|
||||
part
|
||||
})
|
||||
|
||||
// Presentation: per-level heading numbering. Default (一、 / 1.1 / 1.1.1) comes
|
||||
@@ -74,6 +88,6 @@
|
||||
#render-lesson(
|
||||
info: info,
|
||||
target: target,
|
||||
parts: parts,
|
||||
outline: outline,
|
||||
heading-numbering: default-heading-numbering,
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// DEFAULT TEACHER TEMPLATE (framework default; ADR-0011).
|
||||
// DEFAULT TEACHER TEMPLATE (framework default; ADR-0011, outline shape ADR-0029).
|
||||
//
|
||||
// Lives in an engineering file at `exports/teacher.typ`. Compiled AS MAIN with
|
||||
// the manifest injected:
|
||||
@@ -18,38 +18,47 @@
|
||||
// Read the injected manifest (a path string relative to typst --root).
|
||||
#let manifest = toml(sys.inputs.manifest)
|
||||
#let info = manifest.at("info", default: (:))
|
||||
#let raw-parts = manifest.at("parts", default: ())
|
||||
#let raw-outline = manifest.at("outline", default: ())
|
||||
|
||||
// Assemble each part: include its content fields (computed absolute paths,
|
||||
// resolved against --root) and read scalar fields from <path>/element.toml.
|
||||
// `part-fields` (from cph-render) is the single source of truth for kind->fields.
|
||||
#let parts = raw-parts.map(raw => {
|
||||
let kind = raw.at("kind", default: none)
|
||||
let path = raw.at("path", default: none)
|
||||
let spec = part-fields.at(kind, default: (content: (), optional-content: (), scalars: ()))
|
||||
// Which optional content fields are present on disk (manifest-declared).
|
||||
let present = raw.at("fields", default: ())
|
||||
let part = (kind: kind)
|
||||
// Assemble each outline entry: an "element" entry includes its content fields
|
||||
// and reads scalars from element.toml; a "section" entry (ADR-0029) passes
|
||||
// title/depth straight through as a heading, no content to load.
|
||||
#let outline = raw-outline.map(raw => {
|
||||
if raw.at("type", default: "element") == "section" {
|
||||
(
|
||||
entry-type: "section",
|
||||
kind: raw.at("kind", default: none),
|
||||
title: raw.at("title", default: ""),
|
||||
depth: raw.at("depth", default: 1),
|
||||
)
|
||||
} else {
|
||||
let kind = raw.at("kind", default: none)
|
||||
let path = raw.at("path", default: none)
|
||||
let spec = part-fields.at(kind, default: (content: (), optional-content: (), scalars: ()))
|
||||
// Which optional content fields are present on disk (manifest-declared).
|
||||
let present = raw.at("fields", default: ())
|
||||
let entry = (entry-type: "element", kind: kind)
|
||||
|
||||
// Required content fields: <path>/<field>.typ (absolute, root-relative).
|
||||
for field in spec.content {
|
||||
part.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
// Optional content fields: only when the manifest says the file exists.
|
||||
for field in spec.optional-content {
|
||||
if field in present {
|
||||
part.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
// Required content fields: <path>/<field>.typ (absolute, root-relative).
|
||||
for field in spec.content {
|
||||
entry.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
}
|
||||
// Scalar fields come from <path>/element.toml.
|
||||
if spec.scalars.len() > 0 {
|
||||
let element = toml("/" + path + "/element.toml")
|
||||
for field in spec.scalars {
|
||||
let v = element.at(field, default: none)
|
||||
if v != none and v != "" { part.insert(field, v) }
|
||||
// Optional content fields: only when the manifest says the file exists.
|
||||
for field in spec.optional-content {
|
||||
if field in present {
|
||||
entry.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
}
|
||||
// Scalar fields come from <path>/element.toml.
|
||||
if spec.scalars.len() > 0 {
|
||||
let element = toml("/" + path + "/element.toml")
|
||||
for field in spec.scalars {
|
||||
let v = element.at(field, default: none)
|
||||
if v != none and v != "" { entry.insert(field, v) }
|
||||
}
|
||||
}
|
||||
entry
|
||||
}
|
||||
part
|
||||
})
|
||||
|
||||
// Presentation: per-level heading numbering. Default (一、 / 1.1 / 1.1.1) comes
|
||||
@@ -57,6 +66,6 @@
|
||||
#render-lesson(
|
||||
info: info,
|
||||
target: target,
|
||||
parts: parts,
|
||||
outline: outline,
|
||||
heading-numbering: default-heading-numbering,
|
||||
)
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
# Throwaway smoke engineering file for the cph-render template round (ADR-0011).
|
||||
# Exercises all 4 kinds + nested headings (per-level numbering) + an example with
|
||||
# a `source` scalar and one without + a lemma with proof and one without.
|
||||
# Throwaway smoke engineering file for the cph-render template round
|
||||
# (ADR-0011, outline shape ADR-0029). Exercises all 4 kinds + a section heading
|
||||
# + nested headings (per-level numbering) + an example with a `source` scalar
|
||||
# and one without + a lemma with proof and one without.
|
||||
#
|
||||
# The per-part `fields` array lists the content fields present ON DISK. The
|
||||
# template uses it to decide whether to load OPTIONAL content (lemma `proof`),
|
||||
# because typst has no file-exists primitive. (OPEN: the exact manifest shape for
|
||||
# declaring optional-field presence is for the Rust/manifest contract to pin.)
|
||||
# This file is compiled DIRECTLY via `typst compile --input manifest=/manifest.toml`
|
||||
# (see README below), bypassing the Rust engine's augmented-manifest builder
|
||||
# (`cph_typst::build_augmented_manifest`). So the `[[outline]]` shape here is
|
||||
# hand-authored to already be what that builder would produce: an ordered array
|
||||
# of `type = "element"` (kind, path, fields — the content fields present on
|
||||
# disk, since typst has no file-exists primitive) and `type = "section"`
|
||||
# (kind, title, depth) entries.
|
||||
|
||||
[project]
|
||||
id = "smoke-eng"
|
||||
@@ -15,38 +19,54 @@ name = "cph-render template smoke"
|
||||
title = "向量与几何 · 示例讲义"
|
||||
author = ["张老师", "李老师"]
|
||||
|
||||
# segment — nested headings exercise per-level numbering (一、 / 1.1 / 1.1.1).
|
||||
[[parts]]
|
||||
# segment — exercises per-level numbering (一、 / 1.1 / 1.1.1) alongside the
|
||||
# section heading below.
|
||||
[[outline]]
|
||||
type = "element"
|
||||
kind = "segment"
|
||||
path = "segments/向量数量积"
|
||||
fields = ["textbook"]
|
||||
|
||||
# A section heading (ADR-0029): opens depth-1, groups the two examples that
|
||||
# follow. Contributes no element to the sequence.
|
||||
[[outline]]
|
||||
type = "section"
|
||||
kind = "section"
|
||||
title = "数量积的坐标计算"
|
||||
depth = 1
|
||||
path = "examples"
|
||||
|
||||
# example WITH source scalar
|
||||
[[parts]]
|
||||
[[outline]]
|
||||
type = "element"
|
||||
kind = "example"
|
||||
path = "examples/坐标数量积"
|
||||
fields = ["problem", "solution"]
|
||||
|
||||
# example WITHOUT source scalar
|
||||
[[parts]]
|
||||
[[outline]]
|
||||
type = "element"
|
||||
kind = "example"
|
||||
path = "examples/求模长"
|
||||
fields = ["problem", "solution"]
|
||||
|
||||
# lemma WITH proof (proof.typ present on disk; declared in fields)
|
||||
[[parts]]
|
||||
[[outline]]
|
||||
type = "element"
|
||||
kind = "lemma"
|
||||
path = "lemmas/柯西不等式"
|
||||
fields = ["stmt", "proof"]
|
||||
|
||||
# lemma WITHOUT proof (proof.typ absent; fields omits it)
|
||||
[[parts]]
|
||||
[[outline]]
|
||||
type = "element"
|
||||
kind = "lemma"
|
||||
path = "lemmas/垂直判据"
|
||||
fields = ["stmt"]
|
||||
|
||||
# sop
|
||||
[[parts]]
|
||||
[[outline]]
|
||||
type = "element"
|
||||
kind = "sop"
|
||||
path = "sops/求夹角步骤"
|
||||
fields = ["sop"]
|
||||
|
||||
+110
-18
@@ -1,14 +1,14 @@
|
||||
// cph-render — curriculum lesson render package.
|
||||
//
|
||||
// PUBLIC ENTRY: `render-lesson(info, target, parts, heading-numbering)`.
|
||||
// PUBLIC ENTRY: `render-lesson(info, target, outline, heading-numbering)`.
|
||||
//
|
||||
// MODEL (ADR-0011). A build compiles a *template file* (e.g. `exports/student.typ`)
|
||||
// as the typst main, with the manifest injected via `--input manifest=<path>`.
|
||||
// The template reads the manifest, loads each part's content, and calls
|
||||
// `render-lesson` here. Presentation (heading numbering) lives in the template,
|
||||
// not the manifest, not hardcoded-unreachable in this package — we only provide
|
||||
// the DEFAULT scheme (`default-heading-numbering`) for the template to use or
|
||||
// override.
|
||||
// MODEL (ADR-0011, outline shape per ADR-0029). A build compiles a *template
|
||||
// file* (e.g. `exports/student.typ`) as the typst main, with the manifest
|
||||
// injected via `--input manifest=<path>`. The template reads the manifest,
|
||||
// loads each **element** entry's content, and calls `render-lesson` here.
|
||||
// Presentation (heading numbering) lives in the template, not the manifest,
|
||||
// not hardcoded-unreachable in this package — we only provide the DEFAULT
|
||||
// scheme (`default-heading-numbering`) for the template to use or override.
|
||||
//
|
||||
// WHY THE TEMPLATE LOADS CONTENT, NOT US (the include-resolution finding):
|
||||
// typst resolves an `include`/`import` path relative to THE PACKAGE/FILE THE
|
||||
@@ -19,11 +19,15 @@
|
||||
// Therefore the dynamic-include LOOP must live in the TEMPLATE (which lives at
|
||||
// `<root>/exports/*.typ`, so `/<part.path>/<field>.typ` resolves against
|
||||
// `--root`). `render-lesson` is content-in: it takes an ALREADY-ASSEMBLED
|
||||
// `parts` array of dicts and never includes anything itself.
|
||||
// `outline` array of entry dicts and never includes anything itself.
|
||||
//
|
||||
// A part dict the template hands us:
|
||||
// `kind` plus that kind's content/scalar fields. Content field VALUES are
|
||||
// already-evaluated typst content (the template produced them via `include`).
|
||||
// An `outline` entry the template hands us is one of:
|
||||
// - an ELEMENT: `entry-type: "element"`, `kind` plus that kind's
|
||||
// content/scalar fields. Content field VALUES are already-evaluated typst
|
||||
// content (the template produced them via `include`).
|
||||
// - a SECTION (ADR-0029): `entry-type: "section"`, `title` (heading text),
|
||||
// `depth` (1-based heading level). Contributes no element; it is a
|
||||
// heading at its depth-first-open position in the outline.
|
||||
//
|
||||
// kind -> fields (MVP) — see `part-fields` below, which the template uses to
|
||||
// know what to load:
|
||||
@@ -41,7 +45,6 @@
|
||||
// unknown : rendered conservatively == student (show only required-public
|
||||
// fields). Never crashes. The "no render rule => warning"
|
||||
// diagnostic is the Rust side's job, not ours.
|
||||
|
||||
#import "src/style.typ": base-style, default-heading-numbering, title-block, subtitle-block
|
||||
#import "src/elements/segment.typ": display-segment
|
||||
#import "src/elements/example.typ": display-example
|
||||
@@ -106,14 +109,33 @@
|
||||
}
|
||||
}
|
||||
|
||||
/// Render one section-heading outline entry (ADR-0029): `entry.title` at
|
||||
/// `entry.depth` (1-based heading level).
|
||||
#let _render-section(entry) = {
|
||||
heading(level: entry.at("depth", default: 1))[#entry.at("title", default: "")]
|
||||
}
|
||||
|
||||
/// Render one outline entry: an element dispatches on `kind` via
|
||||
/// [`_render-part`]; a section (ADR-0029) renders its heading and contributes
|
||||
/// no element.
|
||||
#let _render-entry(entry, flags) = {
|
||||
if entry.at("entry-type", default: "element") == "section" {
|
||||
_render-section(entry)
|
||||
} else {
|
||||
_render-part(entry, flags)
|
||||
}
|
||||
}
|
||||
|
||||
/// THE ENTRY POINT — called by a template (`exports/*.typ`).
|
||||
///
|
||||
/// - `info`: dict, e.g. (title: "…", author: "…"). `author` may be absent.
|
||||
/// Templates typically pass `manifest.at("info", default: (:))`.
|
||||
/// - `target`: string. MVP: "student" | "teacher". Unknown => conservative.
|
||||
/// Each template hardcodes its own target (student.typ => "student").
|
||||
/// - `parts`: ordered array of part dicts, ALREADY ASSEMBLED by the template
|
||||
/// (content fields included, scalars read). See file header.
|
||||
/// - `outline`: ordered array of outline-entry dicts (ADR-0029), ALREADY
|
||||
/// ASSEMBLED by the template (element content fields included,
|
||||
/// scalars read; section entries carry `title`/`depth`). See file
|
||||
/// header for the entry shapes.
|
||||
/// - `heading-numbering`: array of per-level numbly pattern strings, e.g.
|
||||
/// `("{1:一}、", "{1:1}.{2:1}", "{1:1}.{2:1}.{3:1}")`. Presentation
|
||||
/// lives in the template (ADR-0011); the template passes its chosen
|
||||
@@ -122,7 +144,7 @@
|
||||
#let render-lesson(
|
||||
info: (:),
|
||||
target: "student",
|
||||
parts: (),
|
||||
outline: (),
|
||||
heading-numbering: default-heading-numbering,
|
||||
) = {
|
||||
let title = info.at("title", default: [])
|
||||
@@ -146,7 +168,77 @@
|
||||
subtitle-block(flags.subtitle)
|
||||
|
||||
// Render strictly in array order.
|
||||
for part in parts {
|
||||
_render-part(part, flags)
|
||||
for entry in outline {
|
||||
_render-entry(entry, flags)
|
||||
}
|
||||
}
|
||||
|
||||
/// Shift a section entry's `depth` by `delta`; an element entry passes through
|
||||
/// unchanged (elements carry no depth). Used by [`render-bundle`] to nest each
|
||||
/// lesson's own outline one level under that lesson's title heading.
|
||||
#let _shift-depth(entry, delta) = {
|
||||
if entry.at("entry-type", default: "element") == "section" {
|
||||
entry.depth = entry.depth + delta
|
||||
}
|
||||
entry
|
||||
}
|
||||
|
||||
/// THE BUNDLE ENTRY POINT (ADR-0030) — called by a bundle target's template
|
||||
/// (`exports/<target>.typ` under a `bundle.toml` root) to assemble several
|
||||
/// already-loaded lessons into one combined document.
|
||||
///
|
||||
/// - `info`: the bundle's own `[info]` (title/author of the 合集).
|
||||
/// - `lessons`: ordered array of `(info: .., target: .., outline: ..)` dicts —
|
||||
/// one per `bundle.toml` `lessons` entry, each ALREADY ASSEMBLED exactly as
|
||||
/// a single-lesson template would assemble it for [`render-lesson`].
|
||||
/// - `heading-numbering`: shared per-level numbering scheme across the whole
|
||||
/// bundle (ADR-0011 presentation-in-template stance; same knob as
|
||||
/// `render-lesson`).
|
||||
/// - `reset-counters`: whether `example`/`lemma` auto-counters reset at each
|
||||
/// lesson boundary. **Default `true`** (ADR-0030's recommended default: a
|
||||
/// lesson's internal "例题3" means that lesson's 例题3, so cross-lesson
|
||||
/// continuation would silently break author references). Pass `false` for
|
||||
/// a genuine "全书连续编号" 合集.
|
||||
///
|
||||
/// Each lesson's own outline is rendered under a depth-1 heading naming that
|
||||
/// lesson (`lesson.info.title`); the lesson's own section headings shift one
|
||||
/// level deeper (ADR-0029's per-lesson depths are relative to that lesson, so
|
||||
/// nesting under the lesson-title heading keeps the outline↔structure
|
||||
/// correspondence meaningful in the combined document). `@label`/`@ref`
|
||||
/// cross-references stay global across the whole compiled document (typst's
|
||||
/// ordinary behavior) regardless of `reset-counters`.
|
||||
#let render-bundle(
|
||||
info: (:),
|
||||
lessons: (),
|
||||
heading-numbering: default-heading-numbering,
|
||||
reset-counters: true,
|
||||
) = {
|
||||
let title = info.at("title", default: [])
|
||||
let author = info.at("author", default: none)
|
||||
|
||||
set document(
|
||||
title: title,
|
||||
author: if author == none { () } else { author },
|
||||
)
|
||||
|
||||
show: base-style.with(heading-numbering: heading-numbering)
|
||||
|
||||
title-block()
|
||||
v(1.2em, weak: true)
|
||||
|
||||
for lesson in lessons {
|
||||
if reset-counters {
|
||||
example-counter.update(0)
|
||||
lemma-counter.update(0)
|
||||
}
|
||||
|
||||
let flags = _flags-for(lesson.at("target", default: "student"))
|
||||
let lesson-info = lesson.at("info", default: (:))
|
||||
|
||||
heading(level: 1)[#lesson-info.at("title", default: [])]
|
||||
|
||||
for entry in lesson.at("outline", default: ()) {
|
||||
_render-entry(_shift-depth(entry, 1), flags)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-11
@@ -1,4 +1,4 @@
|
||||
# Default export templates (ADR-0011)
|
||||
# Default export templates (ADR-0011, outline shape ADR-0029)
|
||||
|
||||
`student.typ` / `teacher.typ` are the **framework default templates**. In a real
|
||||
engineering file they live at `exports/student.typ` / `exports/teacher.typ`; the
|
||||
@@ -9,11 +9,16 @@ offline smoke test below.
|
||||
Each template:
|
||||
|
||||
1. reads the injected manifest: `toml(sys.inputs.manifest)`;
|
||||
2. loops `manifest.parts`, `include`-ing each content field via a computed
|
||||
**root-relative absolute** path `/<part.path>/<field>.typ`, and reading scalar
|
||||
fields (example `source`) from `/<part.path>/element.toml`;
|
||||
3. assembles a `parts` array and calls `cph-render`'s `render-lesson(...)`,
|
||||
passing the per-level heading numbering (presentation lives in the template).
|
||||
2. loops `manifest.outline` (ADR-0029's depth-first rendering order — elements
|
||||
interleaved with section headings at their DFS-open position). For an
|
||||
`type = "element"` entry: `include`-ing each content field via a computed
|
||||
**root-relative absolute** path `/<part.path>/<field>.typ`, and reading
|
||||
scalar fields (example `source`) from `/<part.path>/element.toml`. For a
|
||||
`type = "section"` entry: passing its `title`/`depth` straight through — no
|
||||
content to load, it is a heading;
|
||||
3. assembles an `outline` array of entry dicts and calls `cph-render`'s
|
||||
`render-lesson(...)`, passing the per-level heading numbering (presentation
|
||||
lives in the template).
|
||||
|
||||
## Why the include loop is in the template, not in cph-render
|
||||
|
||||
@@ -23,7 +28,7 @@ root**. A dynamic `include` written inside the package resolves against the
|
||||
*package* dir — even an absolute `/segments/x.typ` — never the engineering
|
||||
`--root`. Verified empirically. The template lives under `--root`, so its
|
||||
`/<part.path>/<field>.typ` resolves against `--root`. Hence the template loads
|
||||
content and hands `render-lesson` an already-assembled `parts` array;
|
||||
content and hands `render-lesson` an already-assembled `outline` array;
|
||||
`render-lesson` never includes anything.
|
||||
|
||||
## Key path facts for the engine
|
||||
@@ -36,9 +41,13 @@ content and hands `render-lesson` an already-assembled `parts` array;
|
||||
relative to the *template's* location (`exports/`), so a bare
|
||||
`manifest=manifest.toml` would look in `exports/`. Pass the leading `/`.
|
||||
- **Optional content presence** (lemma `proof`): typst has no file-exists
|
||||
primitive, so the template cannot probe disk. It reads a per-part `fields`
|
||||
array from the manifest listing the content fields present on disk. *(OPEN: the
|
||||
exact manifest shape for this is for the Rust/manifest contract to pin.)*
|
||||
primitive, so the template cannot probe disk. It reads a per-element
|
||||
`fields` array from the manifest listing the content fields present on
|
||||
disk. *(OPEN: the exact manifest shape for this is for the Rust/manifest
|
||||
contract to pin.)*
|
||||
- **Sections carry no content fields.** A `type = "section"` outline entry
|
||||
(ADR-0029) has only `kind`/`title`/`depth`/`path`; the template passes it
|
||||
through untouched — no `include`, no `element.toml` read.
|
||||
|
||||
## Offline smoke test
|
||||
|
||||
@@ -60,4 +69,7 @@ typst compile --root examples/smoke-eng \
|
||||
```
|
||||
|
||||
(`examples/smoke-eng/exports/{student,teacher}.typ` are copies of the defaults
|
||||
here, mirroring how a real engineering file carries its own templates.)
|
||||
here, mirroring how a real engineering file carries its own templates. The
|
||||
`examples/smoke-eng/manifest.toml` is hand-authored directly in the augmented
|
||||
`[[outline]]` shape that `cph_typst::build_augmented_manifest` would otherwise
|
||||
produce, since this smoke test bypasses the Rust engine entirely.)
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
// DEFAULT BUNDLE TEMPLATE (ADR-0030, outline shape ADR-0029).
|
||||
//
|
||||
// Lives in a bundle at `<bundle-root>/exports/<target>.typ`, e.g.
|
||||
// `exports/merged.typ`. Compiled AS MAIN with the augmented BUNDLE manifest
|
||||
// injected:
|
||||
// typst compile --root <bundle-root> --input manifest=<path-rel-to-root> exports/merged.typ <out>
|
||||
//
|
||||
// Structurally identical to the single-lesson `student.typ`/`teacher.typ`
|
||||
// templates (see their notes on why the include loop lives in the template,
|
||||
// not in cph-render), except it reads `manifest.lessons` (an ordered array of
|
||||
// per-lesson `(info, target, outline)` tables — see
|
||||
// `cph_typst::build_augmented_bundle_manifest`) instead of a single
|
||||
// `manifest.outline`, and calls `render-bundle` instead of `render-lesson`.
|
||||
//
|
||||
// Every outline entry's `path` in a bundle manifest is ALREADY prefixed with
|
||||
// that lesson's own bundle-root-relative directory (done by the Rust engine),
|
||||
// so the same `include "/" + path + "/" + field + ".typ"` computation used by
|
||||
// a single-lesson template resolves correctly here too — no special-casing
|
||||
// needed in this loop.
|
||||
|
||||
#import "@local/cph-render:0.1.0": render-bundle, part-fields, default-heading-numbering
|
||||
|
||||
#let manifest = toml(sys.inputs.manifest)
|
||||
#let info = manifest.at("info", default: (:))
|
||||
#let raw-lessons = manifest.at("lessons", default: ())
|
||||
|
||||
// Assemble one outline entry exactly as a single-lesson template would.
|
||||
#let assemble-entry(raw) = {
|
||||
if raw.at("type", default: "element") == "section" {
|
||||
(
|
||||
entry-type: "section",
|
||||
kind: raw.at("kind", default: none),
|
||||
title: raw.at("title", default: ""),
|
||||
depth: raw.at("depth", default: 1),
|
||||
)
|
||||
} else {
|
||||
let kind = raw.at("kind", default: none)
|
||||
let path = raw.at("path", default: none)
|
||||
let spec = part-fields.at(kind, default: (content: (), optional-content: (), scalars: ()))
|
||||
let present = raw.at("fields", default: ())
|
||||
let entry = (entry-type: "element", kind: kind)
|
||||
|
||||
for field in spec.content {
|
||||
entry.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
for field in spec.optional-content {
|
||||
if field in present {
|
||||
entry.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
}
|
||||
if spec.scalars.len() > 0 {
|
||||
let element = toml("/" + path + "/element.toml")
|
||||
for field in spec.scalars {
|
||||
let v = element.at(field, default: none)
|
||||
if v != none and v != "" { entry.insert(field, v) }
|
||||
}
|
||||
}
|
||||
entry
|
||||
}
|
||||
}
|
||||
|
||||
#let lessons = raw-lessons.map(raw => (
|
||||
info: raw.at("info", default: (:)),
|
||||
target: raw.at("target", default: "student"),
|
||||
outline: raw.at("outline", default: ()).map(assemble-entry),
|
||||
))
|
||||
|
||||
// Presentation: shared per-level heading numbering across the whole bundle,
|
||||
// and the ADR-0030 recommended default of resetting auto-counters at each
|
||||
// lesson boundary (override `reset-counters: false` for continuous numbering).
|
||||
#render-bundle(
|
||||
info: info,
|
||||
lessons: lessons,
|
||||
heading-numbering: default-heading-numbering,
|
||||
reset-counters: true,
|
||||
)
|
||||
@@ -1,4 +1,4 @@
|
||||
// DEFAULT STUDENT TEMPLATE (framework default; ADR-0011).
|
||||
// DEFAULT STUDENT TEMPLATE (framework default; ADR-0011, outline shape ADR-0029).
|
||||
//
|
||||
// This is a *real, editable* file that lives in an engineering file at
|
||||
// `exports/student.typ`. The framework compiles it AS THE MAIN FILE with the
|
||||
@@ -15,15 +15,16 @@
|
||||
// its own virtual root — an include inside cph-render would resolve against the
|
||||
// PACKAGE, not the engineering root. A `/<part.path>/<field>.typ` written HERE
|
||||
// (this template lives under `--root`) resolves against `--root`. So the
|
||||
// template loads content and hands cph-render an already-assembled `parts` array.
|
||||
// template loads content and hands cph-render an already-assembled `outline`
|
||||
// array (elements interleaved with section headings, ADR-0029).
|
||||
//
|
||||
// OPEN CONTRACT POINT — optional-content presence. typst has no "does this file
|
||||
// exist" primitive (a missing `include` is a hard compile error). So the
|
||||
// template CANNOT probe disk the way the old Rust driver did for lemma `proof`.
|
||||
// It relies on the manifest declaring which optional content fields are present,
|
||||
// via a per-part `fields` array listing the content fields that exist on disk
|
||||
// via a per-element `fields` array listing the content fields that exist on disk
|
||||
// (the engine knows this — it walks the part dir). Required fields are loaded
|
||||
// unconditionally; optional fields load only if listed in `fields`. If a part
|
||||
// unconditionally; optional fields load only if listed in `fields`. If an element
|
||||
// omits `fields`, optional content is skipped (conservative). The exact shape of
|
||||
// this declaration is for the manifest/Rust contract to pin.
|
||||
|
||||
@@ -35,38 +36,51 @@
|
||||
// Read the injected manifest (a path string relative to typst --root).
|
||||
#let manifest = toml(sys.inputs.manifest)
|
||||
#let info = manifest.at("info", default: (:))
|
||||
#let raw-parts = manifest.at("parts", default: ())
|
||||
#let raw-outline = manifest.at("outline", default: ())
|
||||
|
||||
// Assemble each part: include its content fields (computed absolute paths,
|
||||
// resolved against --root) and read scalar fields from <path>/element.toml.
|
||||
// `part-fields` (from cph-render) is the single source of truth for kind->fields.
|
||||
#let parts = raw-parts.map(raw => {
|
||||
let kind = raw.at("kind", default: none)
|
||||
let path = raw.at("path", default: none)
|
||||
let spec = part-fields.at(kind, default: (content: (), optional-content: (), scalars: ()))
|
||||
// Which optional content fields are present on disk (manifest-declared).
|
||||
let present = raw.at("fields", default: ())
|
||||
let part = (kind: kind)
|
||||
// Assemble each outline entry:
|
||||
// - an "element" entry: include its content fields (computed absolute paths,
|
||||
// resolved against --root) and read scalar fields from <path>/element.toml.
|
||||
// `part-fields` (from cph-render) is the single source of truth for
|
||||
// kind->fields.
|
||||
// - a "section" entry (ADR-0029): pass its title/depth straight through — no
|
||||
// content to load, it is a heading.
|
||||
#let outline = raw-outline.map(raw => {
|
||||
if raw.at("type", default: "element") == "section" {
|
||||
(
|
||||
entry-type: "section",
|
||||
kind: raw.at("kind", default: none),
|
||||
title: raw.at("title", default: ""),
|
||||
depth: raw.at("depth", default: 1),
|
||||
)
|
||||
} else {
|
||||
let kind = raw.at("kind", default: none)
|
||||
let path = raw.at("path", default: none)
|
||||
let spec = part-fields.at(kind, default: (content: (), optional-content: (), scalars: ()))
|
||||
// Which optional content fields are present on disk (manifest-declared).
|
||||
let present = raw.at("fields", default: ())
|
||||
let entry = (entry-type: "element", kind: kind)
|
||||
|
||||
// Required content fields: <path>/<field>.typ (absolute, root-relative).
|
||||
for field in spec.content {
|
||||
part.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
// Optional content fields: only when the manifest says the file exists.
|
||||
for field in spec.optional-content {
|
||||
if field in present {
|
||||
part.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
// Required content fields: <path>/<field>.typ (absolute, root-relative).
|
||||
for field in spec.content {
|
||||
entry.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
}
|
||||
// Scalar fields come from <path>/element.toml.
|
||||
if spec.scalars.len() > 0 {
|
||||
let element = toml("/" + path + "/element.toml")
|
||||
for field in spec.scalars {
|
||||
let v = element.at(field, default: none)
|
||||
if v != none and v != "" { part.insert(field, v) }
|
||||
// Optional content fields: only when the manifest says the file exists.
|
||||
for field in spec.optional-content {
|
||||
if field in present {
|
||||
entry.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
}
|
||||
// Scalar fields come from <path>/element.toml.
|
||||
if spec.scalars.len() > 0 {
|
||||
let element = toml("/" + path + "/element.toml")
|
||||
for field in spec.scalars {
|
||||
let v = element.at(field, default: none)
|
||||
if v != none and v != "" { entry.insert(field, v) }
|
||||
}
|
||||
}
|
||||
entry
|
||||
}
|
||||
part
|
||||
})
|
||||
|
||||
// Presentation: per-level heading numbering. Default (一、 / 1.1 / 1.1.1) comes
|
||||
@@ -74,6 +88,6 @@
|
||||
#render-lesson(
|
||||
info: info,
|
||||
target: target,
|
||||
parts: parts,
|
||||
outline: outline,
|
||||
heading-numbering: default-heading-numbering,
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// DEFAULT TEACHER TEMPLATE (framework default; ADR-0011).
|
||||
// DEFAULT TEACHER TEMPLATE (framework default; ADR-0011, outline shape ADR-0029).
|
||||
//
|
||||
// Lives in an engineering file at `exports/teacher.typ`. Compiled AS MAIN with
|
||||
// the manifest injected:
|
||||
@@ -18,38 +18,47 @@
|
||||
// Read the injected manifest (a path string relative to typst --root).
|
||||
#let manifest = toml(sys.inputs.manifest)
|
||||
#let info = manifest.at("info", default: (:))
|
||||
#let raw-parts = manifest.at("parts", default: ())
|
||||
#let raw-outline = manifest.at("outline", default: ())
|
||||
|
||||
// Assemble each part: include its content fields (computed absolute paths,
|
||||
// resolved against --root) and read scalar fields from <path>/element.toml.
|
||||
// `part-fields` (from cph-render) is the single source of truth for kind->fields.
|
||||
#let parts = raw-parts.map(raw => {
|
||||
let kind = raw.at("kind", default: none)
|
||||
let path = raw.at("path", default: none)
|
||||
let spec = part-fields.at(kind, default: (content: (), optional-content: (), scalars: ()))
|
||||
// Which optional content fields are present on disk (manifest-declared).
|
||||
let present = raw.at("fields", default: ())
|
||||
let part = (kind: kind)
|
||||
// Assemble each outline entry: an "element" entry includes its content fields
|
||||
// and reads scalars from element.toml; a "section" entry (ADR-0029) passes
|
||||
// title/depth straight through as a heading, no content to load.
|
||||
#let outline = raw-outline.map(raw => {
|
||||
if raw.at("type", default: "element") == "section" {
|
||||
(
|
||||
entry-type: "section",
|
||||
kind: raw.at("kind", default: none),
|
||||
title: raw.at("title", default: ""),
|
||||
depth: raw.at("depth", default: 1),
|
||||
)
|
||||
} else {
|
||||
let kind = raw.at("kind", default: none)
|
||||
let path = raw.at("path", default: none)
|
||||
let spec = part-fields.at(kind, default: (content: (), optional-content: (), scalars: ()))
|
||||
// Which optional content fields are present on disk (manifest-declared).
|
||||
let present = raw.at("fields", default: ())
|
||||
let entry = (entry-type: "element", kind: kind)
|
||||
|
||||
// Required content fields: <path>/<field>.typ (absolute, root-relative).
|
||||
for field in spec.content {
|
||||
part.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
// Optional content fields: only when the manifest says the file exists.
|
||||
for field in spec.optional-content {
|
||||
if field in present {
|
||||
part.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
// Required content fields: <path>/<field>.typ (absolute, root-relative).
|
||||
for field in spec.content {
|
||||
entry.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
}
|
||||
// Scalar fields come from <path>/element.toml.
|
||||
if spec.scalars.len() > 0 {
|
||||
let element = toml("/" + path + "/element.toml")
|
||||
for field in spec.scalars {
|
||||
let v = element.at(field, default: none)
|
||||
if v != none and v != "" { part.insert(field, v) }
|
||||
// Optional content fields: only when the manifest says the file exists.
|
||||
for field in spec.optional-content {
|
||||
if field in present {
|
||||
entry.insert(field, include "/" + path + "/" + field + ".typ")
|
||||
}
|
||||
}
|
||||
// Scalar fields come from <path>/element.toml.
|
||||
if spec.scalars.len() > 0 {
|
||||
let element = toml("/" + path + "/element.toml")
|
||||
for field in spec.scalars {
|
||||
let v = element.at(field, default: none)
|
||||
if v != none and v != "" { entry.insert(field, v) }
|
||||
}
|
||||
}
|
||||
entry
|
||||
}
|
||||
part
|
||||
})
|
||||
|
||||
// Presentation: per-level heading numbering. Default (一、 / 1.1 / 1.1.1) comes
|
||||
@@ -57,6 +66,6 @@
|
||||
#render-lesson(
|
||||
info: info,
|
||||
target: target,
|
||||
parts: parts,
|
||||
outline: outline,
|
||||
heading-numbering: default-heading-numbering,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user