commit d5248784513b8f2c2a0c0b7bbf40b23cc3334c78 Author: Popa <115492561+Popa-42@users.noreply.github.com> Date: Thu Sep 10 20:02:22 2026 +0200 Initial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..597d9ca --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Popa + +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. diff --git a/LICENSE-OneHalfLight b/LICENSE-OneHalfLight new file mode 100644 index 0000000..2438dd1 --- /dev/null +++ b/LICENSE-OneHalfLight @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Son A. Pham + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..5da3d35 --- /dev/null +++ b/README.md @@ -0,0 +1,99 @@ +# Clean Sheets + +Clean, modern exercise sheets for university courses. The package provides two +page layouts, an exercise overview, statement boxes, syntax-highlighted code, +and small helpers for mathematical and German-language course material. + +## Quick start + +Create a ready-to-edit project: + +```sh +typst init @preview/clean-sheets:0.2.2 +``` + +Or import the package in an existing document: + +```typst +#import "@preview/clean-sheets:0.2.2": base-template, ex_box, qed + +#show: body => base-template( + 1, + [Linear Algebra I], + [Prof. Ada Example], + [Dr. Alan Assistant], + 3, + ([Jane Doe], [John Doe]), + [Taylor Tutor], + show-logo: false, + body, +) + += Exercise 1 + +#ex_box(heading: [Warm-up], points: [10 points])[ + Prove that $1 + 1 = 2$. +] + +The proof is immediate. #qed +``` + +## Templates + +### `base-template` + +The general exercise-sheet layout. Its required positional arguments are +`sheetnumber`, `course`, `prof`, `assistant`, `exercises`, `students`, `tutor`, +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`) +- `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 + +### `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`. + +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`. + +## Components and helpers + +- `ex_box`: 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` +- `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 +- `group-digits-text`: groups digits in a string +- `qed`: right-aligned square; `jb`: justified line break +- `smallcaps` and `upper`: tracked small-cap and uppercase helpers + +See `examples/base.typ` and `examples/computer-science.typ` for complete source +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. + +## License and credits + +Clean Sheets is licensed under the MIT License. The bundled +`assets/OneHalfLight.tmTheme` is the MIT-licensed One Half Light theme by Son +Pham; see `LICENSE-OneHalfLight`. diff --git a/assets/OneHalfLight.tmTheme b/assets/OneHalfLight.tmTheme new file mode 100644 index 0000000..a18ec7b --- /dev/null +++ b/assets/OneHalfLight.tmTheme @@ -0,0 +1,663 @@ + + + + + + name + OneHalfLight + semanticClass + theme.light.one_half_light + uuid + + colorSpaceName + sRGB + author + Son A. Pham <sp@sonpham.me> + comment + A light iTerm color scheme based on Atom's One. See github.com/sonph/onehalf for installation instructions, a dark color scheme, and versions for other editors/terminals such as (Neo)Vim and Sublime Text. + settings + + + settings + + fontStyle + + foreground + #383a42 + background + #fafafa + bracketsOptions + underline + caret + #383a42 + gutter + #fafafa + gutterForeground + #d4d4d4 + invisibles + #a0a1a7 + lineHighlight + #f0f0f0 + selection + #bfceff + selectionBorder + #bfceff + tagsForeground + + tagsOptions + stippled_underline + bracketContentsOptions + underline + + + + name + Comments + scope + comment + settings + + foreground + #a0a1a7 + + + + name + Text + scope + variable.parameter.function + settings + + foreground + #383a42 + + + + name + Delimiters + scope + none + settings + + foreground + + + + + name + Operators + scope + keyword.operator + settings + + foreground + + + + + name + Keywords + scope + keyword + settings + + foreground + #a626a4 + + + + name + Variables + scope + variable + settings + + foreground + #e45649 + + + + name + Functions + scope + entity.name.function, meta.require, support.function.any-method + settings + + foreground + #0184bc + + + + name + Classes + scope + support.class, entity.name.class, entity.name.type.class + settings + + foreground + #c18401 + + + + name + Classes + scope + meta.class + settings + + foreground + #c18401 + + + + name + Methods + scope + keyword.other.special-method + settings + + foreground + #0184bc + + + + name + Storage + scope + storage + settings + + foreground + #a626a4 + + + + name + Support + scope + support.function + settings + + foreground + #0184bc + + + + name + Strings, Inherited Class + scope + string + settings + + foreground + #50a14f + + + + name + Integers + scope + constant.numeric + settings + + foreground + #c18401 + + + + name + Floats + scope + none + settings + + foreground + #c18401 + + + + name + Boolean + scope + none + settings + + foreground + #c18401 + + + + name + Constants + scope + constant + settings + + foreground + #c18401 + + + + name + HTML: Tags + scope + entity.name.tag + settings + + foreground + #e45649 + + + + name + HTML: Tag attributes + scope + entity.other.attribute-name + settings + + foreground + #c18401 + + + + name + Attribute IDs + scope + entity.other.attribute-name.id, punctuation.definition.entity + settings + + foreground + #c18401 + + + + name + Selector + scope + meta.selector + settings + + foreground + #a626a4 + + + + name + Markdown: Headings + scope + markup.heading punctuation.definition.heading, entity.name.section + settings + + fontStyle + + foreground + #0184bc + + + + name + Markdown: Bold + scope + markup.bold, punctuation.definition.bold + settings + + foreground + #a626a4 + + + + name + Markdown: Italic + scope + markup.italic, punctuation.definition.italic + settings + + foreground + #a626a4 + + + + name + Markdown: Code + scope + markup.raw.inline + settings + + foreground + #50a14f + + + + name + Markdown: Link Text + scope + string.other.link, punctuation.definition.string.end.markdown + settings + + foreground + + + + + name + Markdown: Link Url + scope + meta.link + settings + + foreground + #50a14f + + + + name + Markdown: Lists + scope + markup.list + settings + + foreground + + + + + name + Markdown: Quotes + scope + markup.quote + settings + + foreground + #50a14f + + + + name + Java Source + scope + source.java meta.class.java meta.method.java + settings + + foreground + #383a42 + + + + name + Java Class Body + scope + source.java meta.class.java meta.class.body.java + settings + + foreground + #383a42 + + + + name + Javascript: Function Arguments + scope + source.js meta.function.js variable.parameter.function.js + settings + + foreground + #e45649 + + + + name + Javascript: New Variables + scope + source.js variable.other.readwrite.js + settings + + foreground + #e45649 + + + + name + Javascript: Variables + scope + source.js variable.other.object.js + settings + + foreground + #383a42 + + + + name + Javascript: Variables in Function Calls + scope + source.js meta.function-call.method.js variable.other.readwrite.js + settings + + foreground + #e45649 + + + + name + Javascript: New Block Variables + scope + source.js meta.block.js variable.other.readwrite.js + settings + + foreground + #e45649 + + + + name + Javascript: Block Variables + scope + source.js meta.block.js variable.other.object.js + settings + + foreground + #383a42 + + + + name + Javascript: Block Variables in Function Calls + scope + source.js meta.block.js meta.function-call.method.js variable.other.readwrite.js + settings + + foreground + #383a42 + + + + name + Javascript: Function Calls + scope + source.js meta.function-call.method.js variable.function.js + settings + + foreground + #383a42 + + + + name + Javascript: Properties + scope + source.js meta.property.object.js entity.name.function.js + settings + + foreground + #0184bc + + + + name + Javascript: Prototypes + scope + source.js support.constant.prototype.js + settings + + foreground + #383a42 + + + + name + Separator + scope + meta.separator + settings + + background + + foreground + + + + + name + Inserted + scope + markup.inserted + settings + + foreground + #98c379 + + + + name + Deleted + scope + markup.deleted + settings + + foreground + #e06c75 + + + + name + Changed + scope + markup.changed + settings + + foreground + #e5c07b + + + + name + Regular Expressions + scope + string.regexp + settings + + foreground + #50a14f + + + + name + Escape Characters + scope + constant.character.escape + settings + + foreground + #0997b3 + + + + name + Embedded + scope + punctuation.section.embedded, variable.interpolation + settings + + foreground + + + + + name + Illegal + scope + invalid.illegal + settings + + background + #e06c75 + foreground + #fafafa + + + + name + Broken + scope + invalid.broken + settings + + background + #e5c07b + foreground + #fafafa + + + + name + Deprecated + scope + invalid.deprecated + settings + + background + #e5c07b + foreground + #fafafa + + + + name + Unimplemented + scope + invalid.unimplemented + settings + + background + #c678dd + foreground + #fafafa + + + + + \ No newline at end of file diff --git a/assets/syntaxes/Pseudo.sublime-syntax b/assets/syntaxes/Pseudo.sublime-syntax new file mode 100644 index 0000000..437715d --- /dev/null +++ b/assets/syntaxes/Pseudo.sublime-syntax @@ -0,0 +1,131 @@ +%YAML 1.2 +--- +name: Pseudocode +file_extensions: + - psd + - pseudo + - pseudocode +scope: source.pseudocode +version: 2 + +variables: + control_keywords: '\b(?i:(IF|THEN|ELSE|END_IF|WHILE|DO|END_WHILE|END_DO|FOR|FROM|TO|DOWNTO|BEGIN|END|IN|RETURN|BREAK|CONTINUE|EXIT))\b' + declaration_keywords: '\b(?i:(GLOBAL|DEF|PROCEDURE|PROCESS|RETURNS))\b' + io_keywords: '\b(?i:(INPUT|OUTPUT|REGISTER|READ|KEYWORD|ARGUMENT|PRINT|PRINTS))\b' + logical_keywords: '\b(?i:(AND|OR))\b' + boolean_keywords: '\b(?i:(TRUE|FALSE))\b' + builtin_keywords: '\b(?i:(LEN|LENGTH|MIN|MAX|ABS|ROUND))\b' + basic_types: '\b(?i:(INT|STRING|BOOL|BOOLEAN|FLOAT|DOUBLE|CHAR|VOID|LIST|ARRAY|DICT|DICTIONARY|SET|MAP|TUPLE|STACK|QUEUE|MUTEX))\b' + number: '\b\d+(?:\.\d+)?\b' + identifier: '[A-Za-z_][A-Za-z0-9_]*' + +contexts: + prototype: + - include: at_escape + + main: + - include: comments + - include: strings + - include: math_inline + - include: function_definitions + - include: keywords + - include: operators + - include: function_calls + - include: numbers + + function_definitions: + - match: '(?i)\b(DEF|PROCEDURE)\b(\s+)({{identifier}})(\s*)(\()' + captures: + 1: storage.type.function.pseudocode + 2: text.whitespace + 3: entity.name.function.pseudocode + 4: text.whitespace + 5: punctuation.section.group.begin.pseudocode + + function_calls: + - match: '\b(?i:(LEN|MIN))\b(?=\s*\()' + scope: support.function.builtin.pseudocode + - match: '\b{{identifier}}\b(?=\s*\()' + scope: variable.function.pseudocode + + keywords: + - match: '{{basic_types}}' + scope: storage.type.pseudocode + - match: '{{logical_keywords}}' + scope: keyword.operator.logical.pseudocode + - match: '{{boolean_keywords}}' + scope: constant.language.boolean.pseudocode + - match: '{{builtin_keywords}}' + scope: support.function.builtin.pseudocode + - match: '{{declaration_keywords}}' + scope: storage.type.function.pseudocode + - match: '{{io_keywords}}' + scope: support.function.builtin.pseudocode + - match: '{{control_keywords}}' + scope: keyword.control.pseudocode + + operators: + - match: '(?:<<=|>>=|\+=|-=|\*=|/=|%=|&=|\|=|\^=|\+\+|--)' + scope: keyword.operator.assignment.pseudocode + - match: '=(?!=)' + scope: keyword.operator.assignment.pseudocode + - match: '(?:<=|<|>=|>|===|!==|==|!=)' + scope: keyword.operator.comparison.pseudocode + + numbers: + - match: '{{number}}' + scope: constant.numeric.pseudocode + + comments: + - match: '(?:\/\/|\#|\-\-|\;|REM\b)' + scope: punctuation.definition.comment.pseudocode + push: line_comment + - match: '/\*' + scope: punctuation.definition.comment.begin.pseudocode + push: block_comment + + line_comment: + - meta_scope: comment.line.double-slash.pseudocode + - match: '$' + pop: true + + block_comment: + - meta_scope: comment.block.pseudocode + - match: '\*/' + scope: punctuation.definition.comment.end.pseudocode + pop: true + + strings: + - match: '"' + scope: punctuation.definition.string.begin.pseudocode + push: double_quoted_string + + double_quoted_string: + - meta_content_scope: string.quoted.double.pseudocode + - match: '\\.' + scope: constant.character.escape.pseudocode + - match: '"' + scope: punctuation.definition.string.end.pseudocode + pop: true + + at_escape: + - match: '@' + scope: punctuation.section.embedded.begin.pseudocode + push: escaped_region + + escaped_region: + - meta_content_scope: meta.embedded.escape.pseudocode + - match: '@' + scope: punctuation.section.embedded.end.pseudocode + pop: true + + math_inline: + - match: '\$' + scope: punctuation.section.embedded.begin.pseudocode + push: math_inline_body + + math_inline_body: + - meta_content_scope: meta.embedded.math.pseudocode + - match: '\$' + scope: punctuation.section.embedded.end.pseudocode + pop: true diff --git a/examples/base.typ b/examples/base.typ new file mode 100644 index 0000000..7a66754 --- /dev/null +++ b/examples/base.typ @@ -0,0 +1,103 @@ +#import "@preview/clean-sheets:0.2.2": Cal, base-template, ex_box, qed + +#show: body => base-template( + 1, + [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, + body, +) + += Exercise 1 + +#ex_box( + heading: [#lorem(5)], + points: [$5 + 10 + 5$ Points], +)[ + #lorem(30) + + + #lorem(10) + + + #lorem(15) + - #lorem(10) + - #lorem(12) + + + #lorem(8) + + #lorem(40) +] + +#lorem(59)#footnote[#lorem(21)] +$ + (a + b)^n = sum_(k = 0)^n binom(n, k) space.thin a^(n - k) b^k +$ + +#lorem(30) #qed + += Exercise 2 + +#ex_box(points: [$25$ Points])[ + #lorem(41) + + #lorem(26) +] + +#lorem(17) $-pi/2 < arctan(x) := integral_0^x (dif t) / (1 + t^2) < pi/2 space forall x in RR$. #lorem(24) + +$ + V(x_1, ..., x_n) := mat( + 1, x_1, x_1^2, dots.c, x_1^(n-1); + 1, x_2, x_2^2, dots.c, x_2^(n-1); + 1, x_3, x_3^2, dots.c, x_3^(n-1); + dots.v, dots.v, dots.v, dots.down, dots.v; + 1, x_n, x_n^2, dots.c, x_n^(n-1) + ) +$ + +#lorem(20) + +$ + 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(30) #qed + += Exercise 3 + +#ex_box(heading: [#lorem(8)])[ + #lorem(20) + + #lorem(30) +] + +```js +#!/usr/bin/env node +/* block comment */ // line comment +const π = 0xFF + 0b1010 + 0o755 + 1_000 + 1.2e-3, nil = null, nope = undefined; +let str = "double\n\"quote\"", s = 'single\'quote', tpl = `template ${π ?? 42} \`tick\``; +const re = /(?<=foo)[a-z\d_-]+?(?=bar)/giu; +const obj = { key: true, ["computed-"+π]: false, nested: { ...{x: 1} } }; +const fn = async (x = 0) => x?.foo?.(π) ?? (() => { throw new Error("💥"); })(); +class Ω extends Array { #private = 1; static get x() { return this?.name; } } +if (π >= 0 && π !== Infinity || !NaN) for (const [k,v] of Object.entries(obj)) console.log(k, v); +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 diff --git a/examples/computer-science.typ b/examples/computer-science.typ new file mode 100644 index 0000000..0f967a0 --- /dev/null +++ b/examples/computer-science.typ @@ -0,0 +1,47 @@ +#import "@preview/clean-sheets:0.2.2": Cal, chevrons, computer-science-template, def, ex_box, qed, satz + +#show: body => computer-science-template( + [Exemplarische Grundlagen I], + ( + ([Max Mustermann], [1234567]), + ([Erika Musterfrau], [7654321]), + ), + [Wintersemester 2025/26], + [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), + group-digits: true, + decimal-comma: true, + body, +) + + += Aufgabe 1 + +#ex_box( + heading: [Aufgabe 1], + points: [10 Punkte], +)[ + Zeigen Sie eine einfache Aussage über Listen. +] + +```pseudo +DEF magic_recursive(string s, string p): + IF len(p) == 0 THEN return TRUE + IF len(s) == 0 OR p[0] != s[0] THEN return FALSE + return magic_recursive(s[1:], p[1:]) +``` + +#table( + columns: 6, + + [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], +) diff --git a/lib.typ b/lib.typ new file mode 100644 index 0000000..2c3c00a --- /dev/null +++ b/lib.typ @@ -0,0 +1,6 @@ +#import "src/templates/base.typ": base-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/components/boxes.typ": axiom, def, ex_box, kor, lemma, satz +#import "src/theme.typ": smallcaps, upper diff --git a/src/components/boxes.typ b/src/components/boxes.typ new file mode 100644 index 0000000..76c2080 --- /dev/null +++ b/src/components/boxes.typ @@ -0,0 +1,144 @@ +#import "../theme.typ": colors, statement-colors + +#let _box(header, body, color) = block( + inset: 12pt, + radius: 3pt, + width: 100%, + fill: rgb(..color, 10), + stroke: ( + left: (paint: rgb(..color), thickness: 2pt), + rest: (paint: rgb(..color, 155), thickness: 0.6pt), + ), + breakable: false, + [ + #text(rgb(..color))[#header] #body + ], +) + +#let _stmt(kind, body, color, label: [], nobreak: false) = 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 } + + let statement = counter( + "statement-" + str(x) + "-" + str(y), + ) + + let lbl = if label != [] { [ (#label)] } else { [] } + let brk = if nobreak { "" } else { [\ ] } + + [ + #statement.step() + + #context { + let mark = statement.display( + z => numbering("1.1.1", x, y, z), + ) + + _box( + [*#kind #mark*#lbl*.* #brk], + body, + color, + ) + } + ] +} + +#let def(body, label: [], nobreak: false) = _stmt( + "Definition", + body, + statement-colors.definition, + label: label, + nobreak: nobreak, +) + +#let axiom(body, label: [], nobreak: false) = _stmt( + "Axiom", + body, + statement-colors.axiom, + label: label, + nobreak: nobreak, +) + +#let satz(body, label: [], nobreak: false) = _stmt( + "Satz", + body, + statement-colors.theorem, + label: label, + nobreak: nobreak, +) + +#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( + body, + heading: [], + points: [], + color: colors.accent, + stroke-color: colors.stroke, + text-color: colors.text, + radius: 5pt, +) = context { + let background = color.lighten(95%) + + let label-box = content => block( + fill: white, + stroke: stroke-color + 0.4pt, + radius: radius * 0.75, + inset: 5pt, + text(text-color, content), + ) + + let head = if heading != [] or points != [] { + if heading != [] { + let b = label-box(heading) + place(dy: -measure(b).height / 2 - 12pt, b) + } + + if points != [] { + let b = label-box(points) + place( + dy: -measure(b).height / 2 - 12pt, + box(width: 100%, align(right)[#b]), + ) + } + + v(0.5em) + } else { [] } + + if head != [] { v(1em) } + + block( + fill: background, + stroke: ( + left: color + 1.7pt, + top: stroke-color + 0.4pt, + right: stroke-color + 0.6pt, + bottom: stroke-color + 0.6pt, + ), + width: 100%, + radius: radius, + inset: 12pt, + above: 12pt, + below: 18pt, + [ + #set enum(numbering: "(i)") + #head + #body + ], + ) +} diff --git a/src/components/student-table.typ b/src/components/student-table.typ new file mode 100644 index 0000000..738ccfe --- /dev/null +++ b/src/components/student-table.typ @@ -0,0 +1,49 @@ +#let _student-names(students) = { + if type(students) == str { + students + } else { + students.join(", ") + } +} + +#let exercise-overview(exercises, students, tutor, col: black, border: gray, tutor-label: none) = { + let text-color = col.darken(25%) + let _s = 0.4pt + border + + set par(justify: false) + + grid( + columns: (1fr, 1fr), + column-gutter: 1em, + stroke: (bottom: 0.5pt + text-color), + inset: (y: 0.75em), + align: bottom, + grid( + columns: 2, + column-gutter: 1em, + text(fill: text-color)[Name:], _student-names(students), + ), + grid( + columns: 2, + column-gutter: 1em, + text(fill: text-color)[#if tutor-label != none { tutor-label } else { [Tutor:] }], tutor, + ), + ) + + let ex_cells = () + for i in range(1, exercises + 1) { + ex_cells += (table.cell(stroke: (right: _s, bottom: _s))[A#i],) + } + + v(0.75cm) + + set text(fill: text-color) + table( + columns: (1fr,) * (exercises + 1), + align: center, + stroke: none, + ..ex_cells, + table.cell(stroke: (bottom: _s))[$Sigma$], + ..(table.cell(stroke: (right: _s), inset: (y: 0.75em))[],) * exercises, + ) +} diff --git a/src/config.typ b/src/config.typ new file mode 100644 index 0000000..107d864 --- /dev/null +++ b/src/config.typ @@ -0,0 +1,20 @@ +#let custom-raw-syntaxes = ( + "../../assets/syntaxes/Pseudo.sublime-syntax", +) + +#let weekdays-short-de = ("Mo", "Di", "Mi", "Do", "Fr", "Sa", "So") +#let months-de = ( + "Januar", + "Februar", + "März", + "April", + "Mai", + "Juni", + "Juli", + "August", + "September", + "Oktober", + "November", + "Dezember", +) + diff --git a/src/helpers.typ b/src/helpers.typ new file mode 100644 index 0000000..4f3a2ce --- /dev/null +++ b/src/helpers.typ @@ -0,0 +1,68 @@ +#import "config.typ": months-de, weekdays-short-de +#import "theme.typ": fonts + +#let Cal(body) = math.class( + "normal", + text(font: fonts.cmu-math, math.cal(body)), +) + +#let Complement = math.class( + "normal", + text(font: fonts.cmu-math, math.complement), +) + +#let qed = [#h(1fr) $square$] +#let jb = linebreak(justify: true) + +#let chevrons(..children) = { + let body = children.pos().join(", ") + math.lr([$chevron.l #body chevron.r$]) +} + +#let german-date-time(value) = [#{ weekdays-short-de.at(int(value.display("[weekday repr:monday]")) - 1) }., + #{ value.day() }. #{ months-de.at(int(value.display("[month]")) - 1) }, + #value.display("[hour]") Uhr] + +#let group-digits-text(value, sep: sym.space.nobreak.narrow) = { + let chars = value.clusters() + let n = chars.len() + + for (i, ch) in chars.enumerate() { + if i > 0 and calc.rem(n - i, 3) == 0 { + sep + } + ch + } +} + +#let content-to-string(content) = { + if type(content) == str { + content + } else if content.has("text") { + if type(content.text) == str { + content.text + } else { + content-to-string(content.text) + } + } else if content.has("children") { + content.children.map(content-to-string).join("") + } else if content.has("body") { + content-to-string(content.body) + } else if content == [] { + " " + } +} + +#let render-footnote-entry(entry, numbering-pattern: "[1]") = { + let loc = entry.note.location() + let mark = numbering(numbering-pattern + ":", ..counter(footnote).at(loc)) + + pad(left: entry.indent)[ + #grid( + columns: (auto, 1fr), + gutter: 0.3em, + mark, + entry.note.body, + ) + ] +} diff --git a/src/templates/base.typ b/src/templates/base.typ new file mode 100644 index 0000000..37bc621 --- /dev/null +++ b/src/templates/base.typ @@ -0,0 +1,143 @@ +#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 "../components/student-table.typ": exercise-overview + +/// Base template for exercise sheets. +#let base-template( + sheetnumber, + course, + prof, + assistant, + exercises, + students, + tutor, + tutor-label: none, + sheet: [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, + 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) + + set document( + title: ttl, + description: course, + author: students.map(content-to-string), + date: datetime.today(), + ) + + let font-size = base-theme.font-size + + set page( + numbering: page-numbering, + header: context { + if counter(page).get().first() > 1 [ + #set text(base-theme.header-size, weight: 450) + #grid( + columns: (2fr, 1fr, 2fr), + align: (start, center, end), + + course, text(fill: colors.text)[#ttl], (prof, assistant).join([#h(0.25em)·#h(0.25em)]), + ) + #line(length: 100%, stroke: 0.4pt + colors.stroke) + ] + }, + ) + + set par(..common-theme.paragraph) + set text(font: text-font, size: font-size, lang: common-theme.lang) + show math.equation: set text(font: math-font) + + show heading.where(level: 1): set text(..base-theme.heading-1) + show heading.where(level: 2): set text(..base-theme.heading-2) + + show heading: set text(fill: colors.text) + let first-h1 = state("first-h1", true) + show heading.where(level: 1): it => { + if first-h1.get() { + first-h1.update(false) + } else { + // pagebreak(weak: true) + } + v(0.3em) + it + v(-0.9em) + line(length: 100%, stroke: 0.4pt + colors.stroke) + v(0.3em) + } + + set footnote(numbering: common-theme.footnote.numbering.note) + set footnote.entry( + indent: common-theme.footnote.indent, + separator: line(length: 30% + 0pt, stroke: 0.4pt + colors.text), + ) + show footnote.entry: it => render-footnote-entry( + it, + numbering-pattern: common-theme.footnote.numbering.text, + ) + + set raw(syntaxes: custom-raw-syntaxes, tab-size: code-theme.tab-size, theme: code-theme.theme) + + show raw: set text( + font: code-theme.font, + features: code-theme.features, + size: font-size - code-theme.size-offset, + ) + + 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 { + [] + } else { + logo + } + + show title: set text(fill: colors.text, weight: base-theme.title-weight) + + [ + #grid( + columns: (6fr, 1fr), + align: (start + horizon, end + horizon), + row-gutter: 0.25cm, + [ + #title[#sheet #if sheetnumber < 10 { "0" };#sheetnumber] + ], + logo-content, + + grid.cell( + colspan: 2, + align: center, + stroke: (y: 0.4pt + colors.stroke), + inset: (y: 0.5cm), + )[*#course* \ #(prof, assistant).join([#h(0.5em)·#h(0.5em)])], + ) + + #exercise-overview(exercises, students, tutor, col: colors.accent, border: colors.stroke, tutor-label: tutor-label) + ] + + show figure.where(kind: table): set block(breakable: true) + + set table(..common-theme.table) + + show table.cell.where(y: 0): it => if table-header-smallcaps { smallcaps(it) } else { it } + + body + + if show-end-message { + v(1fr) + + set text(size: 10pt) + align(center)[#end-message] + } +} diff --git a/src/templates/computer-science.typ b/src/templates/computer-science.typ new file mode 100644 index 0000000..8895111 --- /dev/null +++ b/src/templates/computer-science.typ @@ -0,0 +1,153 @@ +#import "../config.typ": custom-raw-syntaxes +#import "../theme.typ": code-theme, common-theme, computer-science-theme, smallcaps +#import "../helpers.typ": german-date-time, group-digits-text, render-footnote-entry + +/// Computer science exercise sheet template. +#let computer-science-template( + sheetnumber: 0, + subtitle: none, + course, + students, + semester, + 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, + info-text: none, + text-font: computer-science-theme.text-font, + math-font: computer-science-theme.math-font, + table-header-smallcaps: false, + no-pagebreak: false, + body, +) = { + let font-size = computer-science-theme.font-size + + set page( + header: context { + if counter(page).get().first() > 1 [ + #set text(computer-science-theme.header-size) + #grid( + columns: (3fr, 2fr, 3fr), + align(start)[_#course _], + align(center)[*Übungsblatt #sheetnumber*], + align(end)[#students.map(((name, matrNr)) => name).join(", ")], + ) + #line(length: 100%, stroke: 0.4pt + computer-science-theme.divider) + ] + }, + numbering: page-numbering, + ) + + set par(..common-theme.paragraph) + set text(font: text-font, size: font-size, lang: common-theme.lang) + show math.equation: set text(font: math-font) + + let first-h1 = state("first-h1", true) + show heading.where(level: 1): it => { + if first-h1.get() { + first-h1.update(false) + } else { + if (not no-pagebreak) { + pagebreak(weak: true) + } + } + it + } + + set footnote(numbering: common-theme.footnote.numbering.note) + set footnote.entry(indent: common-theme.footnote.indent) + show footnote.entry: it => render-footnote-entry( + it, + numbering-pattern: common-theme.footnote.numbering.text, + ) + + set raw(syntaxes: raw-syntaxes, tab-size: code-theme.tab-size, theme: code-theme.theme) + + show raw: set text( + font: code-theme.font, + features: code-theme.features, + size: font-size - code-theme.size-offset, + ) + + show raw.where(block: true): box.with(..computer-science-theme.raw-block) + show raw.where(block: false): box.with(..code-theme.inline) + + show figure.where(kind: table): set block(breakable: true) + + set table(..common-theme.table) + + show table.cell.where(y: 0): it => if table-header-smallcaps { smallcaps(it) } else { it } + + show math.equation: it => { + show regex("\\d+\\.\\d+"): it => if decimal-comma { + show ".": { "," + h(0pt) } + it + } else { it } + it + } + + let digit-grouping = state("digit-grouping", group-digits) + + let no-digit-grouping(body) = context { + let was-enabled = digit-grouping.get() + digit-grouping.update(false) + body + digit-grouping.update(was-enabled) + } + + show regex("\\b\\d{4,}\\b"): it => context { + if digit-grouping.get() { + group-digits-text(it.text) + } else { + it + } + } + + [ + #grid( + columns: (1fr, 1fr), + align(start)[ + *#course* \ + #students.map(((name, matrNr)) => [#name (#no-digit-grouping[#matrNr])]).join(linebreak()) + ], + align(horizon + right)[ + *#no-digit-grouping[#semester]* \ + #university \ + #institute \ + #if department != none [#department] + ], + ) + + #v(0.2cm) + #line(length: 100%, stroke: 0.4pt + computer-science-theme.divider) + #v(0.3cm) + + #align(center)[ + #title[Bearbeitung des #sheetnumber. Übungsblatts] + #if subtitle != none [== #subtitle #v(1em)] + ] + ] + + v(2em) + + [ + #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 info-text != none [#info-text] + ] + + body +} + diff --git a/src/theme.typ b/src/theme.typ new file mode 100644 index 0000000..8fa0dba --- /dev/null +++ b/src/theme.typ @@ -0,0 +1,111 @@ +#let std-smallcaps = smallcaps +#let std-upper = upper + +#let smallcaps(body, std: false) = if (std) { std-smallcaps(body) } else { std-smallcaps(text(tracking: 0.6pt, body)) } +#let upper(body) = std-upper(text(tracking: 0.6pt, body)) + +#let colors = ( + accent: eastern, + text: eastern.darken(25%), + stroke: eastern.lighten(50%), + code-border: gray, + code-inline-border: rgb("CCCCCC"), + code-block-fill: luma(98.75%), + code-inline-fill: luma(96%), +) + +#let fonts = ( + base: "New Computer Modern", + base-math: "New Computer Modern Math", + cmu: "New Computer Modern", + cmu-math: "New Computer Modern Math", + code: "DejaVu Sans Mono", +) + +#let code-text-features = ( + calt: 1, + cv02: 1, // g + cv04: 1, // i + cv06: 1, + cv08: 1, // l + cv16: 1, + ss01: 1, // r + ss02: 1, // >= + ss03: 1, + ss04: 1, + ss05: 1, + ss06: 1, + ss08: 1, + zero: 1, // 0 +) + +#let default-page-numbering = (..nums) => [ + #set text(size: 10pt) + *#nums.at(0)* / #nums.at(-1) +] + +#let common-theme = ( + lang: "de", + page-numbering: default-page-numbering, + paragraph: (justify: true), + footnote: ( + numbering: (text: "[1]", note: "1"), + indent: 1em, + ), + table: ( + inset: 7pt, + stroke: 0.5pt + colors.stroke, + ), +) + +#let code-theme = ( + font: fonts.code, + features: code-text-features, + tab-size: 4, + size-offset: 2.5pt, + block: ( + stroke: 0.4pt + colors.code-border, + fill: colors.code-block-fill, + radius: 0.2em, + inset: (x: 1.25em, y: 1em), + width: 100%, + ), + inline: ( + stroke: 0.4pt + colors.code-inline-border, + fill: colors.code-inline-fill, + inset: (x: 3pt, y: 0pt), + outset: (y: 3pt), + radius: 2pt, + ), + theme: "../../assets/OneHalfLight.tmTheme", +) + +#let base-theme = ( + font-size: 12pt, + text-font: fonts.base, + math-font: fonts.base-math, + header-size: 8.5pt, + heading-1: (size: 18pt, weight: 300), + heading-2: (weight: 380), + title-weight: 300, + raw-block: code-theme.block, +) + +#let computer-science-theme = ( + font-size: 10.5pt, + text-font: fonts.cmu, + math-font: fonts.cmu-math, + header-size: 10pt, + divider: black, + 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 statement-colors = ( + definition: (247, 57, 72), + axiom: (247, 92, 37), + theorem: (100, 100, 255), + lemma: (22, 147, 220), + corollary: (157, 82, 255), +) diff --git a/template/main.typ b/template/main.typ new file mode 100644 index 0000000..4e33564 --- /dev/null +++ b/template/main.typ @@ -0,0 +1,55 @@ +#import "@preview/clean-sheets:0.2.2": base-template, ex_box, qed + +#let logo = box( + width: 2.4cm, + height: 1cm, + stroke: 0.8pt + eastern, + radius: 3pt, + align(center + horizon, text(fill: eastern, weight: "bold")[LOGO]), +) + +#show: body => base-template( + 1, + [Introduction to Examples], + [Prof. Ada Example], + [Dr. Alan Assistant], + 3, + ([Jane Doe], [John Doe]), + [Taylor Tutor], + logo: logo, + body, +) + += Exercise 1 + +#ex_box( + heading: [Warm-up], + points: [10 points], +)[ + Prove the following identity for every natural number $n$: + $ + sum_(k=1)^n k = (n (n + 1)) / 2. + $ +] + +Write a proof by induction. #qed + += Exercise 2 + +#ex_box(points: [15 points])[ + Implement a function that returns the first $n$ Fibonacci numbers. +] + +```python +def fibonacci(n): + values = [0, 1] + while len(values) < n: + values.append(values[-1] + values[-2]) + return values[:n] +``` + += Exercise 3 + +#ex_box(heading: [Discussion])[ + Compare the iterative and recursive solutions. +] diff --git a/thumbnail.png b/thumbnail.png new file mode 100644 index 0000000..1bc6008 Binary files /dev/null and b/thumbnail.png differ diff --git a/typst.toml b/typst.toml new file mode 100644 index 0000000..ed1b02b --- /dev/null +++ b/typst.toml @@ -0,0 +1,18 @@ +[package] +name = "clean-sheets" +version = "0.2.2" +compiler = "0.15.0" +repository = "https://git.p0pa.de/Popa/clean-sheets" +entrypoint = "lib.typ" +authors = ["Popa "] +categories = ["layout", "components", "report"] +disciplines = ["education", "mathematics", "computer-science"] +license = "MIT" +description = "Clean exercise sheets for university courses." +keywords = ["exercise sheets", "homework", "university", "education"] +exclude = ["/examples/"] + +[template] +path = "template" +entrypoint = "main.typ" +thumbnail = "thumbnail.png"