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

Citation formatting fails in table.header #4023

Open
1 task done
SeSodesa opened this issue Apr 26, 2024 · 7 comments
Open
1 task done

Citation formatting fails in table.header #4023

SeSodesa opened this issue Apr 26, 2024 · 7 comments
Labels
bug Something isn't working introspection Related to introspection.

Comments

@SeSodesa
Copy link

Description

When I try to compile a typst document that has a citation in a table.header (link to offending commit), I get the following error message:

[15:03:11] compiled with errors

error: failed to format citation (this is a bug)
   ┌─ main.typ:69:42
   │
69 │   [Summary of forward vs. inverse problems @söderholm2024peeling],
   │

I don't know if this is a problem with table.header itself or in the way that I've defined a frame template function in the file tau-presentation.typ, but it would be cool if this could get resolved.

Reproduction URL

https://gitlab.com/SeSodesa/tau-typst-presentation/-/commit/cefd297354da39d0f778431177c80ae15f7d9bfa

Operating system

macOS

Typst version

  • I am using the latest version of Typst
@SeSodesa SeSodesa added the bug Something isn't working label Apr 26, 2024
@PgBiel
Copy link
Contributor

PgBiel commented Apr 28, 2024

Same happens on footers. Strange...

Thanks for reporting.

@PgBiel
Copy link
Contributor

PgBiel commented Apr 28, 2024

Adding repeat: false to header or footer fixes it. Additionally, this doesn't happen within unbreakable rows in general (table.cell(breakable: false)[@citation] isn't enough to trigger the bug; the cell has to be in a repeated header or footer). So it's somehow related to repeating headers/footers.

I also tested placing a labelled heading inside a repeated table header, and I could still query it, so introspection isn't completely broken.

Paging @laurmaedje for ideas. Are we doing something too cursed with regions, to the point of somehow breaking citations? Very weird...

@PgBiel
Copy link
Contributor

PgBiel commented Apr 28, 2024

I've tested further, and this only happens in the first page of the table with a repeated header. That is, if you write

#table(
   table.header([#context { if here().page() == 1 [nothing here] else [@citation] }]),
    ...
)

it won't error and will display normally, unless you add the citation on the first page as well.

In a perhaps similar fashion (at least on the surface), for footers, this only happens if the table has only one page. Otherwise, the citation displays normally across all of a footer's repetitions, including the final appearance of the footer, at the last page of the table.

Edit: The footer also errors on the first page if the citation is in an auto row. It does not error on any other pages, however, just like the header here. However, the repeated header errors on the first page having auto or fixed-size rows.

However, fractional rows in headers and footers are seemingly not affected by the bug.

@bluebear94
Copy link
Contributor

Taking a look at this issue. It seems that the offending citation group element sometimes shows up with a different location.

@bluebear94
Copy link
Contributor

I’ve found that the citation group element is getting two different locations because elem.children[0] has a different disambiguator in its location. I thought that discounting a content’s location from its hash would fix it, but there’s still the problem of having different disambiguators for the citation group element itself, so this probably isn’t the correct solution.

@bluebear94
Copy link
Contributor

Replacing line 234 of crates/typst/src/layout/mod.rs:

-            let mut locator = Locator::chained(locator);
+            let mut locator = Locator::new();

makes this bug not manifest, but this obviously isn’t a desirable solution.

@laurmaedje
Copy link
Member

Perhaps the error happens because the assigned locations don't line up across measurement and true layout. If it is indeed this, the problem is explained in the "Measurement and Introspection" section in https://laurmaedje.github.io/posts/frozen-state/.

@laurmaedje laurmaedje added the introspection Related to introspection. label Apr 29, 2024
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

4 participants