Repository navigation
Conversation
|
Hi! This would be super useful! What is the PR waiting on? Is there anything I can help with? |
Sorry for the delay. I still need to figure out a sane way to deal with fractional spacing in display math. The main goal is so that without any alignment points, this will work: #5780 (comment). I'm still not sure what is the most logical way it would work when there are alignment points though. If you have any ideas here that would be great! |
ce74652 to
29fba47
Compare
There was a problem hiding this comment.
I've rebased this on main so it is working again. I was thinking we just leave out fractional spacing in display math for now, so this can finally be merged. EDIT: Here's some ideas I wrote up https://typst.app/project/rABIqxO4x98oguiHSQplgv
I left some comments to note on review. Mainly some MathML export things.
| MathItem::Fractional(_) => { | ||
| // TODO: should probably warn. | ||
| return Ok(()); | ||
| } |
There was a problem hiding this comment.
We probably shouldn't silently ignore this.
There was a problem hiding this comment.
Yes, a warning would be good here, too.
| MathItem::Absolute(amount, _, _) => { | ||
| // TODO: Relative spacing has no effect in MathML Core. | ||
| ctx.push( | ||
| HtmlElem::new(tag::mspace) | ||
| .with_attr(attr::width, amount.to_css(())) | ||
| .pack(), | ||
| ); | ||
| return Ok(()); |
There was a problem hiding this comment.
I think we should just pass the absolute part, amount.abs, to the width attribute. If we keep it as is, browsers complain, e.g. in Firefox the HTML from $A #h(50% + 10pt) B$ says
Error in parsing MathML attribute value ‘calc(50% + 10pt)’ as length. Attribute ignored.
Error in parsing the value ‘calc(50% + 10pt)’ for ‘width’ attribute of <mspace/>. Attribute ignored.
Should we warn then if the relative part is non-zero?
There was a problem hiding this comment.
Seems fine. I think we should warn, yes.
| pub fn into_frame(self) -> Frame { | ||
| match self { | ||
| Self::Glyph(glyph) => glyph.into_frame(), | ||
| Self::Frame(fragment) => fragment.frame, | ||
| Self::Tag(tag) => { | ||
| let mut frame = Frame::soft(Size::zero()); | ||
| frame.push(Point::zero(), FrameItem::Tag(tag)); | ||
| frame | ||
| } | ||
| Self::Space(_) => Frame::soft(self.size()), | ||
| Self::Space(_) | Self::Fractional(_) => Frame::soft(self.size()), | ||
| } | ||
| } |
There was a problem hiding this comment.
Just flagging this. If a fractional length shows up nested somewhere, we just turn it into an empty frame of size zero.
| if prev_width.at(*prev_font_size) < width.at(font_size) { | ||
| if prev_width.map(|abs| abs.at(*prev_font_size)) | ||
| < width.map(|abs| abs.at(font_size)) | ||
| { |
There was a problem hiding this comment.
As a note, the PartialOrd implementation for Rel<T> is
typst/crates/typst-library/src/layout/rel.rs
Lines 193 to 203 in 9f2b6e8
This seems incomplete?
Also, the current implementation violates transitivity: a = -1pt + 0%, b = 0pt + 0%, and c = 0pt + 10% has a < b, b < c, but comparing a and c gives None.
laurmaedje
left a comment
There was a problem hiding this comment.
I would be okay with leaving out the fractional spacing in display math for now.
On that matter though: I think I prefer design C. In inline layout fractional h spacing is line by line and C keeps it consistent with that. D would be a bit more consistent with fr in grid/table cells. So I suppose which one feels more consistent depends on whether you think about math line by line or as a grid. I suspect most people think line-by-line. A potential future tab-stop feature in inline layout would likely also keep fr per line.
The main downside is that the frs will not necessarily fill up the entire remaining space in the line if they are used across alignment points. But that would be the cost of keeping 1fr consistent across the line...
| MathItem::Absolute(amount, _, _) => { | ||
| // TODO: Relative spacing has no effect in MathML Core. | ||
| ctx.push( | ||
| HtmlElem::new(tag::mspace) | ||
| .with_attr(attr::width, amount.to_css(())) | ||
| .pack(), | ||
| ); | ||
| return Ok(()); |
There was a problem hiding this comment.
Seems fine. I think we should warn, yes.
| MathItem::Fractional(_) => { | ||
| // TODO: should probably warn. | ||
| return Ok(()); | ||
| } |
There was a problem hiding this comment.
Yes, a warning would be good here, too.
| /// Explicit spacing with the font size at the point of creation. The | ||
| /// boolean indicates whether the spacing is weak. | ||
| Spacing(Length, Abs, bool), | ||
| Absolute(Rel<Length>, Abs, bool), |
There was a problem hiding this comment.
"Absolute" seem like a misnomer. Maybe just Rel like for the Spacing and Sizing enums?
| // Same as explicit spacing that isn't weak. | ||
| RawMathItem::Item(MathItem::Fractional(_)) => { | ||
| last = None; | ||
| space = None; | ||
| resolved.push(item); | ||
| continue; | ||
| } |
There was a problem hiding this comment.
I wanted to comment that fractional spacing should destroy weak spacing (unlike explicit spacing), but it appears that this is already inconsistent between h and v in normal layout 🫠
A #h(6cm, weak: true) #h(1fr) B #h(1fr)
#pagebreak()
A #v(6cm, weak: true) #v(1fr) B #v(1fr)In principle, the idea was that fractional spacing is destructive and therefore eats up the weak spacing.
| // Validate that ignorant elements are layouted | ||
| #context test(counter("test").get(), (3,)) | ||
|
|
||
| --- math-spacing-relative paged --- |
There was a problem hiding this comment.
Maybe call this test *-block then?
| --- math-spacing-relative-inline paged --- | ||
| // Test relative spacing in inline math. | ||
| #let mtext = text.with(font: "Libertinus Serif") | ||
| Hello#h(40%)world \ |
There was a problem hiding this comment.
Could also use A and B here for consistency and a slightly smaller image.
| let mut frame_prev = | ||
| std::mem::replace(&mut frame, Frame::soft(Size::zero())); | ||
|
|
||
| finalize_frame(&mut frame_prev, x, ascent, descent); | ||
| items.push(InlineItem::Frame(frame_prev)); | ||
| empty = true; | ||
|
|
||
| x = Abs::zero(); | ||
| ascent = Abs::zero(); | ||
| descent = Abs::zero(); | ||
| } |
There was a problem hiding this comment.
Duplicating the entire logic from below is a bit unfortunate.
| frame | ||
| } | ||
| Self::Space(_) => Frame::soft(self.size()), | ||
| Self::Space(_) | Self::Fractional(_) => Frame::soft(self.size()), |
There was a problem hiding this comment.
I suppose nested fr spacing could also be a warning. Would that have to touch a lot of code?
| if let Some(f_next) = iter.peek() | ||
| && !is_space(f_next) | ||
| { | ||
| if iter.peek().map(is_space).is_some() { |
There was a problem hiding this comment.
This looks sus because the map isn't doing anything when followed by is_some. Should this be is_some_and(is_space)?
Even then, though, the behavior differs if we're at the end of the equation as the else branch would push a zero-width spacing. This is almost unnoticable but could theoretically affect smartquotes.
Closes #6213 and half does #5780. I still need to sort out fractional spacing in display math.