Repository navigation
Conversation
|
Looking at the new reference image, it may be that this is actually only desirable for a subset of symbols. For arrows it seems very sensible, but for cc: @Enivex due to #1304 (comment) |
It makes more sense for some symbols than others, but I'd argue that this should be opt-in regardless. Perhaps through something like Whether the behavior is desirable is both subjective and situational. |
|
@laurmaedje Introduced |
The image good to my eyes, but maybe you should also add tests with absolute lengths as well? Like 1cm or 2em, not just %-based. Edit: And length < 100%. Maybe I'd like to scale an arrow, but not all the way to the length of the attachment. |
stretch()-able to accommodate wide attachments
mkorje
left a comment
There was a problem hiding this comment.
I think we should also add an element function to allow stretching vertically as well, and so we'd maybe have math.hstretch and math.vstretch. Whilst math.lr kind of does this, its really just for delimiters.
Adding an axis argument or something similar would make things a bit annoying I think - though maybe this could be done automatically by searching for the glyph in both the horizontal and vertical variants/constructions. I'm not sure if there exists any glyph that have both horizontal and vertical variants, which would cause problems then.
| /// Stretches a base to accommodate wide top or bottom attachments. | ||
| /// | ||
| /// ```example | ||
| /// $ H stretch(=)^"define" U + p V $ | ||
| /// $ P => Q stretch(=>, width: #200%) R $ | ||
| /// $ V stretch(->, width: #(100% + 1.5em))^("surjection") ZZ $ | ||
| /// ``` | ||
| #[elem(LayoutMath)] | ||
| pub struct StretchElem { | ||
| /// The base to stretch. | ||
| #[required] | ||
| pub body: Content, | ||
|
|
||
| /// The width of the base to stretch to, relative to the maximum width of | ||
| /// the base and the attachments (if any). | ||
| pub width: Smart<Rel<Length>>, | ||
| } |
There was a problem hiding this comment.
I think we should be generalising the StretchElem since you might just want to stretch a glyph like an arrow, but have no intention of adding attachments; and so the docs should reflect this.
| stretch(equiv)^(forall i)_"Chern-Weil" R | ||
| stretch(equiv, width: #(120% + 2mm))^(forall i)_"Chern-Weil" S \ | ||
| P &-> Q | ||
| stretch(->) R // Not stretched: no width specifid and no attachments |
There was a problem hiding this comment.
| stretch(->) R // Not stretched: no width specifid and no attachments | |
| stretch(->) R // Not stretched: no width specified and no attachments |
| #[derive(Clone, Copy, Debug)] | ||
| pub struct StretchInfo { | ||
| from: Abs, | ||
| to: Smart<Rel<Length>>, | ||
| } |
There was a problem hiding this comment.
If the change in impl LayoutMath for Packed<AttachElem> is made then we can get rid of this struct as only to needs to be passed around on the GlyphFragment. The from field will always just be the fragment's width then.
| fn layout_math(&self, ctx: &mut MathContext, styles: StyleChain) -> SourceResult<()> { | ||
| let mut fragment = ctx.layout_into_fragment(self.body(), styles)?; | ||
| let stretch = StretchInfo { from: fragment.width(), to: self.width(styles) }; | ||
| fragment.set_stretch(Some(stretch)); |
There was a problem hiding this comment.
Is there any point in adding stretch information to the frame before we check if the fragment can actually be stretched?
| let b = layout!(b, sub_style_chain)?; | ||
| if let Some(stretch) = base.stretch() { | ||
| let relative_to_width = | ||
| measure!(t, width).max(measure!(b, width)).max(stretch.from); |
There was a problem hiding this comment.
I think including stretch.from here makes interactions between math.stretch and math.attach a bit inconsistent. For example, a long attachment can cause the base to be stretched, but a shorter one doesn't cause the base to be compressed. If having width: auto with attachments means sizing the base relative to the attachments, then it should go both ways IMO.
#let base = math.stretch($=$, width: 250%)
$ // This gets shortened.
stretch(base, width: #50%)
// But this doesn't.
stretch(base)^"a" $| fn stretch_fragment( | ||
| ctx: &mut MathContext, | ||
| styles: StyleChain, | ||
| stretch: StretchInfo, | ||
| relative_to_width: Abs, | ||
| fragment: MathFragment, | ||
| ) -> MathFragment { |
There was a problem hiding this comment.
I guess if we're passing in the fragment already, we may as well pass it with a mutable reference and instead not return anything.
|
@mkorje Thanks for the review!
I can't really think of a glyph where that would make sense. I feel like the |
|
Me neither, though I guess there's nothing stopping a font from including such things for a glyph. It wouldn't hurt then to have an And yeah I agree that it isn't very Typst like. Adding the word horizontal or vertical felt too verbose and I couldn't think of a nice shortening of both words. |
|
Is there anything blocking this? |
|
Hi - I became a bit busy recently so I'm fine with someone taking this work and create a new PR (hence the drop in my recent PR counts). I could come back to this later if that's not already done. Also, is a 0.12 release imminent? |
|
I'd be happy to continue on this PR's work. It'd be nice to get this into 0.12. |
|
Closing in favor of #5030. Thanks all! |
No description provided.