diff --git a/README.md b/README.md index 5da3d35..0c1a459 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,13 @@ and small helpers for mathematical and German-language course material. Create a ready-to-edit project: ```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: ```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( 1, @@ -49,32 +49,53 @@ and `body`. Optional arguments: - `tutor-label`: custom label beside the tutor name (`none`) -- `sheet`: name displayed before the sheet number (`[Exercise Sheet]`) -- `logo`: logo content, usually `image("logo.png")` (`none`) -- `show-logo`: whether to display the provided logo (`true`) +- `sheet-label`: name displayed before the sheet number (`[Exercise Sheet]`) +- `logo`: logo content, usually `image("logo.png")` or similar (`none`) - `page-numbering`: custom page-numbering function - `table-header-smallcaps`: use small capitals in table headers (`false`) - `text-font` and `math-font`: font families with portable fallbacks -- `show-end-message`: display the package credit (`false`) -- `end-message`: custom credit content +- `no-pagebreak`: whether to avoid page breaks between exercises (level 1 + headings) (`true`) +- `show-credits`: display the package credit (`false`) +- `credits`: custom credit content ### `computer-science-template` -A denser layout with submission and test dates, optional digit grouping, and -decimal-comma formatting. Required arguments are `course`, `students`, -`semester`, `university`, `institute`, and `body`. +A denser layout with (German) submission and attestation dates, optional digit +grouping, and decimal-comma formatting. Required arguments are `sheetnumber`, +`course`, `students`, `semester`, `university`, `institute`, and `body`. -Optional arguments are `sheetnumber`, `subtitle`, `department`, `submit_until`, -`testats_from`, `testats_until`, `group-digits`, `decimal-comma`, -`page-numbering`, `raw-syntaxes`, `info-text`, `text-font`, `math-font`, -`table-header-smallcaps`, and `no-pagebreak`. +Optional arguments: + +- `subtitle`: custom subtitle for this exercise sheet (`none`) +- `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 -- `ex_box`: exercise box with optional `heading`, `points`, `color`, +- `exercise`: exercise box with optional `heading`, `points`, `color`, `stroke-color`, `text-color`, and `radius` -- `def`, `axiom`, `satz`, `lemma`, `kor`: numbered statement boxes; each takes - a body and the optional arguments `label` and `nobreak` +- `definition`, `axiom`, `theorem`, `lemma`, `corollary`: numbered statement + 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 - `chevrons`: wraps comma-separated math content in angle brackets - `german-date-time`: formats a datetime in German @@ -87,10 +108,21 @@ examples. ## Fonts -The defaults use New Computer Modern, New Computer Modern Math, and DejaVu Sans -Mono. All three are bundled with Typst, so the template renders consistently in -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. +The default font stack prefers Fira Sans, Fira Math, and Fira Code, with +fallbacks that are available in a standard Typst installation: + +* 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 diff --git a/examples/base.typ b/examples/base.typ index cfba431..34542a5 100644 --- a/examples/base.typ +++ b/examples/base.typ @@ -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( - 1, + none, // sheetnumber can be omitted for an unnumbered exercise sheet [Linear Algebra I], [Prof. Dr. Daniel Docent], [Dr. Anne Assistant], 4, ([Jane Doe], [Joe Shmoe]), - [John Q. Public], - show-logo: false, - show-end-message: true, + [John Q. Public, James X. Smith], + tutor-label: [Tutors:], + 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, ) = Exercise 1 -#ex_box( +#exercise( heading: [#lorem(5)], points: [$5 + 10 + 5$ Points], )[ @@ -32,16 +48,34 @@ #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 +#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 -#ex_box(points: [$25$ Points])[ +#exercise(points: [$25$ Points])[ #lorem(41) #lorem(26) @@ -65,17 +99,13 @@ $ 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 = Exercise 3 -#ex_box(heading: [#lorem(8)])[ - #lorem(20) - - #lorem(30) -] +#exercise[#lorem(20)] ```js #!/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}`); } ``` -$ - 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(20) #qed diff --git a/examples/computer-science.typ b/examples/computer-science.typ index a9e7542..e45b94a 100644 --- a/examples/computer-science.typ +++ b/examples/computer-science.typ @@ -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( + 1, + subtitle: [Vorlesung 1: Einführung in die Grundlagen], [Exemplarische Grundlagen I], ( ([Max Mustermann], [1234567]), ([Erika Musterfrau], [7654321]), ), - [Wintersemester 2025/26], + [Wintersemester 2026/27], [Beispiel-Universität Musterstadt], [Institut für Exemplarisches], - sheetnumber: 1, - subtitle: lorem(5), department: [Abteilung Beispiel], - submit_until: datetime(day: 1, month: 1, year: 2026, hour: 14, minute: 0, second: 0), - testats_from: datetime(day: 1, month: 1, year: 2026, hour: 18, minute: 0, second: 0), - testats_until: datetime(day: 8, month: 1, year: 2026, hour: 10, minute: 0, second: 0), + submit-until: datetime(day: 1, month: 1, year: 2027, hour: 14, minute: 0, second: 0), + attestations-from: datetime(day: 1, month: 1, year: 2027, hour: 18, 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, decimal-comma: true, + text-font: "Libertinus Serif", + math-font: "Libertinus Math", + table-header-smallcaps: true, + no-pagebreak: false, body, ) - = Aufgabe 1 -#ex_box( - heading: [Aufgabe 1], - points: [10 Punkte], +#exercise( + heading: [Listen], + points: [$10000.5$ Punkte], + color: fuchsia, + stroke-color: fuchsia.lighten(50%), + text-color: fuchsia.darken(25%), )[ Zeigen Sie eine einfache Aussage über Listen. ] @@ -40,8 +48,37 @@ DEF magic_recursive(string s, string p): #table( 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 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 +$ diff --git a/lib.typ b/lib.typ index 2c3c00a..184b2bd 100644 --- a/lib.typ +++ b/lib.typ @@ -2,5 +2,5 @@ #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/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 diff --git a/src/components/boxes.typ b/src/components/boxes.typ index 76c2080..6310539 100644 --- a/src/components/boxes.typ +++ b/src/components/boxes.typ @@ -1,8 +1,8 @@ #import "../theme.typ": colors, statement-colors -#let _box(header, body, color) = block( +#let _box(header, body, color, radius) = block( inset: 12pt, - radius: 3pt, + radius: radius, width: 100%, fill: rgb(..color, 10), 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 x = if h.len() >= 1 { h.at(0) } else { 0 } let y = if h.len() >= 2 { h.at(1) } else { 0 } @@ -39,52 +39,41 @@ [*#kind #mark*#lbl*.* #brk], body, color, + radius, ) } ] } -#let def(body, label: [], nobreak: false) = _stmt( - "Definition", - body, - statement-colors.definition, - label: label, - nobreak: nobreak, +#let statement-names = ( + en: ( + definition: [Definition], + axiom: [Axiom], + theorem: [Theorem], + lemma: [Lemma], + corollary: [Corollary], + ), + de: ( + definition: [Definition], + axiom: [Axiom], + theorem: [Satz], + lemma: [Lemma], + corollary: [Korollar], + ), ) -#let axiom(body, label: [], nobreak: false) = _stmt( - "Axiom", - body, - statement-colors.axiom, - label: label, - nobreak: nobreak, -) +#let _stmt-name(kind, lang: "en") = { statement-names.at(lang).at(kind) } -#let satz(body, label: [], nobreak: false) = _stmt( - "Satz", - body, - statement-colors.theorem, - label: label, - nobreak: nobreak, -) +#let definition(body, label: none, nobreak: false, lang: "en") = _stmt(_stmt-name(kind, lang: lang), body, statement-colors.at(kind), label: label, nobreak: nobreak) +#let axiom(body, label: none, nobreak: false, lang: "en") = _stmt(_stmt-name(kind, lang: lang), body, statement-colors.at(kind), label: label, nobreak: nobreak) +#let theorem(body, label: none, nobreak: false, lang: "en") = _stmt(_stmt-name(kind, lang: lang), body, statement-colors.at(kind), label: label, nobreak: nobreak) +#let lemma(body, label: none, nobreak: false, lang: "en") = _stmt(_stmt-name(kind, lang: lang), body, statement-colors.at(kind), label: label, nobreak: nobreak) +#let corollary(body, label: none, nobreak: false, lang: "en") = _stmt(_stmt-name(kind, lang: lang), body, statement-colors.at(kind), label: label, nobreak: nobreak) +// Aliases +#let satz(..args) = theorem(..args, lang: "de") +#let korollar(..args) = corollary(..args, lang: "de") -#let lemma(body, label: [], nobreak: false) = _stmt( - "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( +#let exercise( body, heading: [], points: [], diff --git a/src/templates/base.typ b/src/templates/base.typ index 37bc621..769651a 100644 --- a/src/templates/base.typ +++ b/src/templates/base.typ @@ -1,6 +1,6 @@ #import "../config.typ": custom-raw-syntaxes #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 /// Base template for exercise sheets. @@ -13,21 +13,23 @@ students, tutor, tutor-label: none, - sheet: [Exercise Sheet], + sheet-label: [Exercise Sheet], logo: none, - show-logo: true, page-numbering: common-theme.page-numbering, table-header-smallcaps: false, text-font: base-theme.text-font, math-font: base-theme.math-font, - show-end-message: false, - end-message: end-message, + no-pagebreak: true, + show-credits: false, + credits: credits, body, ) = { assert.eq(type(exercises), int, message: "exercises must be an 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( title: ttl, @@ -67,7 +69,9 @@ if first-h1.get() { first-h1.update(false) } else { - // pagebreak(weak: true) + if (not no-pagebreak) { + pagebreak(weak: true) + } } v(0.3em) it @@ -97,8 +101,8 @@ show raw.where(block: true): box.with(..base-theme.raw-block) 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 { logo } @@ -110,9 +114,8 @@ columns: (6fr, 1fr), align: (start + horizon, end + horizon), row-gutter: 0.25cm, - [ - #title[#sheet #if sheetnumber < 10 { "0" };#sheetnumber] - ], + + title(ttl), logo-content, grid.cell( @@ -134,10 +137,10 @@ body - if show-end-message { + if show-credits { v(1fr) set text(size: 10pt) - align(center)[#end-message] + align(center)[#credits] } } diff --git a/src/templates/computer-science.typ b/src/templates/computer-science.typ index 8895111..a536dea 100644 --- a/src/templates/computer-science.typ +++ b/src/templates/computer-science.typ @@ -4,7 +4,7 @@ /// Computer science exercise sheet template. #let computer-science-template( - sheetnumber: 0, + sheetnumber, subtitle: none, course, students, @@ -12,14 +12,14 @@ university, institute, department: none, - submit_until: none, - testats_from: none, - testats_until: none, - group-digits: false, - decimal-comma: false, - page-numbering: common-theme.page-numbering, - raw-syntaxes: custom-raw-syntaxes, + submit-until: none, + attestations-from: none, + attestations-until: 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, math-font: computer-science-theme.math-font, table-header-smallcaps: false, @@ -137,12 +137,12 @@ v(2em) [ - #if submit_until != none [ - *Abgabe bis #german-date-time(submit_until);.* + #if submit-until != none [ + *Abgabe bis #german-date-time(submit-until);.* ] - #if testats_from != none and testats_until != none [ - *Testate vom #german-date-time(testats_from) bis #german-date-time(testats_until).* + #if attestations-from != none and attestations-until != none [ + *Testate vom #german-date-time(attestations-from) bis #german-date-time(attestations-until).* ] #if info-text != none [#info-text] diff --git a/src/theme.typ b/src/theme.typ index 34098e2..2504930 100644 --- a/src/theme.typ +++ b/src/theme.typ @@ -15,11 +15,11 @@ ) #let fonts = ( - base: "Fira Sans", - base-math: "Fira Math", + base: ("Fira Sans", "New Computer Modern"), + base-math: ("Fira Math", "New Computer Modern Math"), cmu: "New Computer Modern", cmu-math: "New Computer Modern Math", - code: "Fira Code", + code: ("Fira Code", "DejaVu Sans Mono"), ) #let code-text-features = ( @@ -100,7 +100,7 @@ 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 = ( definition: (247, 57, 72),