Skip to content

Some invisible elements degrade element locations #4029

Closed

Description

@tingerrr

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

Activity

  1. added
    bug
    on Apr 28, 2024
  2. added
    introspection
    on Apr 29, 2024
  3. tingerrr commented on Dec 22, 2025

    @tingerrr
    ContributorAuthor

    With this being more than a year old, I'm removing the document at the reproduction URL. The original issue can be recreated from the example above with a build of the Typst compiler version 0.11.0.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugintrospection

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions