feat: revamp template API and box components

This commit is contained in:
Popa committed 2026-09-11 14:00:59 +02:00
1 parent 51fc2ef3c3
commit 337ff33853
8 files changed
+211 -130

No files matched your search

+53 -21
View File
@@ -9,13 +9,13 @@ and small helpers for mathematical and German-language course material.
Create a ready-to-edit project: Create a ready-to-edit project:
```sh ```sh
typst init @preview/clean-sheets:0.2.2 typst init @preview/clean-sheets:0.3.0
``` ```
Or import the package in an existing document: Or import the package in an existing document:
```typst ```typst
#import "@preview/clean-sheets:0.2.2": base-template, ex_box, qed #import "@preview/clean-sheets:0.3.0": base-template, ex_box, qed
#show: body => base-template( #show: body => base-template(
1, 1,
@@ -49,32 +49,53 @@ and `body`.
Optional arguments: Optional arguments:
- `tutor-label`: custom label beside the tutor name (`none`) - `tutor-label`: custom label beside the tutor name (`none`)
- `sheet`: name displayed before the sheet number (`[Exercise Sheet]`) - `sheet-label`: name displayed before the sheet number (`[Exercise Sheet]`)
- `logo`: logo content, usually `image("logo.png")` (`none`) - `logo`: logo content, usually `image("logo.png")` or similar (`none`)
- `show-logo`: whether to display the provided logo (`true`)
- `page-numbering`: custom page-numbering function - `page-numbering`: custom page-numbering function
- `table-header-smallcaps`: use small capitals in table headers (`false`) - `table-header-smallcaps`: use small capitals in table headers (`false`)
- `text-font` and `math-font`: font families with portable fallbacks - `text-font` and `math-font`: font families with portable fallbacks
- `show-end-message`: display the package credit (`false`) - `no-pagebreak`: whether to avoid page breaks between exercises (level 1
- `end-message`: custom credit content headings) (`true`)
- `show-credits`: display the package credit (`false`)
- `credits`: custom credit content
### `computer-science-template` ### `computer-science-template`
A denser layout with submission and test dates, optional digit grouping, and A denser layout with (German) submission and attestation dates, optional digit
decimal-comma formatting. Required arguments are `course`, `students`, grouping, and decimal-comma formatting. Required arguments are `sheetnumber`,
`semester`, `university`, `institute`, and `body`. `course`, `students`, `semester`, `university`, `institute`, and `body`.
Optional arguments are `sheetnumber`, `subtitle`, `department`, `submit_until`, Optional arguments:
`testats_from`, `testats_until`, `group-digits`, `decimal-comma`,
`page-numbering`, `raw-syntaxes`, `info-text`, `text-font`, `math-font`, - `subtitle`: custom subtitle for this exercise sheet (`none`)
`table-header-smallcaps`, and `no-pagebreak`. - `department`: custom department name (`none`)
- `submit-until`: a `datetime` object for the submission deadline (`none`)
- `attestations-from`: a `datetime` object for the beginning of the attestation
period (`none`)
- `attestations-until`: a `datetime` object for the end of the attestation
period (`none`)
- `info-text`: custom text to be displayed in the very beginning of the
document (`none`)
- `page-numbering`: custom page-numbering function
- `group-digits`: whether to group digits in numbers, e.g. `1 000` instead of
`1000` (`true`)
- `decimal-comma`: whether to use a decimal comma instead of a decimal point
(`false`)
- `raw-syntaxes`: a list of syntax names to be rendered as raw code blocks
- `text-font` and `math-font`: font families with portable fallbacks
- `table-header-smallcaps`: whether to use small capitals in table headers
(`false`)
- `no-pagebreak`: whether to avoid page breaks between exercises (level 1
headings) (`false`)
## Components and helpers ## Components and helpers
- `ex_box`: exercise box with optional `heading`, `points`, `color`, - `exercise`: exercise box with optional `heading`, `points`, `color`,
`stroke-color`, `text-color`, and `radius` `stroke-color`, `text-color`, and `radius`
- `def`, `axiom`, `satz`, `lemma`, `kor`: numbered statement boxes; each takes - `definition`, `axiom`, `theorem`, `lemma`, `corollary`: numbered statement
a body and the optional arguments `label` and `nobreak` boxes; each takes a body and the optional arguments `label`, `nobreak`, and
`lang`.
There are also the aliases `satz` and `korollar` for German-language documents.
- `Cal` and `Complement`: calligraphic and complement math helpers - `Cal` and `Complement`: calligraphic and complement math helpers
- `chevrons`: wraps comma-separated math content in angle brackets - `chevrons`: wraps comma-separated math content in angle brackets
- `german-date-time`: formats a datetime in German - `german-date-time`: formats a datetime in German
@@ -87,10 +108,21 @@ examples.
## Fonts ## Fonts
The defaults use New Computer Modern, New Computer Modern Math, and DejaVu Sans The default font stack prefers Fira Sans, Fira Math, and Fira Code, with
Mono. All three are bundled with Typst, so the template renders consistently in fallbacks that are available in a standard Typst installation:
the web app and on the command line. Pass `text-font` and `math-font` to either
template if you prefer locally installed fonts such as Fira Sans and Fira Math. * body text: `Fira Sans`, falling back to `New Computer Modern`
* math: `Fira Math`, falling back to `New Computer Modern Math`
* code: `Fira Code`, falling back to `DejaVu Sans Mono`
The Fira fonts are available by default in the Typst web app. The local Typst
CLI, however, only bundles a small set of fonts, including New Computer Modern,
New Computer Modern Math, and DejaVu Sans Mono. When the Fira fonts are not
installed locally, Typst therefore uses the respective fallback fonts.
You can check which fonts are available to your local Typst installation with
`typst fonts`. If you prefer different fonts, pass `text-font` and `math-font`
to either template.
## License and credits ## License and credits
+46 -26
View File
@@ -1,21 +1,37 @@
#import "@preview/clean-sheets:0.3.0": Cal, base-template, ex_box, qed #import "@preview/clean-sheets:0.3.0": Cal, base-template, exercise, qed
#let logo = box(
width: 2.4cm,
height: 1cm,
stroke: 0.8pt + eastern,
radius: 3pt,
align(center + horizon, text(fill: eastern, weight: "bold")[UNI LOGO]),
)
#show: body => base-template( #show: body => base-template(
1, none, // sheetnumber can be omitted for an unnumbered exercise sheet
[Linear Algebra I], [Linear Algebra I],
[Prof. Dr. Daniel Docent], [Prof. Dr. Daniel Docent],
[Dr. Anne Assistant], [Dr. Anne Assistant],
4, 4,
([Jane Doe], [Joe Shmoe]), ([Jane Doe], [Joe Shmoe]),
[John Q. Public], [John Q. Public, James X. Smith],
show-logo: false, tutor-label: [Tutors:],
show-end-message: true, sheet-label: [Example Exercise Sheet],
logo: logo,
page-numbering: "— I of I —",
table-header-smallcaps: true,
text-font: "IBM Plex Sans",
math-font: "IBM Plex Math",
no-pagebreak: true,
show-credits: true,
credits: [_Typset with #link("https://typst.app")[Typst]._],
body, body,
) )
= Exercise 1 = Exercise 1
#ex_box( #exercise(
heading: [#lorem(5)], heading: [#lorem(5)],
points: [$5 + 10 + 5$ Points], points: [$5 + 10 + 5$ Points],
)[ )[
@@ -32,16 +48,34 @@
#lorem(40) #lorem(40)
] ]
#lorem(59)#footnote[#lorem(21)] #lorem(20)#footnote[#lorem(21)]
$ $
(a + b)^n = sum_(k = 0)^n binom(n, k) space.thin a^(n - k) b^k bold("B")(P) =
mu_0 / (4 pi)
integral
(I times bold(hat("r"))) / r^2 dif bold(l)
= (mu_0 I) / (4 pi)
integral
(dif bold(l) times bold(hat("r"))) / r^2
$ $
#lorem(30) #qed #lorem(30) #qed
#table(
columns: (1fr,) * 5,
align: (start,) + (center,) * 3 + (end,),
table.header([Header 1], [Header 2], [Header 3], [Header 4], [Header 5]),
[Cell 1], [Cell 2], [Cell 3], [Cell 4], [Cell 5],
[Cell 6], [Cell 7], [Cell 8], [Cell 9], [Cell 10],
[Cell 11], [Cell 12], [Cell 13], [Cell 14], [Cell 15],
)
= Exercise 2 = Exercise 2
#ex_box(points: [$25$ Points])[ #exercise(points: [$25$ Points])[
#lorem(41) #lorem(41)
#lorem(26) #lorem(26)
@@ -65,17 +99,13 @@ $
det V(x_1, ..., x_n) = product_(1 <= i < j <= n)(x_j - x_i) det V(x_1, ..., x_n) = product_(1 <= i < j <= n)(x_j - x_i)
$ $
#lorem(60)#footnote[#lorem(31)]#footnote[#lorem(13)] #qed #lorem(59)#footnote[#lorem(31)]#footnote[#lorem(13)]
#lorem(30) #qed #lorem(30) #qed
= Exercise 3 = Exercise 3
#ex_box(heading: [#lorem(8)])[ #exercise[#lorem(20)]
#lorem(20)
#lorem(30)
]
```js ```js
#!/usr/bin/env node #!/usr/bin/env node
@@ -90,14 +120,4 @@ if (π >= 0 && π !== Infinity || !NaN) for (const [k,v] of Object.entries(obj))
try { await Promise.resolve(fn?.({foo:n=>n**2})); } catch (e) { console.error(`${e}`); } try { await Promise.resolve(fn?.({foo:n=>n**2})); } catch (e) { console.error(`${e}`); }
``` ```
$ #lorem(20) #qed
bold("B")(P) =
mu_0 / (4 pi)
integral
(I times bold(hat("r"))) / r^2 dif bold(l)
= (mu_0 I) / (4 pi)
integral
(dif bold(l) times bold(hat("r"))) / r^2
$
#lorem(30) #qed
+49 -12
View File
@@ -1,31 +1,39 @@
#import "@preview/clean-sheets:0.3.0": Cal, chevrons, computer-science-template, def, ex_box, qed, satz #import "@preview/clean-sheets:0.3.0": Cal, chevrons, computer-science-template, exercise, lemma, qed
#show: body => computer-science-template( #show: body => computer-science-template(
1,
subtitle: [Vorlesung 1: Einführung in die Grundlagen],
[Exemplarische Grundlagen I], [Exemplarische Grundlagen I],
( (
([Max Mustermann], [1234567]), ([Max Mustermann], [1234567]),
([Erika Musterfrau], [7654321]), ([Erika Musterfrau], [7654321]),
), ),
[Wintersemester 2025/26], [Wintersemester 2026/27],
[Beispiel-Universität Musterstadt], [Beispiel-Universität Musterstadt],
[Institut für Exemplarisches], [Institut für Exemplarisches],
sheetnumber: 1,
subtitle: lorem(5),
department: [Abteilung Beispiel], department: [Abteilung Beispiel],
submit_until: datetime(day: 1, month: 1, year: 2026, hour: 14, minute: 0, second: 0), submit-until: datetime(day: 1, month: 1, year: 2027, hour: 14, minute: 0, second: 0),
testats_from: datetime(day: 1, month: 1, year: 2026, hour: 18, minute: 0, second: 0), attestations-from: datetime(day: 1, month: 1, year: 2027, hour: 18, minute: 0, second: 0),
testats_until: datetime(day: 8, month: 1, year: 2026, hour: 10, minute: 0, second: 0), attestations-until: datetime(day: 8, month: 1, year: 2027, hour: 10, minute: 0, second: 0),
info-text: lorem(40),
page-numbering: "Blatt I von I",
group-digits: true, group-digits: true,
decimal-comma: true, decimal-comma: true,
text-font: "Libertinus Serif",
math-font: "Libertinus Math",
table-header-smallcaps: true,
no-pagebreak: false,
body, body,
) )
= Aufgabe 1 = Aufgabe 1
#ex_box( #exercise(
heading: [Aufgabe 1], heading: [Listen],
points: [10 Punkte], points: [$10000.5$ Punkte],
color: fuchsia,
stroke-color: fuchsia.lighten(50%),
text-color: fuchsia.darken(25%),
)[ )[
Zeigen Sie eine einfache Aussage über Listen. Zeigen Sie eine einfache Aussage über Listen.
] ]
@@ -40,8 +48,37 @@ DEF magic_recursive(string s, string p):
#table( #table(
columns: 6, columns: 6,
[Heading 1], [Heading 2], [Heading 3], [Heading 4], [Heading 5], [Heading 6], table.header([Heading 1], [Heading 2], [Heading 3], [Heading 4], [Heading 5], [Heading 6]),
[Cell 1], [Cell 2], [Cell 3], [Cell 4], [Cell 5], [Cell 6], [Cell 1], [Cell 2], [Cell 3], [Cell 4], [Cell 5], [Cell 6],
[Cell 7], [Cell 8], [Cell 9], [Cell 10], [Cell 11], [Cell 12], [Cell 7], [Cell 8], [Cell 9], [Cell 10], [Cell 11], [Cell 12],
) )
#lemma(label: [Pumping-Lemma], lang: "de")[
Sei $L subset.eq Sigma^*$ eine unendliche reguläre Sprache. Dann existiert eine Zahl $k in NN$ (die Pumping-Konstante), sodass jedes Wort $w in L$ mit $|w| >= k$ in drei Teile $w = x y z$ zerlegt werden kann, wobei
#set enum(numbering: "(i)")
+ $|x y| <= k$,
+ $|y| >= 1$ und
+ $forall i in NN_0: x y^i z in L$.
]
= Aufgabe 2
#exercise(
color: fuchsia,
stroke-color: fuchsia.lighten(50%),
)[
Unter _Rekursion_ versteht man in der Informatik die Eigenschaft einer Funktion, sich selbst aufzurufen. Geben Sie ein Beispiel für eine rekursive Funktion an und erläutern Sie ihre Funktionsweise.
]
#lorem(50) #qed
$
bold("B")(P) =
mu_0 / (4 pi)
integral
(I times bold(hat("r"))) / r^2 dif bold(l)
= (mu_0 I) / (4 pi)
integral
(dif bold(l) times bold(hat("r"))) / r^2
$
+1 -1
View File
@@ -2,5 +2,5 @@
#import "src/templates/computer-science.typ": computer-science-template #import "src/templates/computer-science.typ": computer-science-template
#import "src/helpers.typ": Cal, Complement, chevrons, german-date-time, group-digits-text, jb, qed #import "src/helpers.typ": Cal, Complement, chevrons, german-date-time, group-digits-text, jb, qed
#import "src/components/boxes.typ": axiom, def, ex_box, kor, lemma, satz #import "src/components/boxes.typ": axiom, corollary, definition, exercise, korollar, lemma, satz, theorem
#import "src/theme.typ": smallcaps, upper #import "src/theme.typ": smallcaps, upper
+29 -40
View File
@@ -1,8 +1,8 @@
#import "../theme.typ": colors, statement-colors #import "../theme.typ": colors, statement-colors
#let _box(header, body, color) = block( #let _box(header, body, color, radius) = block(
inset: 12pt, inset: 12pt,
radius: 3pt, radius: radius,
width: 100%, width: 100%,
fill: rgb(..color, 10), fill: rgb(..color, 10),
stroke: ( stroke: (
@@ -15,7 +15,7 @@
], ],
) )
#let _stmt(kind, body, color, label: [], nobreak: false) = context { #let _stmt(kind, body, color, label: [], nobreak: false, radius: 5pt) = context {
let h = counter(heading).get() let h = counter(heading).get()
let x = if h.len() >= 1 { h.at(0) } else { 0 } let x = if h.len() >= 1 { h.at(0) } else { 0 }
let y = if h.len() >= 2 { h.at(1) } else { 0 } let y = if h.len() >= 2 { h.at(1) } else { 0 }
@@ -39,52 +39,41 @@
[*#kind #mark*#lbl*.* #brk], [*#kind #mark*#lbl*.* #brk],
body, body,
color, color,
radius,
) )
} }
] ]
} }
#let def(body, label: [], nobreak: false) = _stmt( #let statement-names = (
"Definition", en: (
body, definition: [Definition],
statement-colors.definition, axiom: [Axiom],
label: label, theorem: [Theorem],
nobreak: nobreak, lemma: [Lemma],
corollary: [Corollary],
),
de: (
definition: [Definition],
axiom: [Axiom],
theorem: [Satz],
lemma: [Lemma],
corollary: [Korollar],
),
) )
#let axiom(body, label: [], nobreak: false) = _stmt( #let _stmt-name(kind, lang: "en") = { statement-names.at(lang).at(kind) }
"Axiom",
body,
statement-colors.axiom,
label: label,
nobreak: nobreak,
)
#let satz(body, label: [], nobreak: false) = _stmt( #let definition(body, label: none, nobreak: false, lang: "en") = _stmt(_stmt-name(kind, lang: lang), body, statement-colors.at(kind), label: label, nobreak: nobreak)
"Satz", #let axiom(body, label: none, nobreak: false, lang: "en") = _stmt(_stmt-name(kind, lang: lang), body, statement-colors.at(kind), label: label, nobreak: nobreak)
body, #let theorem(body, label: none, nobreak: false, lang: "en") = _stmt(_stmt-name(kind, lang: lang), body, statement-colors.at(kind), label: label, nobreak: nobreak)
statement-colors.theorem, #let lemma(body, label: none, nobreak: false, lang: "en") = _stmt(_stmt-name(kind, lang: lang), body, statement-colors.at(kind), label: label, nobreak: nobreak)
label: label, #let corollary(body, label: none, nobreak: false, lang: "en") = _stmt(_stmt-name(kind, lang: lang), body, statement-colors.at(kind), label: label, nobreak: nobreak)
nobreak: nobreak, // Aliases
) #let satz(..args) = theorem(..args, lang: "de")
#let korollar(..args) = corollary(..args, lang: "de")
#let lemma(body, label: [], nobreak: false) = _stmt( #let exercise(
"Lemma",
body,
statement-colors.lemma,
label: label,
nobreak: nobreak,
)
#let kor(body, label: [], nobreak: false) = _stmt(
"Korollar",
body,
statement-colors.corollary,
label: label,
nobreak: nobreak,
)
#let ex_box(
body, body,
heading: [], heading: [],
points: [], points: [],
+17 -14
View File
@@ -1,6 +1,6 @@
#import "../config.typ": custom-raw-syntaxes #import "../config.typ": custom-raw-syntaxes
#import "../helpers.typ": content-to-string, render-footnote-entry #import "../helpers.typ": content-to-string, render-footnote-entry
#import "../theme.typ": base-theme, code-theme, colors, common-theme, end-message, smallcaps #import "../theme.typ": base-theme, code-theme, colors, common-theme, credits, smallcaps
#import "../components/student-table.typ": exercise-overview #import "../components/student-table.typ": exercise-overview
/// Base template for exercise sheets. /// Base template for exercise sheets.
@@ -13,21 +13,23 @@
students, students,
tutor, tutor,
tutor-label: none, tutor-label: none,
sheet: [Exercise Sheet], sheet-label: [Exercise Sheet],
logo: none, logo: none,
show-logo: true,
page-numbering: common-theme.page-numbering, page-numbering: common-theme.page-numbering,
table-header-smallcaps: false, table-header-smallcaps: false,
text-font: base-theme.text-font, text-font: base-theme.text-font,
math-font: base-theme.math-font, math-font: base-theme.math-font,
show-end-message: false, no-pagebreak: true,
end-message: end-message, show-credits: false,
credits: credits,
body, body,
) = { ) = {
assert.eq(type(exercises), int, message: "exercises must be an integer") assert.eq(type(exercises), int, message: "exercises must be an integer")
assert(exercises > 0, message: "exercises must be a positive integer") assert(exercises > 0, message: "exercises must be a positive integer")
let ttl = sheet + if { sheetnumber < 10 } { " 0" } else { " " } + str(sheetnumber) let ttl = if sheetnumber == none { sheet-label } else {
sheet-label + if { sheetnumber < 10 } { " 0" } else { " " } + str(sheetnumber)
}
set document( set document(
title: ttl, title: ttl,
@@ -67,7 +69,9 @@
if first-h1.get() { if first-h1.get() {
first-h1.update(false) first-h1.update(false)
} else { } else {
// pagebreak(weak: true) if (not no-pagebreak) {
pagebreak(weak: true)
}
} }
v(0.3em) v(0.3em)
it it
@@ -97,8 +101,8 @@
show raw.where(block: true): box.with(..base-theme.raw-block) show raw.where(block: true): box.with(..base-theme.raw-block)
show raw.where(block: false): box.with(..code-theme.inline) show raw.where(block: false): box.with(..code-theme.inline)
let logo-content = if not show-logo or logo == none { let logo-content = if logo == none {
[] none
} else { } else {
logo logo
} }
@@ -110,9 +114,8 @@
columns: (6fr, 1fr), columns: (6fr, 1fr),
align: (start + horizon, end + horizon), align: (start + horizon, end + horizon),
row-gutter: 0.25cm, row-gutter: 0.25cm,
[
#title[#sheet #if sheetnumber < 10 { "0" };#sheetnumber] title(ttl),
],
logo-content, logo-content,
grid.cell( grid.cell(
@@ -134,10 +137,10 @@
body body
if show-end-message { if show-credits {
v(1fr) v(1fr)
set text(size: 10pt) set text(size: 10pt)
align(center)[#end-message] align(center)[#credits]
} }
} }
+12 -12
View File
@@ -4,7 +4,7 @@
/// Computer science exercise sheet template. /// Computer science exercise sheet template.
#let computer-science-template( #let computer-science-template(
sheetnumber: 0, sheetnumber,
subtitle: none, subtitle: none,
course, course,
students, students,
@@ -12,14 +12,14 @@
university, university,
institute, institute,
department: none, department: none,
submit_until: none, submit-until: none,
testats_from: none, attestations-from: none,
testats_until: none, attestations-until: none,
group-digits: false,
decimal-comma: false,
page-numbering: common-theme.page-numbering,
raw-syntaxes: custom-raw-syntaxes,
info-text: none, info-text: none,
page-numbering: common-theme.page-numbering,
group-digits: false,
decimal-comma: true,
raw-syntaxes: custom-raw-syntaxes,
text-font: computer-science-theme.text-font, text-font: computer-science-theme.text-font,
math-font: computer-science-theme.math-font, math-font: computer-science-theme.math-font,
table-header-smallcaps: false, table-header-smallcaps: false,
@@ -137,12 +137,12 @@
v(2em) v(2em)
[ [
#if submit_until != none [ #if submit-until != none [
*Abgabe bis #german-date-time(submit_until);.* *Abgabe bis #german-date-time(submit-until);.*
] ]
#if testats_from != none and testats_until != none [ #if attestations-from != none and attestations-until != none [
*Testate vom #german-date-time(testats_from) bis #german-date-time(testats_until).* *Testate vom #german-date-time(attestations-from) bis #german-date-time(attestations-until).*
] ]
#if info-text != none [#info-text] #if info-text != none [#info-text]
+4 -4
View File
@@ -15,11 +15,11 @@
) )
#let fonts = ( #let fonts = (
base: "Fira Sans", base: ("Fira Sans", "New Computer Modern"),
base-math: "Fira Math", base-math: ("Fira Math", "New Computer Modern Math"),
cmu: "New Computer Modern", cmu: "New Computer Modern",
cmu-math: "New Computer Modern Math", cmu-math: "New Computer Modern Math",
code: "Fira Code", code: ("Fira Code", "DejaVu Sans Mono"),
) )
#let code-text-features = ( #let code-text-features = (
@@ -100,7 +100,7 @@
raw-block: code-theme.block, raw-block: code-theme.block,
) )
#let end-message = [_Typeset with #link("https://typst.app")[#text(fill: colors.text)[#underline[Typst]]]\; template available from #link("https://git.p0pa.de/Popa/clean-sheets")[#text(fill: colors.text)[#underline[clean-sheets]]]._] #let credits = [_Typeset with #link("https://typst.app")[#text(fill: colors.text)[#underline[Typst]]]\; template available from #link("https://git.p0pa.de/Popa/clean-sheets")[#text(fill: colors.text)[#underline[clean-sheets]]]._]
#let statement-colors = ( #let statement-colors = (
definition: (247, 57, 72), definition: (247, 57, 72),