Skip to content

Instantly share code, notes, and snippets.

@hongjr03
Last active June 9, 2025 10:30
Show Gist options
  • Select an option

  • Save hongjr03/0a0ffdb20fc9be757cb184191cf41883 to your computer and use it in GitHub Desktop.

Select an option

Save hongjr03/0a0ffdb20fc9be757cb184191cf41883 to your computer and use it in GitHub Desktop.
#let bcol(..args) = layout(container => context {
let num-columns = args.pos().first()
let body = args.pos().at(1)
let parent-places = body.children.filter(x => (
"scope" in x.fields() and x.fields().scope == "parent"
))
let gutter = if "gutter" in args.named() { args.named().gutter } else { (4% + 0pt).length }
let column-width = (container.width - gutter * (num-columns - 1)) / num-columns
let height = (
calc.ceil(
(
(
measure(
body,
width: column-width,
).height
+ parent-places.map(place => measure(place, width: container.width).height).sum(default: 0pt) * num-columns
- parent-places.map(place => measure(place, width: column-width).height).sum(default: 0pt)
)
/ num-columns
+ 0.5em.to-absolute()
)
/ 1em.to-absolute(),
)
* 1em
)
block(
height: height,
breakable: true,
columns(num-columns, body, gutter: gutter, ..args.named()),
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment