Repository navigation
Improved list layout - #7895
Improved list layout#7895
Conversation
|
Great to see work on this @PgBiel! As a small reminder, the following Typst roadmap bullet point can be crossed out once this is merged.
|
track upstream fix typst/typst#7895
track upstream fix typst/typst#7895
d6932b1 to
f49fe8a
Compare
4d6126e to
7193c7f
Compare
3810905 to
ecdeb0c
Compare
df07e6c to
fd9ce28
Compare
e8e99d1 to
daf68d1
Compare
laurmaedje
left a comment
There was a problem hiding this comment.
I have a few minor nitpicks on the code, but more importantly, I found a bug that is not present on main:
When wrapping a list in an auto-sized container like a block, it seems that the body region is not computed correctly. List or body indent or a very wide marker then lead to overflowing content while negative indent leads to a gap at the right end.
Here's an example:
#set page("a5")
#set list(indent: 100pt)
// here are more things to try
// #set list(indent: -50pt)
// #set list(marker: [AAAAAAAAAAAAAAAAAAAAA])
#block[
- #lorem(20)
]I think the measurement code path does not take into account the indents and markers at all.
I had already merged with main in preparation of merge, but feel free to force push that away if you prefer to rebase.
Nice catch. I missed the need for auto column width redistribution when mimicking grid column measurement 😅 |
5db39f7 to
02fbbe2
Compare
|
I've added the same algorithm as grids now: if the sum of marker width + body width surpasses the available width (total - indents, i.e. total - fixed-width columns), then each is given (up to) half of the available width as needed. I've also refactored the Please take a look at the latest commit to confirm. :) |
This seems cleaner and the performance difference should be negligible.
Fixes #529, #1204
Depends on #8150.
Reworks list (and enum, but not
terms) layout by 1. adding a form of baseline alignment between the list item's marker and its body, allowing proper alignment between e.g. the marker and a math equation, and 2. allowing the list to expand to the full surrounding width when it isn't infinite, which fixes center-aligned things inside it.The example image below shows the core of the changes: a centered equation in a list with baseline alignment (the marker matches the baseline height of the math text).
Behavior changes
It is worth noting that baseline alignment will consider the very first (visible) object inside the body. This would correspond to an equation's first row, or to a rectangle around text, etc., so the results won't always be what one might expect. Still, we can always improve the heuristics for specific use cases.width: auto), ceasing the need for hacks like#h(1fr)orshow list: block.with(width: 100%)etc. from Center alignment broken in lists #529. This means that anything that is center-aligned inside the list body, such as equations, will still be center-aligned. (But also right-aligned, and so on.) Of course, the marker itself isn't aligned.There is an important consequence of this.
#align(right)[- my list]will no longer align the whole list to the right - the marker remains to the left (start), because the list always occupies the full width, so alignment doesn't affect the marker. To move the whole list to the right, you need to restore the old list behavior of not expanding to the full width. To do this, one can just surround it with ablock:#align(right, block[- my list]).Implementation details
stackcombined with a custom layouter (for marker horizontal alignment and baseline alignment).stack, differently from agridwith auto columns, propagates to its children whether they canexpandto fill the page width or not. This automatically fixes centering in lists (Center alignment broken in lists #529).startorend.TODOs
stack, fixing centeringenum.number-align