I would like to use an if-condition in a template function to trigger dark mode. The template function has a boolean value dark that defaults to false. The following code works:
set page(fill: rgb("333333")) if dark
set text(fill: rgb("fdfdfd")) if dark
set text(font: "Source Sans Pro") if dark
However, when I try to wrap all three lines into an if-condition, I get a blank page (set in dark mode) and then the rest of the document in light mode instead. What am I doing wrong here?
if dark {
set page(fill: rgb("333333"))
set text(fill: rgb("fdfdfd"))
set text(font: "Source Sans Pro")
}
setrules only work in their scope and child scopes. Theifstatement creates a new scope, meaningsetrules are only active at that level:You can get around this using
set-ifrules:But it is inconvenient to do this for multiple rules in a row or when you rely on nested conditions. For more complicated scenarios, I use the following approach: