feat: add modern template and docs

This commit is contained in:
Popa committed 2026-09-14 22:48:26 +02:00
1 parent 22cb61421d
commit 3c10aab1b5
4 files changed
+334 -1

No files matched your search

+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Tristan Pieper
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+26 -1
View File
@@ -117,6 +117,27 @@ Optional arguments:
- `no-pagebreak`: whether to avoid page breaks between exercises (level 1
headings) (`false`)
### `modern-template`
A modern layout, heavily inspired by the
[`grape-suite`](https://github.com/piepert/grape-suite) package. The only
required argument is `body`.
Optional arguments:
- `seminar`: title for the seminar (`[]`)
- `professor`: professor name (`[]`)
- `assistant`: assistant name (`none`)
- `semester`: current semester (`[]`)
- `sheet-title`: title for the exercise sheet (`[]`)
- `name`: student name (`[]`)
- `date`: date of submission (`datetime.today()`)
- `exercise-label`: label for exercises (`[Exercise]`)
- `hint-label`: label for hints (`[Hint]`)
- `theme`: custom theme for the document
- `decimal-comma`: whether to use a decimal comma instead of a decimal point
(`false`)
## Components and helpers
- `exercise`: exercise box with optional `heading`, `points`, `color`,
@@ -158,4 +179,8 @@ to either template.
Clean Sheets is licensed under the [MIT License](LICENSE). The bundled
`assets/OneHalfLight.tmTheme` is the MIT-licensed
[One Half Light theme](https://github.com/sonph/OneHalf) by Son Pham; see
[`LICENSE-OneHalfLight`](LICENSE-OneHalfLight).
[`LICENSE-OneHalfLight`](LICENSE-OneHalfLight). Finally, since the
`modern-template` layout is heavily inspired by the
[`grape-suite`](https://github.com/piepert/grape-suite) package, we also
include its MIT-license for by Tristan Pieper; see
[`LICENSE-grape-suite`](LICENSE-grape-suite).
+2
View File
@@ -4,3 +4,5 @@
#import "src/helpers.typ": Cal, Complement, chevrons, german-date-time, group-digits-text, jb, qed
#import "src/components/boxes.typ": axiom, corollary, definition, exercise, korollar, lemma, satz, theorem
#import "src/theme.typ": smallcaps, upper
#import "src/templates/modern.typ" as modern
+285
View File
@@ -0,0 +1,285 @@
#import "../helpers.typ": render-footnote-entry
#let default-theme = (
primary: rgb("#0E7C7B"),
secondary: rgb("#D4F4ED"),
accent: rgb("#FFC857"),
warning: rgb("#E9724C"),
error: rgb("#C5283D"),
text-font: ("Fira Sans", "Libertinus Serif"),
math-font: ("Fira Math", "New Computer Modern Math"),
)
#let theme-state = state("homework-theme", default-theme)
#let exercise-label-state = state("homework-exercise-label", [Exercise])
#let hint-label-state = state("homework-hint-label", [Hint])
#let exercise-counter = counter("homework-exercises")
#let subtask-indent = state("homework-subtask-indent", (0,))
#let exercise-active = state("homework-exercise-active", false)
#let exercise(
points: none,
title,
body,
) = context {
subtask-indent.update((0,))
let theme = theme-state.get()
let text-color = theme.primary
let border-color = theme.primary
let background-color = theme.secondary.transparentize(50%)
let exercise-label = exercise-label-state.get()
let subtask-points = query(
selector(metadata).within(here()),
).filter(e => {
type(e.value) == dictionary and "type" in e.value and e.value.type == "subtask-score"
})
let calculated-points = subtask-points.map(e => e.value.points).sum(default: 0)
let shown-points = if points != none { points } else if subtask-points.len() > 0 { calculated-points }
v(1.5em)
exercise-active.update(true)
block(
breakable: false,
sticky: true,
fill: background-color,
inset: (y: 1em, left: 1.25em, right: 1em),
width: 100%,
stroke: (bottom: (paint: border-color, dash: "dashed")),
above: 0pt,
below: 0.05em,
{
set text(fill: text-color, size: 1em)
[*#exercise-label #exercise-counter.display()*]
if title != none and title != [] { [ --- #title] }
h(1fr)
if shown-points != none and shown-points > 0 { [#shown-points P.] }
},
)
move(
dx: 0.25em,
block(
breakable: true,
stroke: (left: (paint: background-color, thickness: 0.5em, dash: "dotted")),
inset: 1em,
width: 100% - 0.25em,
body,
),
)
exercise-active.update(false)
exercise-counter.step()
}
#let subtask(
points: 0,
tight: false,
ignore-points: false,
markers: ("(i)", "(a)"),
show-points: true,
counter: none,
content,
) = {
if (points != none and type(points) == int and not ignore-points) {
metadata((type: "subtask-score", points: points))
}
subtask-indent.update(k => {
k.push(0)
k
})
context {
let indent = subtask-indent.at(here())
let num = if counter == none { indent.at(indent.len() - 2) + 1 } else { counter }
let marker = if indent.len() - 2 >= markers.len() { "i." } else { markers.at(indent.len() - 2) }
if not tight { v(0.25em) }
grid(
columns: (2em, 1fr),
column-gutter: 0.75em,
{
set align(right)
numbering(marker, num)
},
if points != none and points > 0 and show-points {
metadata((type: "subtask-points", content: block(width: 7%, [#points P.])))
content
} else { content },
)
if not tight { v(0.25em) }
}
subtask-indent.update(k => {
k = k.slice(0, k.len() - 1)
if k.len() > 0 { k.last() = k.last() + 1 }
k
})
}
#let hint(
label: none,
body,
) = context {
let theme = theme-state.get()
let hint-label = if label != none and label != [] { label } else { hint-label-state.get() }
let in-exercise = exercise-active.get()
let indent = subtask-indent.get()
let in-subtask = in-exercise and indent.len() == 1
let offset = 0.75em
let hint-block = block(
breakable: true,
stroke: (left: (paint: theme.accent, thickness: 0.25em)),
fill: theme.accent.transparentize(90%),
inset: (y: 0.75em, left: offset, right: 1em),
width: if in-subtask { 100% - 0.25em } else { 100% + offset },
[
#text(size: 8pt, weight: 600, fill: theme.accent.darken(25%), hint-label) \
#body
],
)
if in-subtask {
move(dx: 0.25em, hint-block)
} else {
move(dx: -offset, hint-block)
}
}
#let modern-template(
seminar: [],
professor: [],
assistant: none,
semester: [],
sheet-title: [],
name: [],
date: datetime.today(),
exercise-label: [Exercise],
hint-label: [Hint],
theme: default-theme,
decimal-comma: false,
body,
) = {
let text-color = theme.primary
let border-color = theme.primary
let accent-color = theme.accent
theme-state.update(theme)
exercise-label-state.update(exercise-label)
hint-label-state.update(hint-label)
exercise-counter.update(1)
subtask-indent.update((0,))
set document(title: sheet-title, date: date, author: name.text)
set page(
margin: (y: 3cm),
numbering: (..c) => [*#c.at(0)* / #c.at(-1)],
background: context {
let point-list = query(metadata).filter(e => {
type(e.value) == dictionary and "type" in e.value and e.value.type == "subtask-points"
})
for p in point-list {
if p.location().page() == here().page() {
place(dx: 89.5%, dy: p.location().position().y, p.value.content)
}
}
},
header: {
set text(size: 8pt)
grid(
columns: (auto, auto),
column-gutter: 1fr,
align: (start, end),
[
#text(weight: 800)[#seminar] \
#(professor, assistant).join([#h(0.25em)·#h(0.25em)]) \
#semester
],
[
#text(fill: text-color, weight: 800)[#sheet-title] \
#name \
#if date != none { date.display("[day].[month].[year]") }
],
)
line(length: 100%, stroke: border-color)
},
footer: context {
line(length: 100%, stroke: border-color)
grid(
columns: (2fr, 1fr, 2fr),
align: (start, center, end),
none, counter(page).display(both: true), none,
)
},
)
set text(font: theme.text-font)
show math.equation: set text(font: theme.math-font)
show raw: set text(font: "Fira Code", size: 10pt)
set footnote(numbering: "[1]")
set footnote.entry(
separator: line(length: 30% + 0pt, stroke: (paint: theme.primary.lighten(50%), dash: "dotted")),
indent: 1em,
)
show footnote.entry: it => render-footnote-entry(
it,
numbering-pattern: "[1]",
)
set par(justify: true, linebreaks: "optimized")
show math.equation: it => if decimal-comma {
show regex("\\d+\\.\\d+"): it => {
show ".": { "," + h(0pt) }
it
}
it
} else { it }
show title: set text(fill: text-color, size: 1.05em)
show heading: set text(fill: text-color)
v(0.5em)
align(center, title(sheet-title))
body
}
#let _qed = $square$
#let qed-equation(eq) = {
set math.equation(numbering: n => _qed, number-align: right + bottom)
eq
}
#let qed = [#h(1fr)#_qed]