iTranslated by AI
Creating Exam Answer Boxes with Typst
Since it looked interesting, I implemented something like answerbox.sty in Typst.
Usage
You can get the general idea by looking at the Example.

#anshere((
q(),
q(),
q-blank,
q-break,
..(q(),) * 3,
q-break,
q(content: [#h(1fr)m / s]),
q(content: [#h(1fr)T#h(10pt)/#h(10pt)F#h(1fr)]),
q(label: [$2x + 1$]),
q-break,
q(counter-reset: 1),
q(),
q-blank,
q-break,
q(numbering-width: 50pt),
q(hide-numbering: true)
))
Basically, you chain q(), q-break, and q-blank inside anshere().
You can create a line break with q-break and a blank space with q-blank.
You can pass various arguments to q().
-
content
Allows writing in the answer field.
You can useh(1fr)to add spacing appropriately. -
label
Allows writing in the question number field. -
counter-reset
Forcibly resets the question number. -
numbering-width
Changes the width of the question number field. -
hide-numbering
Hides the question number.
#anshere((
..(q(numbering: "a"),) * 4,
..(q-blank,) * 2,
q-break,
q(counter-reset: 1),
q(),
q(counter-skip: 1),
q(),
q(counter-skip: 1),
q(),
q-break,
q(counter-reset: 1),
q(),
q(counter-skip: -1),
q(),
q(counter-skip: -1),
q(),
q-break,
))
-
numbering
Changes the numbering style. -
counter-skip
Skips n numbers. It is recommended to use this overcounter-resetwhen possible.
#anshere((
q(children: (
q(),
q(),
q(children: (
q(),
q(),
)),
)),
))
#anshere(
(
q(children: (
q(),
q(children: (
q(),
q(children: (
q(),
q(),
)),
)),
)),
),
numberings: ("1", "1", "(1)", "あ", "a"),
)
-
children
You can nest questions to create sub-questions within sub-questions. Note that you cannot useq-breakorq-blankinside this (everything will be line-broken).
By passing numberings as an argument to anshere, you can specify the question number format collectively.
Impressions
Initially, I thought about calculating colspan and rowspan in a table, but I gave up on that and implemented it by nesting grids instead.
One issue that occurred because of the grid was that the row heights would become misaligned. For now, I've made it so that height is maintained—at least in Noto Serif CJK JP and Noto Sans CJK JP—by always displaying a zero-width space sym.zws, but it might still misalign depending on the font combination. I want to fix this properly using tables someday...
Discussion
私も数学のテストでtypstで問題と解答作りました。