Andrew
April 7, 2025, 8:41pm
8
a_w:
So do I understand you correctly that this would turn my example into something like this:
main.typ
#import "template.typ": *
#show: template.with(headline-size: 18pt)
#set page(margin: (top: 10%))
#set text(size: 12pt, font: "Libertinus Sans")
#let colorize = colorize.with(color: blue)
#let colorbox = colorbox.with(color: blue)
= Headline
This should be #colorize("red") by default, but #colorize("blue") in after setting the `highlight-color` to blue. As should #colorbox("this").
and
template.typ
#let colorize(body, color: red) = {
set text(color)
body
}
#let colorbox(body, color: red) = {
box(fill: color, body)
}
#let template(doc, headline-size: 12pt) = {
set page(margin: (top: 5%))
set text(size: 12pt, font: "Comic Neue")
show heading: set text(size: headline-size)
doc
}
Well, mostly yes, but if you want, you can add the font and margin parameters to the template()
and just use one global show rule. But also this:
#let colorize(body, color: red) = text(color, body)
#let colorbox(body, color: red) = box(fill: color, body)
I think I remember that in some rare cases set text(color)
would work better, but if you just apply this directly on a normal text, then you can use a shorter version.
Not sure what procedural means here, but the majority of set and show-set rules supposed to be in a template function, this is literally what it’s for, generally speaking.
a_w:
Standalone functions get named arguments that can be directly modified using .with
Show-Rules are either left out of the template (and stay in each seperate file) altogether or get arguments on the template function if they really should be shared
Yes.
a_w:
Well, the state
thing, I guess, but that’s about it.