Skip to content

Commit

Permalink
feat: hide solutions; template: fix link to manual
Browse files Browse the repository at this point in the history
  • Loading branch information
lace-wing committed Jan 14, 2025
1 parent 53d65d7 commit 378eb44
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
14 changes: 12 additions & 2 deletions packages/preview/lacy-ubc-math-project/0.1.0/format.typ
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
// Make sure the numbering and labeling are consistent.
#assert(__question-numbering.len() == __max-qs-level and __question-labels.len() == __max-qs-level)

// solution visibility
#let __solution-visible = state("solution-visible", true)
#let toggle-solution(visible) = {
assert(type(visible) == bool, message: "The visibility of the solution must be a boolean.")
__solution-visible.update(v => visible)
}
#let __solution-disabled = sys.inputs.at("hide-solution", default: "") in ("1", "true", "yes", "y")

/// Creates an author (a `dictionary`).
/// - firstname (str, content): The author's first name, bold when displayed.
/// - lastname (str, content): The author's last name.
Expand Down Expand Up @@ -125,12 +133,14 @@
/// - body (content): The solution.
/// - color (color): The color of the solution frame and text.
/// - supplement (content): The supplemental text to be displayed before the solution.
#let solution(body, color: green-solution, supplement: [*Solution*: ]) = {
block(
#let solution(body, color: green-solution, supplement: [*Solution*: ], force: false) = {
context block(
width: 100%,
inset: 1em,
stroke: color + 0.5pt,
)[
#if __solution-disabled { return none }
#if not force and not __solution-visible.get() { return none }
#set align(left)
#set text(fill: color)
#supplement#body
Expand Down
10 changes: 7 additions & 3 deletions packages/preview/lacy-ubc-math-project/0.1.0/lib.typ
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#import prefixes: *
#import "@preview/equate:0.2.1": *

#import "format.typ": author, question, solution, green-solution
#import "format.typ": author, question, solution, green-solution, toggle-solution
#import "shorthand.typ": *
#import "drawing.typ" as drawing

Expand Down Expand Up @@ -100,8 +100,12 @@
#set page(numbering: none)
#set par(first-line-indent: 0em)
#set text(font: ("DejaVu Serif", "New Computer Modern"), size: 10pt)
#show ref: set text(fill: blue.darken(30%), stroke: 0.2pt + blue.darken(30%))
#show link: set text(fill: blue.darken(30%), stroke: 0.2pt + blue.darken(30%))
#let link_s = it => {
set text(fill: blue.darken(30%))
underline(it)
}
#show ref: link_s
#show link: link_s

#set math.equation(numbering: "(1.1)")

Expand Down
Binary file modified packages/preview/lacy-ubc-math-project/0.1.0/manual.pdf
Binary file not shown.
26 changes: 26 additions & 0 deletions packages/preview/lacy-ubc-math-project/0.1.0/manual.typ
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,32 @@ Solution is usually put in a question block as a response to it.
]
```

== Hiding Solutions
There are 2 ways to hide solutions.

To disable all solutions (all solutions will not show, no matter what), provide `hide-solution` to compile inputs:
```bash
typst compile filename.typ --input hide-solution=true
```
The value can be any of `true`, `1`, `yes`, `y`.

This flag is also visible in the `unsafe` module as ```typc __solution-disabled```.

To hide arbitrary solutions, use ```typc toggle-solution()``` before the solutions you wish to hide.
In this case, individual solutions can be forced to show by setting ```typc force: true``` in the ```typc solution()``` function.
#showcode(```typst
#solution[Visible.]
// toggle solutions off
#toggle-solution(false)
#solution[Hidden.]
// force it to show
#solution(force: true)[Forced to be visible.]
// toggle them back on
#toggle-solution(true)
#solution[Visible again.]
```)



= Drawing
As we are doing math, inevitably we will need to draw some graphs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@
]
]

There is also a #link("/lace-wing/lacy-ubc-math-project/blob/master/manual.pdf")[manual] for this project.
There is also a #link("https://github.com/lace-wing/lacy-ubc-math-project")[manual] for this project.

2 changes: 1 addition & 1 deletion packages/preview/lacy-ubc-math-project/0.1.0/unsafe.typ
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#import "format.typ": __question-level, __question-counters, __question-labels, __question-numbering, __max-qs-level, __question-duplicates
#import "format.typ": __question-level, __question-counters, __question-labels, __question-numbering, __max-qs-level, __question-duplicates, __solution-visible, __solution-disabled

0 comments on commit 378eb44

Please sign in to comment.