Typst solution state
This commit is contained in:
@ -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) = {
|
||||
|
Reference in New Issue
Block a user