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

show figure: fig => fig.body doesn't work anymore #4633

Closed
jbirnick opened this issue Jul 26, 2024 · 3 comments
Closed

show figure: fig => fig.body doesn't work anymore #4633

jbirnick opened this issue Jul 26, 2024 · 3 comments
Labels
bug Something isn't working styling About set and show rules or style properties

Comments

@jbirnick
Copy link
Contributor

jbirnick commented Jul 26, 2024

Description

Consider the following document:

#show figure: fig => fig.body

#figure()[
  #block[
    This should be displayed as a normal block.
    
    In particular, this shouldn't be centered.
  ]
]

When you compile it with typst 0.11.1 (50115102), it works properly. That is, it will show a normal, left-aligned block.
However, if you compile it with the current main branch (commit c4dd6fa), it shows the text centered; so something went wrong.

@jbirnick jbirnick added the bug Something isn't working label Jul 26, 2024
@LaurenzV LaurenzV added the urgent Should be fixed before the next release. label Jul 27, 2024
@Leedehai
Copy link
Contributor

Leedehai commented Jul 27, 2024

TL;DR: it looks to me this behavior is intended.

Since 0.11 (commit 5011510, May 17) is not in the main branch, I wanted to test this issue on the commit one day after 0.11's release (commit daf3ccb, May 18), but it turned out the codebase at that time is no longer compilable by the current Rust compiler (version 1.80.0). The dev environment is not yet fully hermit! (But including the toolchain in version control seems an overfill right now)

So I checked out commit 45366c0 (Jun 24), where the Rust compiler was bumped from 1.77.0 to 1.79.0. The codebase is compilable, and this issue already existed on that commit. I downgraded to Rust 1.77.0 then checked out commit daf3ccb (May 18), and the issue did not exist on that commit. Fortunately, the big test runner refactoring was done back in April so I was able to run the tests.

The bisection result between the above two commits indicated commit e6739ec caused this issue:

e6739ecc2f78f023b7b6b1729983af30f657e6dd is the first bad commit
commit e6739ecc2f78f023b7b6b1729983af30f657e6dd (HEAD, refs/bisect/bad)
Author: Laurenz <[email protected]>
Date:   Wed May 29 15:17:05 2024  0200

    Fix figure centering (#4276)

However, PR #4276, which created this commit, stated that the PR would "break users who assume that show figure: it => it.body is equivalent to just it.body, since it doesn't revoke the centering anymore (just like show heading: it => it.body doesn't revoke the heading styling)". Therefore, I think the behavior reported by this issue is intended by that PR.

@jbirnick
Copy link
Contributor Author

jbirnick commented Jul 28, 2024

Thanks for the analysis; indeed, it looks like this is exactly intended.

Though, can someone explain me why you would want that behavior? To me it seems counterintuitive, because I thought show rules would give me full control of the styling.

(Also note that the two other people, LaurenzV and Leedehai, who have seen the issue so far, first considered it an issue and hence didn't expect that behavior as well. Is there a part of the docs that explains how show rules of pre-styled elements are supposed to work?)

And what is the current solution if I really just want to display the body of the figure, without any inherited styling?

@PgBiel
Copy link
Contributor

PgBiel commented Jul 28, 2024

The show rule behaves exactly as before, except for alignment. Show rules always inherit styles, you can see this with headings too. But figure was doing a weird thing which didn't let you override the alignment, so after that PR it is properly a style which is configurable through #show figure: set align(start) (for example - this code would solve your use case, and is the intended approach).

A more general mechanism, such as some special form of the revoke rules proposal, would be needed to negate any inherited styles in a show rule, but this is not currently supported by Typst, and is orthogonal to the issue at hand. (If there isn't a separate issue requesting this, feel free to make one!)

Edit: It is noteworthy that you can cancel all alignment by wrapping your figure in a block().

@PgBiel PgBiel closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2024
@PgBiel PgBiel added styling About set and show rules or style properties and removed urgent Should be fixed before the next release. labels Jul 28, 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 styling About set and show rules or style properties
Projects
None yet
Development

No branches or pull requests

4 participants