Non rectangular boxes/cells

Is there a way to make “non square boxes” in typst?
Here’s an image as reference

There is curve for arbitrary shapes and drawing.

There are no text wrapping in Typst, so you can use meander to do this automatically:

#import "@preview/meander:0.3.0"

#let special-box(special, main) = rect(meander.reflow({
  import meander: *
  placed(top + right, dx: 5pt, dy: -5pt, block(stroke: white + 1.5pt, rect(
    stroke: (top: none, right: none, rest: 1pt),
    outset: 0.5pt,
    inset: 0.5pt,
    rect(stroke: red, outset: (top: 0.5pt, right: 0.5pt))[#special],
  )))
  container()
  content[#main]
}))

#special-box[#lorem(5)][
  #lorem(57)
]

I don’t know how to make it a single shape, so I used some stroke hackery + inset/outset adjustments to get the ideal output.

image

To make it more readable, I used a chain of show rule wrappers:

#import "@preview/meander:0.3.0"

#let special-box(special, main) = rect(meander.reflow({
  import meander: *
  placed(top + right, dx: 5pt, dy: -5pt, {
    show: block.with(stroke: white + 1.5pt) // no default 5 pt inset
    show: rect.with(
      stroke: (top: none, right: none, rest: 1pt),
      outset: 0.5pt,
      inset: 0.5pt,
    )
    show: rect.with(stroke: red, outset: (top: 0.5pt, right: 0.5pt))
    [#special]
  })
  container()
  content[#main]
}))

#special-box[#lorem(5)][
  #lorem(57)
]

You can even do stuff like #special-box(6, 9).

3 Likes

Thanks! this is great!