#How to add a custom array-like field to a custom theorion box?

2 messages · Page 1 of 1 (latest)

scenic wave
#

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 custom theorem from the provided template of 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 for example.

The goal was to achieve the look in the attached photo. which I did using the following code:

#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` */
    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)
      ]

(cont'd below)

#

(cont'd)
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)
      ]
  1. When I don't specify the fill arg, I need it to fall back to the default.
  2. Suffix handles its arguments with flexibility, like stroke for example, like stroke: 2pt + red is equivalent to stroke: (paint: red, thickness: 2pt). Any parameter (from the rest) that is not specified, doesn't fail to return a value, it gives the defaults.