Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some invisible elements degrade element locations #4029

Open
1 task done
tingerrr opened this issue Apr 28, 2024 · 0 comments
Open
1 task done

Some invisible elements degrade element locations #4029

tingerrr opened this issue Apr 28, 2024 · 0 comments
Labels
bug Something isn't working introspection Related to introspection.

Comments

@tingerrr
Copy link
Contributor

tingerrr commented Apr 28, 2024

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

  • I am using the latest version of Typst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working introspection Related to introspection.
Projects
None yet
Development

No branches or pull requests

2 participants