From c81d8f65b213e299100f1c940a878adda516c063 Mon Sep 17 00:00:00 2001 From: Gaspard Jankowiak Date: Mon, 17 Nov 2025 20:56:12 +0100 Subject: [PATCH] enable customizing exercise numbering --- README.md | 33 ++++++++++++++++++++++++++++++++- lib.typ | 11 ++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a739df5..5e796c0 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ A summary is then printed on the front page. ## Usage -Writing an exam is now easy: +Writing an exam is now easy (see [API](#api) for all options): #import "@local/exam:0.1.0": exam, exercise, exercise-items, mtext @@ -99,3 +99,34 @@ These are used in the example above. - `mtext(str)` to typeset text within math mode using the default text font. - `frame(stroke_width)` provides `stroke` for use in a `table`, horizontal lines only, top and bottom lines are bold. + +### API + +```typ +exam( + title: "%KLAUSUR or EXAM%", + + course-title: [%COURSE_TITLE_FIRST_LINE% \ %COURSE_TITLE_SECOND_LINE%], + course-short-title: "%course-short-title%", + course-code: "%course-code%", + + date: "%DATE%", + + institution: smallcaps("NAWI Graz"), + + duration-minutes: "%DURATION%", + + ask-student-number: false, + ask-trainer-name: false, + ask-group: true, + + instructions: none, + + language: "de", // or "en" + font-size: 12pt, + paper-size: "a4", + + exercise-numbering: "1", +) +``` + diff --git a/lib.typ b/lib.typ index 476b489..a2004c6 100644 --- a/lib.typ +++ b/lib.typ @@ -103,25 +103,26 @@ // Used to compute the overview table (see below) // title: string, title of the exercise // points: int, the number of points the exercise is worth -#let exercise(title, points, numbering: "1") = { +#let exercise(title, points) = { // state("exercise_points").update(points) let exercise_counter = counter("exercise") exercise_counter.step() context { let current_exercise = exercise_counter.get().at(0) + let exercise-numbering = state("exercise-numbering").get() let exercise_registry = state("exercise-registry") let final_points = 0 if (exercise_registry.final().len() >= current_exercise) { final_points = exercise_registry.final().at(exercise_counter.get().at(0)-1).at(2) } - let exercise_label = exercise_counter.display(numbering) + let exercise_label = exercise_counter.display(exercise-numbering) exercise_registry.update(entries => entries + ((exercise_label, title, points),)) block(radius: 1cm, stroke: none, fill: lightgray, inset: 1pt, table( columns: (auto, 1fr, auto), align: (left, center, right), stroke: none, - [#rect(radius:1cm, outset: 4pt, inset: (x:2pt, y:0pt), fill: white)[*#get_L("exercise") #context{exercise_counter.display(numbering)}*]], [#title], [#rect(radius:1cm, outset: 4pt, inset: (x:2pt, y:0pt), fill: white)[*#format_points(final_points)*]], + [#rect(radius:1cm, outset: 4pt, inset: (x:2pt, y:0pt), fill: white)[*#get_L("exercise") #context{exercise_counter.display(exercise-numbering)}*]], [#title], [#rect(radius:1cm, outset: 4pt, inset: (x:2pt, y:0pt), fill: white)[*#format_points(final_points)*]], ) )}} @@ -148,6 +149,8 @@ font-size: 12pt, paper-size: "a4", + exercise-numbering: "1", + body ) = { @@ -159,6 +162,8 @@ set page(paper: paper-size) set text(size: font-size, lang: language, hyphenate: true) +state("exercise-numbering").update(exercise-numbering) + /* * Localization */