Skip to content

Instantly share code, notes, and snippets.

@te-lang-wakker
Last active March 18, 2024 09:19
Show Gist options
  • Save te-lang-wakker/9b4788ead11a0b2aa54b2083a33f2dda to your computer and use it in GitHub Desktop.
Save te-lang-wakker/9b4788ead11a0b2aa54b2083a33f2dda to your computer and use it in GitHub Desktop.
Titled & stacking textbox for Typst
// todo: key this by the provided label or just use dependency injection
#let this-counter = counter("info-box")
#let info-box(
title: none,
sections: none,
label: none,
caption: none,
radius: 3pt,
inset: 16pt,
outset: 0pt,
fill: luma(45),
) = {
set block(spacing: 0pt)
let title-radius = radius
if sections != none {
title-radius = (top: radius)
}
pad(
y: inset,
[
#pad(
x: outset,
rect(
width: 100%,
inset: 0pt,
stroke: fill,
radius: radius,
[
#if title != none {
block(
width: 100%,
radius: title-radius,
fill: fill,
pad(
inset,
par(
justify: false,
text(
hyphenate: false,
white,
title
)
)
)
)
}
#if sections != none {
let i = 0
for section in sections {
if i > 0 {
line(length: 100%)
}
pad(
inset,
section
)
i += 1
}
}
]
)
)
#if caption != none {
align(
center,
pad(
12pt,
[
#if label != none {
label
}
#this-counter.display():
#caption
]
)
)
this-counter.step()
}
]
)
}

Can't find a nice license text, but consider it public domain, CC0, etc. to the extent I am able to. It's just a few lines of code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment