forked from EduCraft/curriculum-project-hub
feat(checker): cph-typst — embed typst 0.15, driver-gen, compile, PDF (WU-4)
The heart of the pipeline. Embeds the typst 0.15 compiler as a library to compile-check a lesson and export a PDF, with diagnostics mapped back to source spans (the product's value). - LessonWorld: a typst World over the engineering-file directory tree. vpath = real relative path (ADR-0007); the per-target driver is mounted in-memory as `main` (.cph/driver-<target>.typ, never written to disk); @local/cph-render is resolved from render_dir (CPH_RENDER_DIR / with_render_dir), no package install or network. Fonts via typst-kit FontStore (system CJK). - Driver generation: from the manifest, per target — static root-relative `include` of each content file (⇒ module body content, ADR-0006), assembled into the frozen `display(info, target, parts)` call; optional lemma proof emitted only if proof.typ exists; example `source` scalar threaded through. - Diagnostics: typst SourceDiagnostic (errors + warnings) → cph_diag::Diagnostic. 0.15 DiagSpan handled via span.id() + WorldExt::range → file-relative SourceSpan with 1-based line/col; driver-internal spans re-pointed with a "generated driver" hint, never dropped. typst hints/trace carried through. - Engine API: new / with_render_dir / compile_check / build_pdf. - 6 tests incl. build_pdf_with_real_render — full World→driver→cph-render→PDF producing real PDF-1.7 output (student 42KB / teacher 54KB). clippy/fmt clean. Also fixes render/typst.toml `compiler = ">=0.15.0"` → `"0.15.0"`: typst 0.15's manifest parser rejects a `>=` comparator on the compiler field (the 0.14 CLU WU-2 tested against was lenient). This unblocks loading the real render package. Pinned: typst/typst-pdf/typst-syntax/typst-library/typst-layout/typst-kit =0.15.0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
kind = "example"
|
||||
source = "自拟"
|
||||
@@ -0,0 +1 @@
|
||||
一物体从静止自由下落,求下落时间 $t$ 后的速度 $v$ 与位移 $h$。
|
||||
@@ -0,0 +1 @@
|
||||
由匀加速运动公式,$v = g t$,$h = 1/2 g t^2$。代入 $g approx 9.8 "m/s"^2$ 即得数值结果。
|
||||
@@ -0,0 +1 @@
|
||||
kind = "lemma"
|
||||
@@ -0,0 +1,3 @@
|
||||
设 $T = l^a g^b$。量纲为 $[T] = "T"$,$[l] = "L"$,$[g] = "L T"^(-2)$。
|
||||
比较两端得 $a + b = 0$ 与 $-2 b = 1$,解得 $a = 1 slash 2$,$b = -1 slash 2$,
|
||||
故 $T prop sqrt(l slash g)$。$qed$
|
||||
@@ -0,0 +1,3 @@
|
||||
设单摆周期 $T$ 仅依赖摆长 $l$ 与重力加速度 $g$,则由量纲分析必有
|
||||
$ T = k sqrt(l / g) $
|
||||
其中 $k$ 为无量纲常数。
|
||||
@@ -0,0 +1,23 @@
|
||||
[project]
|
||||
id = "mini"
|
||||
name = "迷你课时"
|
||||
|
||||
[info]
|
||||
title = "迷你示例课时"
|
||||
author = "测试作者"
|
||||
|
||||
[[parts]]
|
||||
kind = "segment"
|
||||
path = "segments/开场对照导言"
|
||||
|
||||
[[parts]]
|
||||
kind = "lemma"
|
||||
path = "lemmas/量纲分析估计"
|
||||
|
||||
[[parts]]
|
||||
kind = "example"
|
||||
path = "examples/自由落体"
|
||||
|
||||
[targets.student]
|
||||
|
||||
[targets.teacher]
|
||||
@@ -0,0 +1 @@
|
||||
kind = "segment"
|
||||
@@ -0,0 +1,2 @@
|
||||
本节通过对照两种估计方法,引入量纲分析这一工具。我们先回顾自由落体,
|
||||
其中能量与质量的关系可写作 $E = m c^2$(此处仅作记号示例)。
|
||||
@@ -0,0 +1,29 @@
|
||||
// Minimal stand-in for the real `cph-render` package, used so cph-typst's
|
||||
// World / compile / PDF path can be proven independently of WU-2.
|
||||
//
|
||||
// It exercises the same call shape as the real entry: it reads `info`, walks
|
||||
// `parts` IN ORDER, and renders each part's content fields by `kind`. Content
|
||||
// values are already-evaluated content (the driver produced them via include).
|
||||
#let display(info: (:), target: "student", parts: ()) = {
|
||||
set document(title: info.at("title", default: ""))
|
||||
[= #info.at("title", default: "")]
|
||||
[target: #target]
|
||||
for p in parts {
|
||||
let kind = p.at("kind", default: none)
|
||||
[== #kind]
|
||||
if kind == "segment" {
|
||||
p.textbook
|
||||
} else if kind == "lemma" {
|
||||
p.stmt
|
||||
let proof = p.at("proof", default: none)
|
||||
if proof != none { proof }
|
||||
} else if kind == "example" {
|
||||
p.problem
|
||||
p.solution
|
||||
let src = p.at("source", default: none)
|
||||
if src != none [来源:#src]
|
||||
} else if kind == "sop" {
|
||||
p.sop
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "cph-render"
|
||||
version = "0.1.0"
|
||||
entrypoint = "lib.typ"
|
||||
authors = ["cph-typst tests"]
|
||||
license = "MIT"
|
||||
description = "Minimal stand-in for cph-render used by cph-typst tests."
|
||||
Reference in New Issue
Block a user