From e97c53be664f60a47f815412fa1f0e998b533b1b Mon Sep 17 00:00:00 2001 From: ReeseHatfield Date: Fri, 4 Dec 2026 10:51:22 -0500 Subject: [PATCH 1/4] prototype --- examples/exam_example.typ | 19 ++++++++++++++++++ src/exams.typ | 42 +++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/examples/exam_example.typ b/examples/exam_example.typ index bf5d974..0a4de0e 100644 --- a/examples/exam_example.typ +++ b/examples/exam_example.typ @@ -454,3 +454,22 @@ Fill in some code below: ) ```, width: 100%) + + + +#e.question-block([Use the block to answer the following questions:], + () => e.short-answer( + "What is the time complexity of the method shown above?", + lines: 2, + points: 2 + ), + () => e.multiple-choice( + "Which data structure would optimize this code?", + points: 1, + cols: 2, + [Array List], + [Hash Map], + [Linked List], + [Binary Tree] + ) +) \ No newline at end of file diff --git a/src/exams.typ b/src/exams.typ index 92f6597..4be4554 100644 --- a/src/exams.typ +++ b/src/exams.typ @@ -106,6 +106,10 @@ "num-qs", 1 ) +#let cur-sub-question = counter( + "sub-question-n" +) + /// question: Create a generic question /// - body (content, str): Question Body @@ -121,15 +125,33 @@ message: "Expected points to be int, but received" + str(type(points)) ) - cur-question.update(n => n + 1) total-points.update(p => p + points) - let qnum = cur-question.get() - + let q-num = cur-question.get() + + + + // counters return an array, despite only having 1 value + // this relies that is set in question-block + let sub-val = cur-sub-question.get().at(0) + let has-sub = sub-val != 0 + + let sub-label = if has-sub { + [#cur-sub-question.display("A")] + } else { + none + } + + // only update the q num if the question has NO sub questions + if not has-sub { + cur-question.update(n => n + 1) + } + block(width: 100%, breakable: true, inset: (bottom: 0.5em))[ #grid( columns: (20pt, 1fr), column-gutter: 8pt, - text(weight: "bold")[#qnum.], + // TIL ~ is a non-breaking space + text(weight: "bold")[#q-num~#sub-label.], [#body #h(5pt) (#points pts)] ) ] @@ -499,3 +521,15 @@ } + +#let question-block(q-body, ..questions) = { + cur-sub-question.update(1) + + for q in questions.pos() { + q() + cur-sub-question.step() + } + + cur-sub-question.update(0) +} + From c866336d0a72b57e1bf790f2c48668ccdaa77ff9 Mon Sep 17 00:00:00 2001 From: ReeseHatfield Date: Fri, 4 Dec 2026 10:53:44 -0500 Subject: [PATCH 2/4] fix bug in future questions --- examples/exam_example.typ | 15 +++++++++++++++ src/exams.typ | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/examples/exam_example.typ b/examples/exam_example.typ index 0a4de0e..59b3340 100644 --- a/examples/exam_example.typ +++ b/examples/exam_example.typ @@ -472,4 +472,19 @@ Fill in some code below: [Linked List], [Binary Tree] ) +) + +#e.tf-block([Mark the following statements as either True (T) of False (F):], points: 5, + [```java LinkedList``` utilizes nodes and next pointers to store information], // T + [```java ArrayList``` is always faster than ```java LinkedList```], // F + [```java ArrayList``` has more flexible memory usage than ```java LinkedList```], // F + [```java ArrayList``` and ```java LinkedList``` implement the same ADT], // T + [```java ArrayList```s are faster than ```java LinkedList```s at retrieval operations], // T +) +#e.tf-block([Mark the following statements as either True (T) of False (F):], points: 5, + [```java LinkedList``` utilizes nodes and next pointers to store information], // T + [```java ArrayList``` is always faster than ```java LinkedList```], // F + [```java ArrayList``` has more flexible memory usage than ```java LinkedList```], // F + [```java ArrayList``` and ```java LinkedList``` implement the same ADT], // T + [```java ArrayList```s are faster than ```java LinkedList```s at retrieval operations], // T ) \ No newline at end of file diff --git a/src/exams.typ b/src/exams.typ index 4be4554..334e514 100644 --- a/src/exams.typ +++ b/src/exams.typ @@ -523,6 +523,7 @@ #let question-block(q-body, ..questions) = { + // basically just a wrapper, that manages some state for the question() function cur-sub-question.update(1) for q in questions.pos() { @@ -530,6 +531,11 @@ cur-sub-question.step() } + // disable sub-question state + // and keep the cur-question moving + cur-question.update(n => n + 1) cur-sub-question.update(0) + + } From 2569c243b33f14b9293498a94322ed91ece19c86 Mon Sep 17 00:00:00 2001 From: ReeseHatfield Date: Fri, 4 Dec 2026 10:55:30 -0500 Subject: [PATCH 3/4] update examples --- examples/exam_example.typ | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/examples/exam_example.typ b/examples/exam_example.typ index 59b3340..b56c05b 100644 --- a/examples/exam_example.typ +++ b/examples/exam_example.typ @@ -432,15 +432,6 @@ Use the code block to answer the following questions: [```java ArrayList```s are faster than ```java LinkedList```s at retrieval operations], // T ) -#e.tf-block([Mark the following statements as either True (T) of False (F):], points: 5, - [```java LinkedList``` utilizes nodes and next pointers to store information], // T - [```java ArrayList``` is always faster than ```java LinkedList```], // F - [```java ArrayList``` has more flexible memory usage than ```java LinkedList```], // F - [```java ArrayList``` and ```java LinkedList``` implement the same ADT], // T - [```java ArrayList```s are faster than ```java LinkedList```s at retrieval operations], // T -) - - Fill in some code below: #code-block( @@ -457,6 +448,18 @@ Fill in some code below: +#pagebreak() +#e.tf-block([Mark the following statements as either True (T) of False (F):], points: 5, + [```java LinkedList``` utilizes nodes and next pointers to store information], // T + [```java ArrayList``` is always faster than ```java LinkedList```], // F + [```java ArrayList``` has more flexible memory usage than ```java LinkedList```], // F + [```java ArrayList``` and ```java LinkedList``` implement the same ADT], // T + [```java ArrayList```s are faster than ```java LinkedList```s at retrieval operations], // T +) + + + + #e.question-block([Use the block to answer the following questions:], () => e.short-answer( "What is the time complexity of the method shown above?", @@ -487,4 +490,6 @@ Fill in some code below: [```java ArrayList``` has more flexible memory usage than ```java LinkedList```], // F [```java ArrayList``` and ```java LinkedList``` implement the same ADT], // T [```java ArrayList```s are faster than ```java LinkedList```s at retrieval operations], // T -) \ No newline at end of file +) + +#e.question("Please write your favorite algorithm below:", points: 4) \ No newline at end of file From 511f69d6201341f1ba0d93faa8dc404e6eff4217 Mon Sep 17 00:00:00 2001 From: ReeseHatfield Date: Fri, 4 Dec 2026 11:02:30 -0500 Subject: [PATCH 4/4] formatting --- src/exams.typ | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/exams.typ b/src/exams.typ index 334e514..fa25516 100644 --- a/src/exams.typ +++ b/src/exams.typ @@ -128,8 +128,6 @@ total-points.update(p => p + points) let q-num = cur-question.get() - - // counters return an array, despite only having 1 value // this relies that is set in question-block let sub-val = cur-sub-question.get().at(0)