From aaeefaed6b3bf62a847e1dbf2b6115f01be5148e Mon Sep 17 00:00:00 2001 From: Passthem Date: Wed, 8 Apr 2026 14:02:22 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E6=B7=BB=E5=8A=A0=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=88=B0=E4=BB=93=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/gen_index.py | 2 +- templates/lib.typ | 91 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 templates/lib.typ diff --git a/scripts/gen_index.py b/scripts/gen_index.py index 34d6c9a..12e1a1e 100644 --- a/scripts/gen_index.py +++ b/scripts/gen_index.py @@ -52,7 +52,7 @@ def indent_text(text: str, indent: int = 2) -> str: def generate_index(questions: list[dict], dry_run: bool, logger) -> str: """Generate index.typ content.""" lines = [ - '#import "@local/phomework:0.1.0": homework, question, answer, shadow', + '#import "./templates/lib.typ": homework, question, answer, shadow', "", ] diff --git a/templates/lib.typ b/templates/lib.typ new file mode 100644 index 0000000..bbb7248 --- /dev/null +++ b/templates/lib.typ @@ -0,0 +1,91 @@ +#import "@preview/cmarker:0.1.8" +#import "@preview/mitex:0.2.6": mitex +#import "@preview/codly:1.3.0": * +#import "@preview/codly-languages:0.1.1": * + +#let shadow_switch = state("phomework.shadow.enabled", true) + +/// =========== +/// 问题排版 +/// =========== + +// 直接文本定义的问题,适合复杂的图标 +#let question(content, title: "问题") = [ + #v(1em) + #grid( + columns: (auto, auto), + align: top, + gutter: .2em, + rect(fill: rgb("#776cad"), width: 4.5em)[ + #set text(fill: rgb("#ffffff"), font: "Source Han Serif", weight: "bold") + #set align(center) + + #title + ], + rect(stroke: none, width: 100%)[ + #set text(font: "Source Han Serif", fill: rgb("#3e3978")) + #set table(stroke: (paint: rgb("#3e3978")), inset: (y: 6pt, x: 9pt)) +#show table: t => align(center, t) + + #content + ] + ) +] + +#let answer(content) = [ + #set par(first-line-indent: (amount: 2em, all: true)) + #content +] + +#let shadow(content) = context { + set text(fill: gray) + + if (shadow_switch.get()) { + cmarker.render(content, math: mitex) + } +} + +#let homework( + title: "", + secret: "", + enable_shadow: true, + body +) = { + set page( + header: [ + #set text(font: "HarmonyOS Sans SC", weight: 700) + #title + #h(1fr) + #secret + ], + numbering: "第 1 页,共 1 页", + ) + set text(font: ("LXGW WenKai")) + show: codly-init.with() + shadow_switch.update(enable_shadow) + + show heading.where(level: 1): it => [ + #set align(center) + #text(it, size: 24pt, weight: "black", font: "Source Han Serif") + ] + show heading.where(level: 2): it => [ + #set align(center) + #text(it, size: 16pt, weight: "bold", font: "Source Han Serif") + ] + show heading.where(level: 3): it => [ + #text(it, size: 14pt, weight: "bold", font: "Source Han Sans SC") + ] + show raw: set text(font: "Maple Mono NF", size: 9pt) + show math.equation: set text(font: ( + "New Computer Modern Math", + "Source Han Serif", + )) + + [ + = #title + + == #secret + + #body + ] +}