diff --git a/lib/typst/local/handout/0.1.0/lib.typ b/lib/typst/local/handout/0.1.0/lib.typ index 43e503e..7d3e59b 100755 --- a/lib/typst/local/handout/0.1.0/lib.typ +++ b/lib/typst/local/handout/0.1.0/lib.typ @@ -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() + } } } diff --git a/lib/typst/local/handout/0.1.0/solution.typ b/lib/typst/local/handout/0.1.0/solution.typ index 2af06c2..97c3f75 100755 --- a/lib/typst/local/handout/0.1.0/solution.typ +++ b/lib/typst/local/handout/0.1.0/solution.typ @@ -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) = {