#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]