Skip to content

Commit

Permalink
add gap answer
Browse files Browse the repository at this point in the history
  • Loading branch information
SillyFreak committed Oct 3, 2024
1 parent aad626f commit baf9c97
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Binary file modified docs/manual.pdf
Binary file not shown.
15 changes: 15 additions & 0 deletions docs/manual.typ
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,18 @@ Which of these answers are even?
style: tidy.styles.minimal,
)
}

== `scrutinize.task-kinds.gap`

#{
let module = tidy.parse-module(
read("/src/task-kinds/gap.typ"),
label-prefix: "gap.",
scope: scope,
)
tidy.show-module(
module,
sort-functions: none,
style: tidy.styles.minimal,
)
}
41 changes: 41 additions & 0 deletions src/task-kinds/gap.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#let _grid = grid

/// An answer filled in a gap in a text. If the document is not in solution mode, the answer is
/// hidden but the height of the element is preserved.
///
/// Example:
///
/// #task-example(lines: "2-", ```typ
/// #import task-kinds.gap: gap
/// #set par(leading: 1em)
/// This is a #gap(width: 2cm)[difficult] question \
/// and it has #gap(width: 1.2cm, stroke: "box")[two] lines.
/// ```)
///
/// - answer (content): the answer to (maybe) display
/// - width (auto, relative): the width of the region where an answer can be written
/// - stroke (none, string, stroke): the stroke with which to mark the answer area. The special
/// values `"underline"` or `"box"` may be given to draw one or four border lines with a default
/// stroke.
/// -> content
#let gap(answer, width: auto, stroke: "underline") = context {
import "../solution.typ"

let stroke = stroke
assert(
type(stroke) != str or stroke in ("underline", "box"),
message: "for string values, only \"underline\" or \"box\" are allowed",
)
if stroke == "underline" {
stroke = (bottom: 0.5pt)
} else if stroke == "box" {
stroke = 0.5pt
}

let answer = answer
if (not solution.get()) {
answer = hide(answer)
}

box(width: width, stroke: stroke, outset: (y: 0.4em), align(center, answer))
}
1 change: 1 addition & 0 deletions src/task-kinds/mod.typ
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#import "choice.typ"
#import "free-form.typ"
#import "gap.typ"

0 comments on commit baf9c97

Please sign in to comment.