Repository navigation
Add math.stretch element function - #5030
Merged
Merged
Conversation
laurmaedje
reviewed
Sep 26, 2024
mkorje
force-pushed
the
math-stretch-elem
branch
from
September 26, 2024 13:20
be7dbe4 to
1440605
Compare
laurmaedje
reviewed
Sep 26, 2024
laurmaedje
reviewed
Sep 26, 2024
laurmaedje
reviewed
Sep 26, 2024
laurmaedje
left a comment
Member
There was a problem hiding this comment.
found one more thing. otherwise, it looks ready to merge from my end.
Member
|
Thank you. Nice work! Also thanks to @Leedehai for getting the ball rolling on this! |
1 task done
Collaborator
Author
|
I've found an issue I made when implementing this: stretching things vertically doesn't work at all with an attachment. I'll try to fix this. |
Dikluwe
pushed a commit
to Dikluwe/typst-crystalline
that referenced
this pull request
Sep 12, 2026
This file contains hidden or 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
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.
Closes #1304. This PR continues @Leedehai's work in #4569.
This PR adds the element function
math.stretch, which allows you to stretch a glyph horizontally or vertically (only if the glyph is stretchable in the font - this means it has entries in the MathVariants table). It automatically stretches the glyph along the correct axis. You specify a size to stretch the glyph to with thesizeparameter, which is auto or relative (to the glyph's current size). This size parameter defaults toauto, which will only have an effect if a top/bottom attachment is attached tostretch(...).When there are top/bottom attachments present, and when
math.stretch(attach: true)is set (trueis the default), the size parameter will instead be relative to the top/bottom attachments' width. Here is also whereautocomes into play, which will stretch the glyph to the size of the top/bottom attachments.The example below sums up how it all works.
See the tests for some more examples.
Implementation
I've been able to avoid adding to the proliferation of fields on the structs in
fragment.rsby checking if the base of an attachment is aStretchElemand then peeking inside.The
StretchElemlives instretch.rs. I've moved thedelimiter_alignmentfunction there frommod.rs. I've also changed some of the code inlr.rsto avoid some repetition, by relying on the functions instretch.rs.If a glyph for some reason has both horizontal and vertical variants, I've opted to panic for now. This should probably never happen, and if it does we'd want to know the culprit font...
I also don't know if the name of the parameter
attachis great. Idk what else to name it though.