enable customizing exercise numbering
This commit is contained in:
parent
921082f61d
commit
c81d8f65b2
2 changed files with 40 additions and 4 deletions
33
README.md
33
README.md
|
|
@ -18,7 +18,7 @@ A summary is then printed on the front page.
|
||||||
|
|
||||||
## Usage
|
## 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
|
#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.
|
- `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,
|
- `frame(stroke_width)` provides `stroke` for use in a `table`, horizontal lines only,
|
||||||
top and bottom lines are bold.
|
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",
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
||||||
11
lib.typ
11
lib.typ
|
|
@ -103,25 +103,26 @@
|
||||||
// Used to compute the overview table (see below)
|
// Used to compute the overview table (see below)
|
||||||
// title: string, title of the exercise
|
// title: string, title of the exercise
|
||||||
// points: int, the number of points the exercise is worth
|
// 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)
|
// state("exercise_points").update(points)
|
||||||
let exercise_counter = counter("exercise")
|
let exercise_counter = counter("exercise")
|
||||||
exercise_counter.step()
|
exercise_counter.step()
|
||||||
context {
|
context {
|
||||||
let current_exercise = exercise_counter.get().at(0)
|
let current_exercise = exercise_counter.get().at(0)
|
||||||
|
let exercise-numbering = state("exercise-numbering").get()
|
||||||
let exercise_registry = state("exercise-registry")
|
let exercise_registry = state("exercise-registry")
|
||||||
let final_points = 0
|
let final_points = 0
|
||||||
if (exercise_registry.final().len() >= current_exercise) {
|
if (exercise_registry.final().len() >= current_exercise) {
|
||||||
final_points = exercise_registry.final().at(exercise_counter.get().at(0)-1).at(2)
|
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),))
|
exercise_registry.update(entries => entries + ((exercise_label, title, points),))
|
||||||
block(radius: 1cm, stroke: none, fill: lightgray, inset: 1pt,
|
block(radius: 1cm, stroke: none, fill: lightgray, inset: 1pt,
|
||||||
table(
|
table(
|
||||||
columns: (auto, 1fr, auto),
|
columns: (auto, 1fr, auto),
|
||||||
align: (left, center, right),
|
align: (left, center, right),
|
||||||
stroke: none,
|
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,
|
font-size: 12pt,
|
||||||
paper-size: "a4",
|
paper-size: "a4",
|
||||||
|
|
||||||
|
exercise-numbering: "1",
|
||||||
|
|
||||||
body
|
body
|
||||||
) = {
|
) = {
|
||||||
|
|
||||||
|
|
@ -159,6 +162,8 @@
|
||||||
set page(paper: paper-size)
|
set page(paper: paper-size)
|
||||||
set text(size: font-size, lang: language, hyphenate: true)
|
set text(size: font-size, lang: language, hyphenate: true)
|
||||||
|
|
||||||
|
state("exercise-numbering").update(exercise-numbering)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Localization
|
* Localization
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue