Expose baselines for box and block - #8150
Conversation
|
Note that #5855 is not properly linked as being closed by this PR. |
|
Fixed, thanks! |
3750581 to
12d0268
Compare
laurmaedje
left a comment
There was a problem hiding this comment.
Looking good! I have some nitpicks, but all minor.
-
The test case
block-clip-svg-glyphsis interesting. The auto baseline is pushed beyond the height of the box because already the first line overflows. I wonder whether we should restrict the baseline to not exceed the box's height. But I'm not sure. -
Do you know what happened for these five tests? The PNG is the same, but PDF and SVG differ slightly:
line-numbers-page-scope-quasi-empty-first-columnmath-equation-number-align-multiline-expandmath-lr-ignore-ignorantshow-text-regex-character-classspacing-h-and-v
I'm not sure whether we discussed these before, I might've forgotten.
-
Also, is the TODO "Address remaining tests" still relevant?
2fcd480 to
92973c0
Compare
|
Would be great if you could also rebase on top of main since there are conflicts. |
Yeah, that's an interesting question. I suppose we generally can't prevent the baseline from moving out of bounds... But your proposal does make some sense, if we consider that baseline is strictly a property of layout, not of render or purely visual. Worth thinking a bit about.
The core problem here is that the For the rest, I had found that the changes were mostly in subtle position changes of empty shapes, likely spaces, so I don't think anything major was spotted there. In any case, I'll take a second look to confirm.
No. |
Element description says it shouldn't affect layout. Baselines affect layout (they change box sizing).
Proposed algorithm: new baseline crosses (width / 2, baseline) post-transform.
Box has a "non-semantic" paragraph inside it, whereas there is another paragraph holding the box outside. Hence, there were two line numbers: one below the box and one inside it. Now that the baselines coincide, the two line numbers were merged together. But this is something to investigate further in the future. Should par.line be restricted only to semantic paragraphs? That is not always desirable (e.g. headings should still be numbered, more often than not), and can be done today already with `#show par: set par.line(...)`. Overall, worth some further discussion.
|
Nice to have this merged. One step closer to having the list issues fixed, too. :) |


Needed for #7895. Fixes #4796 (which might also address #7319 (comment)), #5855. Partially addresses #493.
Boxes and blocks will now propagate the baseline of what's inside them - usually text or math - allowing them to properly align with their surrounding text / math. For this to work, text and math content now expose their baselines. For paragraphs, the baseline will be set to that under the first line of text. For math equations, the global baseline will be set to the baseline of the first row. And for content with more than one paragraph / equation, the baseline of the first one will be used. With that, several little annoyances when using
boxshall be gone.This means that:
box($a x + b y = 10 - c z$)to ensure that pesky long inline equation won't break across lines.boxeffects) around the boxed text, and it will now remain aligned!For blocks, for now, the only meaningful change is when a
blockis used inside an equation: it will now be properly aligned with the rest. For example, this is how$ #block($y$) + y $currently looks like:And this is how it will now look like:
In the future (in #7895), block baselines will also be used for list marker alignment.
In addition,
box(scale[Text])will also use the correct baseline after the scaling withreflow: true. However,box(rotate[Text])will stay as it is today regardless ofreflow: trueas it is not yet very clear where the baseline should go after, say, a 180-degree rotation of a paragraph.Configuration
Despite all the goodies listed above, it's possible the old behavior is still desired. In that case,
box(baseline: ...)now accepts new values (defaulting toauto):box(baseline: bottom)ensures text aligns withbottomof the box - this was the previous default behavior.box(baseline: top)andbox(baseline: horizon)also allow moving the baseline to the top or middle of the box.Note that
box(baseline: 5pt)(to shift the baseline by that height compared to where it normally is) is still supported, and both options can be specified simultaneously through a dictionary:box(baseline: (at: bottom, shift: 5pt)).This is a breaking change if you're reading
context box.baselineas this will now always return a dictionary.TODO