forked from bai/curriculum-project-hub
feat(render): export templates + render-lesson entry; template owns include loop (WU-C', ADR-0011)
Replace the display(parts) entry (which a generated driver called) with the
template model: real editable templates (render/templates/{student,teacher}.typ,
the framework defaults copied into an engineering file's exports/) read the
manifest via toml(sys.inputs.manifest) and assemble parts themselves.
Key finding (drives the engine): a dynamic `include` inside a package resolves
against the PACKAGE root, never --root — so the include loop must live in the
TEMPLATE (which sits under --root): `include "/" + part.path + "/" + field +
".typ"` (root-relative absolute, runtime-computed — legal per ADR-0011's verified
fact). cph-render exposes render-lesson(info, target, parts, heading-numbering)
(content-in, never includes) + part-fields (kind→fields) + default-heading-numbering.
Numbering (numbly per-level) is set in the template, editable per engineering file.
Surfaced OPEN point closed by the engine (WU-D'): typst has no file-exists
primitive, so optional content (lemma proof) presence comes from a per-part
`fields` array the engine computes from disk. Manifest injected as root-relative
absolute (--input manifest=/...). numbly stays vendored/offline. display removed.
local-packages symlink (test-only @local resolution) gitignored — regenerable,
self-referential; the embedded engine mounts cph-render directly.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
// Smoke test — exercises the per-target presentation `config` override path
|
||||
// (ADR-0009). Here the engineering-file-supplied `config.numbering.heading`
|
||||
// overrides the framework-default heading numbering. The patterns happen to
|
||||
// match the correct per-level scheme (level-1 `一、`, level-2 `1.1`), proving
|
||||
// the override is wired AND yields correct (NOT `二、一、`) output.
|
||||
#import "../lib.typ": display
|
||||
#import "smoke-parts.typ": info, parts
|
||||
|
||||
#display(
|
||||
info: info,
|
||||
target: "teacher",
|
||||
parts: parts,
|
||||
config: (numbering: (heading: ("{1:一}、", "{1:1}.{2:1}"))),
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
source = "2024 高考甲卷"
|
||||
@@ -0,0 +1 @@
|
||||
已知 $arrow(a) = (1, 2)$,$arrow(b) = (3, -1)$,求 $arrow(a) dot arrow(b)$。
|
||||
@@ -0,0 +1 @@
|
||||
由坐标公式,$arrow(a) dot arrow(b) = 1 times 3 + 2 times (-1) = 3 - 2 = 1$。
|
||||
@@ -0,0 +1 @@
|
||||
# no source scalar — exercises the absent-scalar path
|
||||
@@ -0,0 +1 @@
|
||||
求向量 $arrow(a) = (3, 4)$ 的模长 $|arrow(a)|$。
|
||||
@@ -0,0 +1 @@
|
||||
$|arrow(a)| = sqrt(3^2 + 4^2) = sqrt(25) = 5$。
|
||||
@@ -0,0 +1,79 @@
|
||||
// DEFAULT STUDENT TEMPLATE (framework default; ADR-0011).
|
||||
//
|
||||
// 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
|
||||
// manifest injected:
|
||||
// typst compile --root <eng-root> --input manifest=<path-rel-to-root> exports/student.typ <out>
|
||||
//
|
||||
// It is intentionally self-contained (no shared helper import) so it can be
|
||||
// copied verbatim into a new engineering file's `exports/`. Presentation —
|
||||
// heading numbering — lives HERE (editable per engineering file), not in the
|
||||
// manifest and not hardcoded in the cph-render package.
|
||||
//
|
||||
// WHY THE INCLUDE LOOP IS HERE AND NOT IN cph-render: typst resolves a dynamic
|
||||
// `include` path relative to the file it lexically appears in, and a package has
|
||||
// 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.
|
||||
//
|
||||
// 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
|
||||
// (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
|
||||
// omits `fields`, optional content is skipped (conservative). The exact shape of
|
||||
// this declaration is for the manifest/Rust contract to pin.
|
||||
|
||||
#import "@local/cph-render:0.1.0": render-lesson, part-fields, default-heading-numbering
|
||||
|
||||
// This template IS the student build, so the target is fixed.
|
||||
#let target = "student"
|
||||
|
||||
// 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: ())
|
||||
|
||||
// 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)
|
||||
|
||||
// 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")
|
||||
}
|
||||
}
|
||||
// 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) }
|
||||
}
|
||||
}
|
||||
part
|
||||
})
|
||||
|
||||
// Presentation: per-level heading numbering. Default (一、 / 1.1 / 1.1.1) comes
|
||||
// from cph-render; override here per engineering file if desired.
|
||||
#render-lesson(
|
||||
info: info,
|
||||
target: target,
|
||||
parts: parts,
|
||||
heading-numbering: default-heading-numbering,
|
||||
)
|
||||
@@ -0,0 +1,62 @@
|
||||
// DEFAULT TEACHER TEMPLATE (framework default; ADR-0011).
|
||||
//
|
||||
// Lives in an engineering file at `exports/teacher.typ`. Compiled AS MAIN with
|
||||
// the manifest injected:
|
||||
// typst compile --root <eng-root> --input manifest=<path-rel-to-root> exports/teacher.typ <out>
|
||||
//
|
||||
// Self-contained (copyable into an engineering file). Identical to student.typ
|
||||
// except the fixed target is "teacher" (so the (kind x target) render matrix in
|
||||
// cph-render shows solutions and proofs). See student.typ for the full notes on
|
||||
// why the include loop lives here (package virtual-root resolution) and on the
|
||||
// OPEN optional-content (`fields`) contract point.
|
||||
|
||||
#import "@local/cph-render:0.1.0": render-lesson, part-fields, default-heading-numbering
|
||||
|
||||
// This template IS the teacher build, so the target is fixed.
|
||||
#let target = "teacher"
|
||||
|
||||
// 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: ())
|
||||
|
||||
// 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)
|
||||
|
||||
// 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")
|
||||
}
|
||||
}
|
||||
// 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) }
|
||||
}
|
||||
}
|
||||
part
|
||||
})
|
||||
|
||||
// Presentation: per-level heading numbering. Default (一、 / 1.1 / 1.1.1) comes
|
||||
// from cph-render; override here per engineering file if desired.
|
||||
#render-lesson(
|
||||
info: info,
|
||||
target: target,
|
||||
parts: parts,
|
||||
heading-numbering: default-heading-numbering,
|
||||
)
|
||||
@@ -0,0 +1 @@
|
||||
# lemma WITHOUT proof — proof.typ is absent on disk; manifest omits it from fields
|
||||
@@ -0,0 +1 @@
|
||||
两个非零向量垂直当且仅当其数量积为零,即 $arrow(a) perp arrow(b) <==> arrow(a) dot arrow(b) = 0$。
|
||||
@@ -0,0 +1 @@
|
||||
# lemma scalars: none
|
||||
@@ -0,0 +1,3 @@
|
||||
由数量积定义 $arrow(a) dot arrow(b) = |arrow(a)| |arrow(b)| cos theta$,
|
||||
又 $|cos theta| <= 1$,故 $|arrow(a) dot arrow(b)| = |arrow(a)| |arrow(b)| |cos theta| <= |arrow(a)| |arrow(b)|$。
|
||||
$qed$
|
||||
@@ -0,0 +1 @@
|
||||
对任意向量 $arrow(a)$、$arrow(b)$,有 $|arrow(a) dot arrow(b)| <= |arrow(a)| |arrow(b)|$。
|
||||
@@ -0,0 +1,64 @@
|
||||
# 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.
|
||||
#
|
||||
# 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.)
|
||||
|
||||
[project]
|
||||
id = "smoke-eng"
|
||||
name = "cph-render template smoke"
|
||||
|
||||
[info]
|
||||
title = "向量与几何 · 示例讲义"
|
||||
author = ["张老师", "李老师"]
|
||||
|
||||
# segment — nested headings exercise per-level numbering (一、 / 1.1 / 1.1.1).
|
||||
[[parts]]
|
||||
kind = "segment"
|
||||
path = "segments/向量数量积"
|
||||
fields = ["textbook"]
|
||||
|
||||
# example WITH source scalar
|
||||
[[parts]]
|
||||
kind = "example"
|
||||
path = "examples/坐标数量积"
|
||||
fields = ["problem", "solution"]
|
||||
|
||||
# example WITHOUT source scalar
|
||||
[[parts]]
|
||||
kind = "example"
|
||||
path = "examples/求模长"
|
||||
fields = ["problem", "solution"]
|
||||
|
||||
# lemma WITH proof (proof.typ present on disk; declared in fields)
|
||||
[[parts]]
|
||||
kind = "lemma"
|
||||
path = "lemmas/柯西不等式"
|
||||
fields = ["stmt", "proof"]
|
||||
|
||||
# lemma WITHOUT proof (proof.typ absent; fields omits it)
|
||||
[[parts]]
|
||||
kind = "lemma"
|
||||
path = "lemmas/垂直判据"
|
||||
fields = ["stmt"]
|
||||
|
||||
# sop
|
||||
[[parts]]
|
||||
kind = "sop"
|
||||
path = "sops/求夹角步骤"
|
||||
fields = ["sop"]
|
||||
|
||||
[targets.student]
|
||||
artifact = "single-file"
|
||||
[[targets.student.steps]]
|
||||
type = "typst-compile"
|
||||
template = "exports/student.typ"
|
||||
|
||||
[targets.teacher]
|
||||
artifact = "single-file"
|
||||
[[targets.teacher.steps]]
|
||||
type = "typst-compile"
|
||||
template = "exports/teacher.typ"
|
||||
@@ -0,0 +1,14 @@
|
||||
= 平面向量的数量积
|
||||
|
||||
本节研究平面向量的基本运算。设 $arrow(a)$、$arrow(b)$ 为平面内两个向量,
|
||||
其数量积定义为 $arrow(a) dot arrow(b) = |arrow(a)| |arrow(b)| cos theta$,
|
||||
其中 $theta$ 为两向量的夹角。
|
||||
|
||||
== 坐标表示
|
||||
|
||||
在直角坐标系下,若 $arrow(a) = (x_1, y_1)$、$arrow(b) = (x_2, y_2)$,则
|
||||
$arrow(a) dot arrow(b) = x_1 x_2 + y_1 y_2$。
|
||||
|
||||
== 几何意义
|
||||
|
||||
数量积等于一个向量的模与另一向量在其方向上投影之积。
|
||||
@@ -0,0 +1 @@
|
||||
# sop scalars: none
|
||||
@@ -0,0 +1,4 @@
|
||||
求两向量夹角的标准步骤:
|
||||
+ 计算数量积 $arrow(a) dot arrow(b)$;
|
||||
+ 分别计算模长 $|arrow(a)|$、$|arrow(b)|$;
|
||||
+ 代入 $cos theta = (arrow(a) dot arrow(b)) / (|arrow(a)| |arrow(b)|)$ 求出 $theta$。
|
||||
@@ -1,83 +0,0 @@
|
||||
// Shared hand-written sample lesson exercising all 4 kinds.
|
||||
// Content field values are plain content blocks — exactly what the Rust driver
|
||||
// would hand us via `include`.
|
||||
|
||||
#let info = (
|
||||
title: "向量与几何 · 示例讲义",
|
||||
author: ("张老师", "李老师"),
|
||||
)
|
||||
|
||||
#let parts = (
|
||||
// segment — with NESTED headings so per-level numbering is visible:
|
||||
// level-1 `=` should render `一、`, level-2 `==` should render `1.1`
|
||||
// (NOT the old buggy `二、一、`).
|
||||
(
|
||||
kind: "segment",
|
||||
textbook: [
|
||||
= 平面向量的数量积
|
||||
|
||||
本节研究平面向量的基本运算。设 $arrow(a)$、$arrow(b)$ 为平面内两个向量,
|
||||
其数量积定义为 $arrow(a) dot arrow(b) = |arrow(a)| |arrow(b)| cos theta$,
|
||||
其中 $theta$ 为两向量的夹角。
|
||||
|
||||
== 坐标表示
|
||||
|
||||
在直角坐标系下,若 $arrow(a) = (x_1, y_1)$、$arrow(b) = (x_2, y_2)$,则
|
||||
$arrow(a) dot arrow(b) = x_1 x_2 + y_1 y_2$。
|
||||
|
||||
== 几何意义
|
||||
|
||||
数量积等于一个向量的模与另一向量在其方向上投影之积。
|
||||
],
|
||||
),
|
||||
// example WITH source
|
||||
(
|
||||
kind: "example",
|
||||
source: "2024 高考甲卷",
|
||||
problem: [
|
||||
已知 $arrow(a) = (1, 2)$,$arrow(b) = (3, -1)$,求 $arrow(a) dot arrow(b)$。
|
||||
],
|
||||
solution: [
|
||||
由坐标公式,$arrow(a) dot arrow(b) = 1 times 3 + 2 times (-1) = 3 - 2 = 1$。
|
||||
],
|
||||
),
|
||||
// example WITHOUT source
|
||||
(
|
||||
kind: "example",
|
||||
problem: [
|
||||
求向量 $arrow(a) = (3, 4)$ 的模长 $|arrow(a)|$。
|
||||
],
|
||||
solution: [
|
||||
$|arrow(a)| = sqrt(3^2 + 4^2) = sqrt(25) = 5$。
|
||||
],
|
||||
),
|
||||
// lemma WITH proof
|
||||
(
|
||||
kind: "lemma",
|
||||
stmt: [
|
||||
对任意向量 $arrow(a)$、$arrow(b)$,有 $|arrow(a) dot arrow(b)| <= |arrow(a)| |arrow(b)|$。
|
||||
],
|
||||
proof: [
|
||||
由数量积定义 $arrow(a) dot arrow(b) = |arrow(a)| |arrow(b)| cos theta$,
|
||||
又 $|cos theta| <= 1$,故 $|arrow(a) dot arrow(b)| = |arrow(a)| |arrow(b)| |cos theta| <= |arrow(a)| |arrow(b)|$。
|
||||
$qed$
|
||||
],
|
||||
),
|
||||
// lemma WITHOUT proof (proof key omitted entirely)
|
||||
(
|
||||
kind: "lemma",
|
||||
stmt: [
|
||||
两个非零向量垂直当且仅当其数量积为零,即 $arrow(a) perp arrow(b) <==> arrow(a) dot arrow(b) = 0$。
|
||||
],
|
||||
),
|
||||
// sop
|
||||
(
|
||||
kind: "sop",
|
||||
sop: [
|
||||
求两向量夹角的标准步骤:
|
||||
+ 计算数量积 $arrow(a) dot arrow(b)$;
|
||||
+ 分别计算模长 $|arrow(a)|$、$|arrow(b)|$;
|
||||
+ 代入 $cos theta = (arrow(a) dot arrow(b)) / (|arrow(a)| |arrow(b)|)$ 求出 $theta$。
|
||||
],
|
||||
),
|
||||
)
|
||||
@@ -1,6 +0,0 @@
|
||||
// Smoke test — student target. Imports the package by RELATIVE path so it
|
||||
// compiles in place (no @local install needed).
|
||||
#import "../lib.typ": display
|
||||
#import "smoke-parts.typ": info, parts
|
||||
|
||||
#display(info: info, target: "student", parts: parts)
|
||||
@@ -1,5 +0,0 @@
|
||||
// Smoke test — teacher target. Imports the package by RELATIVE path.
|
||||
#import "../lib.typ": display
|
||||
#import "smoke-parts.typ": info, parts
|
||||
|
||||
#display(info: info, target: "teacher", parts: parts)
|
||||
Reference in New Issue
Block a user