Minor cleanup #21
lib/typst/local/handout/0.1.0
@ -93,7 +93,9 @@
|
|||||||
// Make handout title
|
// Make handout title
|
||||||
{
|
{
|
||||||
import "header.typ": make_header, solution_warning
|
import "header.typ": make_header, solution_warning
|
||||||
import "solution.typ": show_solutions
|
import "solution.typ": solutions_state, reset_solutions
|
||||||
|
|
||||||
|
reset_solutions()
|
||||||
|
|
||||||
let url = link(
|
let url = link(
|
||||||
"https://betalupi.com/handouts",
|
"https://betalupi.com/handouts",
|
||||||
@ -108,8 +110,10 @@
|
|||||||
top_right: url,
|
top_right: url,
|
||||||
)
|
)
|
||||||
|
|
||||||
if show_solutions {
|
context {
|
||||||
solution_warning()
|
if solutions_state.get() {
|
||||||
|
solution_warning()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,34 +1,63 @@
|
|||||||
#import "misc.typ": ored, oblue
|
#import "misc.typ": ored, oblue
|
||||||
|
|
||||||
|
|
||||||
/// If false, hide instructor info.
|
/// If false, hide instructor info.
|
||||||
///
|
/// If true, show it.
|
||||||
/// Compile with the following command to hide solutions:
|
|
||||||
/// `typst compile main.typ --input show_solutions=false`
|
|
||||||
///
|
///
|
||||||
/// Solutions are shown by default. This behavior
|
/// Solutions are shown by default. This behavior
|
||||||
/// is less surprising than hiding content by default.
|
/// 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 {
|
if "show_solutions" in sys.inputs {
|
||||||
// Show solutions unless they're explicitly disabled
|
if (
|
||||||
not (
|
|
||||||
sys.inputs.show_solutions == "false" or sys.inputs.show_solutions == "no"
|
sys.inputs.show_solutions == "false" or sys.inputs.show_solutions == "no"
|
||||||
)
|
) {
|
||||||
} else {
|
return solutions_state.update(x => false)
|
||||||
// Show solutions by default
|
}
|
||||||
true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#let if_solutions(content) = {
|
#let if_solutions(content) = context {
|
||||||
if show_solutions { content }
|
if solutions_state.get() { content }
|
||||||
}
|
}
|
||||||
|
|
||||||
#let if_no_solutions(content) = {
|
#let if_no_solutions(content) = context {
|
||||||
if not show_solutions { content }
|
if not solutions_state.get() { content }
|
||||||
}
|
}
|
||||||
|
|
||||||
#let if_solutions_else(if_yes, if_no) = {
|
#let if_solutions_else(if_yes, if_no) = context {
|
||||||
if show_solutions { if_yes } else { if_no }
|
if solutions_state.get() { if_yes } else { if_no }
|
||||||
}
|
}
|
||||||
|
|
||||||
#let solution(content) = {
|
#let solution(content) = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user