Is this the right way to do show if?
#{
...
show math.equation.where(block: false): x => {
if equation-box-inline {
box(x) // no line breaks in inline math
} else {
x
}
}
...
}
Is this the right way to do show if?
#{
...
show math.equation.where(block: false): x => {
if equation-box-inline {
box(x) // no line breaks in inline math
} else {
x
}
}
...
}
Pretty much.
#show selector: it => {
if condition { return it }
// Process it
}
#show selector: it => if condition { it } else {
// Process it
}
Same thing with everything show rule, just omit the selector and use doc instead of it or something.
Though this doesn’t exactly work when you need context.
There is also sometimes a thing like show [selector]: if condition { ... } else { it => ... }.
The if test being done in the show rule for every element rubs me a bit the wrong way if we assume the condition equation-box-inline is meant as a global toggle… Depending on the use case the following might make sense:
// One sub-template that can be enabled/disabled in the main one
#let inline-eq-template(doc) = {
show math.equation.where(block: false): box
doc
}
// The main template, to be applied by the user
#let main-template(doc, equation-box-inline: true) = {
let sub-templates = ()
if equation-box-inline {
sub-templates.push(inline-eq-template)
}
// Add more functions in sub-templates as desired
// Finally, apply all sub-templates
sub-templates.fold(doc, (new-doc, sub-template) => {
show: sub-template
new-doc
})
}
#show: main-template
// For debugging
#set box(stroke: red)
A $x$ b.
Or if you don’t have several of these sub-templates, sometimes you can just do
#let template(doc) = {
if equation-box-inline {
show math.equation.where(block: false): box
doc
} else {
doc
}
}
#show: template