Hello there everyone, I’m trying to learn the software and explore making & customizing things to learn, and I came across this use case:
I made a simple custom theorem from the provided template from theorion
package.
I wanted to add some sort of marker I called it suffix
(an optional tag for the theorem). Ideally expecting it to have a flexibility when dealing with specifying the arguments like in stroke
, or radius
for example.
The goal was to achieve the look in the attached photo.
which I did using the following code:
/// page setup
#set page(height: auto, width: 10cm)
#import "@preview/theorion:0.3.3": *
#import cosmos.clouds: *
// tag fnc to define the style
#let tag(fill: blue, body) = box(
radius:0.20em,
fill: fill.lighten(80%),
inset: (x:0.25em),
outset: (y:0.15em)
)[
#text(size:0.6em)[#body]
]
#show: show-theorion
#let (mytheo-counter, mytheo-box, mytheo, show-mytheo) = make-frame(
"theorem",
"Theorem",
counter: theorem-counter,
inherited-levels: 2,
inherited-from: heading,
render: (
prefix: auto,
title: "",
full-title: auto,
suffix: (text:auto,fill: blue), /* // need it to behave like `stroke` or `radius` */
body) => [
#block(
fill:blue.lighten(85%),
inset: 0.5em,
radius: 0.4em,
)[
*#full-title*
#h(1fr)
#{
if suffix.text != auto {
tag(fill: suffix.fill)[#suffix.text]
}
}
#linebreak()
#body
]
]
)
#show: show-mytheo
#mytheo(
suffix:(text:"important", fill:red) // both specified, works fine
)[
#lorem(5)
]
My attempt at implementing suffix
was bad but I don’t know how to fix it, it worked in the example above but only because both suffix.text
and suffix.fill
are explicitly specified.
But whenever I attempt not specifying at least one of the keys, it no longer renders, and gives the following error as shown below:
#mytheo(
suffix:(text:"important") // error: "dictionary does not contain key "fill""
)[
#lorem(5)
]
- When I don’t specify the fill arg, I need it to fall back to the default.
I expectsuffix
to handle its arguments/parameters with flexibility, likestroke
for example, specifyingstroke: 2pt + red
is equivalent tostroke: (paint: red, thickness: 2pt)
. Any parameter (from the rest) that is not specified, doesn’t fail to return a value, it gives the defaults.
It doesn’t need to be the same level of flexibility, as this may be reserved to Typst’s native types, but any correction to my current understanding to how to implement this is most welcome.