-
-
Notifications
You must be signed in to change notification settings - Fork 939
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
New flow layout, with multi-column floats #5017
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hecking AWESOME |
bluebear94
reviewed
Sep 24, 2024
Cool! |
Finally! Thanks for the hard work. |
This was referenced Sep 25, 2024
This was referenced Sep 25, 2024
Merged
1 task
1 task
FYI, in the example given by @laurmaedje above I believe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a full, fundamental redesign and rewrite of Typst's most central layouter, the flow layouter. This layouter is responsible for arranging paragraphs, blocks, spacing, placed elements, floats, and footnotes across pages.
Why a new flow layouter?
The old flow layouter was written a long time ago and grew over time. New features, like footnotes and floats, were mostly bolted on top: This showed up in a lack of features (e.g. floats over two columns) and bugs (e.g. footnotes in breakable blocks flowing away to the last page of the block). To address those properly required a fundamental shift in how the flow operates. The old flow layout proceeded in a strictly linear manner: It processed elements one by one, with no way to go back and revise a decision. This mode of operation is quite limiting and can fundamentally not handle all features we want Typst to have.
How does it work?
The new flow layout operates in a sort of flipped-around way: Instead of walking elements one by one, it walks pages one by one. For each page, it fills it with content as long as space is available. And here comes the crucial part: While laying out a page, it can decide to trigger a relayout of the page. This happens when a float or footnote is inserted, as this can affect the layout of the page's inner content. I wrote a bit more about this approach in a blog post some time ago: In summary, the approach of gaining information and then relayouting with that new information can help us iteratively solve various problems that can't be solved in a single step. It's sort of similar to how Typst already runs multiple layout iterations to resolve introspection, but additional and add the page-level. (It might seem like a good idea to actually use the normal introspection for these things, but one runs into convergence issues immediately, which is why the iteration scope must be tighter.)
What does it do?
User-facing, this PR
block.sticky
to property to prevent a pagebreak after a block. This is used internally by headings.The new floating placement looks like this:
The PR also lays the groundwork for exciting future features like to-the-side wrapping floats, layout through chained containers, page margins depending on the page number, and more.
Notes
In my very unscientific testing on a few documents, performance was not affected much. While working on the PR, I primarily on focused on getting things right and not hurting performance too much, so that's a good result I would say. Fundamentally, doing relayouts is of course more expensive than not doing them.
The PR also adds the new file
tests/skip.txt
, which can be used to temporarily disable all the tests listed within. This is very useful during large incremental refactors.Linked issues
align(horizon)
messes withv(1fr)
#2213