Minor cleanup #21

Merged
Mark merged 3 commits from cleanup into main 2025-03-02 19:36:20 -08:00
2 changed files with 52 additions and 19 deletions
Showing only changes of commit 8d49154277 - Show all commits

View File

@ -93,7 +93,9 @@
// Make handout title
{
import "header.typ": make_header, solution_warning
import "solution.typ": show_solutions
import "solution.typ": solutions_state, reset_solutions
reset_solutions()
let url = link(
"https://betalupi.com/handouts",
@ -108,8 +110,10 @@
top_right: url,
)
if show_solutions {
solution_warning()
context {
if solutions_state.get() {
solution_warning()
}
}
}

View File

@ -1,34 +1,63 @@
#import "misc.typ": ored, oblue
/// If false, hide instructor info.
///
/// Compile with the following command to hide solutions:
/// `typst compile main.typ --input show_solutions=false`
/// If true, show it.
///
/// Solutions are shown by default. This behavior
/// is less surprising than hiding content by default.
#let show_solutions = {
#let solutions_state = state("solutions_state", true)
/// Force solutions to be hidden after this point.
///
/// This function produces content that must be
/// included in the document. If it is not included,
/// this function will have no effect.
#let hide_solutions() = {
return solutions_state.update(x => false)
}
/// Force solutions to be shown after this point.
///
/// This function produces content that must be
/// included in the document. If it is not included,
/// this function will have no effect.
#let show_solutions() = {
return solutions_state.update(x => true)
}
/// Reset the solution flag to its default value.
/// This value is determined by compile flags:
/// Compile with the following command to hide solutions:
/// `typst compile main.typ --input show_solutions=false`
///
/// Solutions are shown by default.
///
/// This function produces content that must be
/// included in the document. If it is not included,
/// this function will have no effect.
#let reset_solutions() = {
if "show_solutions" in sys.inputs {
// Show solutions unless they're explicitly disabled
not (
if (
sys.inputs.show_solutions == "false" or sys.inputs.show_solutions == "no"
)
} else {
// Show solutions by default
true
) {
return solutions_state.update(x => false)
}
}
}
#let if_solutions(content) = {
if show_solutions { content }
#let if_solutions(content) = context {
if solutions_state.get() { content }
}
#let if_no_solutions(content) = {
if not show_solutions { content }
#let if_no_solutions(content) = context {
if not solutions_state.get() { content }
}
#let if_solutions_else(if_yes, if_no) = {
if show_solutions { if_yes } else { if_no }
#let if_solutions_else(if_yes, if_no) = context {
if solutions_state.get() { if_yes } else { if_no }
}
#let solution(content) = {