Some invisible elements degrade element locations
Description
When investigating hydra#2 I stumbled upon something interesting. It's regarding how locations for elements are created when show rules with leading invisible elements are involved.
In the following show rules, the location of elem changes depending on the rule.
#show elem: it => {
v(8cm)
// loc starts here, this makes sense as the spacing is invisible and a user likely cares more about where the actual content starts
it
}
#show elem: it => {
// loc starts here, this makes sense, the block may not be invisible
block({
v(8cm)
it
})
}
#show elem: it => {
// loc starts here, this makes no sense as metadata is not just invisible it's also 0-sized
metadata(none)
v(8cm)
it
}
A similar thing happens to page numbers for locations when a rule of the following form is given:
// introspection thinks this element appears on the previous page
#show elem: it => counter(other).update(0) + pagebreak(weak: true) + it
The latter example involving page breaks may seem contrived, but is a real problem in templates. If a template provides a heading show rule that adds leading weak page breaks on level 1 headings, then any rule added by the user below the template itself may add arbitrary, perhaps invisible elements to the front of those headings. The user may not even be able to put it before the template if the template adds other headings where their rule should not apply.
Given how many styles a template may apply, adding a sort of override function that a user could pass in that is applied before this to circumvent this becomes unfeasible, needlessly complicated and unidiomatic.
Reproduction URL
https://typst.app/project/rgKG6an4XgcA6_QwpIefzT
Operating system
Web app
Typst version
- [X] I am using the latest version of Typst