diff --git a/CHANGELOG.md b/CHANGELOG.md index 70fa9cb..4b363f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Added `begin-at-new-page` option for `task` and `subtask` - Added `skip` option for `task` and `subtask` - Added `bonus-style` option for `task` +- Added `theorem-counter-reset` option for `task` and `subtask` ## [0.4.0] - 2025-11-22 diff --git a/examples/task-config.typ b/examples/task-config.typ index 10816f8..ef89d12 100644 --- a/examples/task-config.typ +++ b/examples/task-config.typ @@ -1,4 +1,4 @@ -#import "@preview/sheetstorm:0.4.0": assignment, subtask, task +#import "@preview/sheetstorm:0.4.0": assignment, subtask, task, theorem #show: assignment.with( title: "Task Configuration Example", @@ -10,6 +10,7 @@ // You can customize the task/subtask functions like so: #let task = task.with( todo-show: false, + theorem-counter-reset: true, ) #let subtask = subtask.with( numbering: ("a.", "i."), @@ -33,8 +34,14 @@ #task(counter-show: false, name: "Name")[ You can disable the task number in the title. + + #theorem[First theorem of the task.] ] -#task(hidden: true, counter: 7)[This task is hidden in the score box.] +#task(hidden: true, counter: 7)[ + This task is hidden in the score box. + + #theorem[Also the theorem counter was automatically reset.] +] #task(skip: 1)[This would be task 8 but now it is task 9.] diff --git a/src/task.typ b/src/task.typ index b92e3cb..d7057bd 100644 --- a/src/task.typ +++ b/src/task.typ @@ -104,6 +104,8 @@ bonus-style: t => [#t (#context i18n.translate("Bonus"))], /// Whether the task is hidden in the score box. -> bool hidden: false, + /// Whether to reset the theorem counter at the start of the task. -> bool + theorem-counter-reset: false, /// Padding above the task. -> auto | length space-above: auto, /// Padding below the task. -> auto | length @@ -147,6 +149,10 @@ c("sheetstorm-todo").step() } + if theorem-counter-reset { + c("sheetstorm-theorem-count").update(1) + } + let maybe-todo = context { let curr-task = query(selector().before(here())) .last() @@ -294,6 +300,8 @@ /// /// -> bool numbering-cycle: false, + /// Whether to reset the theorem counter at the start of the subtask. -> bool + theorem-counter-reset: false, /// The minimum indent of the subtask body. /// /// The indent of the subtask body is the maximum of this value and the width of the marker. @@ -316,6 +324,8 @@ /// -> content.. ..body-args, ) = { + let c = std.counter + assert(body-args.named().len() == 0, message: "Unexpected named argument.") assert( body-args.pos().len() == 1 or body-args.pos().len() == 2, @@ -348,6 +358,10 @@ }) } + if theorem-counter-reset { + c("sheetstorm-theorem-count").update(1) + } + let marker = if marker != auto { marker } else { context { let depth = state("sheetstorm-subtask").get().len() - 1 diff --git a/tests/examples/task-config/ref/1.png b/tests/examples/task-config/ref/1.png index f285948..994c8fe 100644 Binary files a/tests/examples/task-config/ref/1.png and b/tests/examples/task-config/ref/1.png differ diff --git a/tests/examples/task-config/test.typ b/tests/examples/task-config/test.typ index 8b07012..bc66bac 100644 --- a/tests/examples/task-config/test.typ +++ b/tests/examples/task-config/test.typ @@ -1,4 +1,4 @@ -#import "@local/sheetstorm:0.4.0": assignment, subtask, task +#import "@local/sheetstorm:0.4.0": assignment, subtask, task, theorem #show: assignment.with( title: "Task Configuration Example", @@ -10,6 +10,7 @@ // You can customize the task/subtask functions like so: #let task = task.with( todo-show: false, + theorem-counter-reset: true, ) #let subtask = subtask.with( numbering: ("a.", "i."), @@ -33,8 +34,14 @@ #task(counter-show: false, name: "Name")[ You can disable the task number in the title. + + #theorem[First theorem of the task.] ] -#task(hidden: true, counter: 7)[This task is hidden in the score box.] +#task(hidden: true, counter: 7)[ + This task is hidden in the score box. + + #theorem[Also the theorem counter was automatically reset.] +] #task(skip: 1)[This would be task 8 but now it is task 9.]