If I’m getting the gist of your question correctly, you want to know whether some content can fit in a single page, and adjust the content until it can. I think you can achieve this in Typst; here are the fundamental steps:
- Put the content in a function that you can call with different
actual-thresholds. You don’t need state for this; just do something like this:#let full-content(actual-threshold) = { let item-with-threshold(level: 0, ..args) = { if level <= actual-threshold [#args.pos().join()\ ] } item-with-threshold(level: 0)[This item has a very high priority] item-with-threshold(level:1)[This has lower priority] // ... } - Use
layoutandmeasureto determine the height of the content on the actual page:#layout(size => { let measured-height = measure(full-content(2), width: size.width) // does it fit? check `measured-height < size.height` }) - Use binary or linear search to determine the largest
actual-thresholdthat fits. Do all this insidelayout(), or you’ll run into Why is the value I receive from context always content?