Skip to content

Improve positioning of multiple accents and attachments - #3059

Merged
laurmaedje merged 9 commits into
typst:mainfrom
EpicEricEE:accent-attach
Jan 4, 2024
Merged

laurmaedje merged 9 commits into
typst:mainfrom
EpicEricEE:accent-attach

Conversation

@EpicEricEE

Copy link
Copy Markdown
Contributor

Fixes #1672

The accent attachment position and italics correction is now stored in the fragment, so that it can be preserved when new elements create a frame fragment around it. This happens in accent, cancel and op elements, thus stacked accents are now properly aligned on top of each other.

In #1129, the positioning of attachments for character boxes was fixed. However, that only worked for "pure" characters, so accent or cancel elements were not considered as character boxes. To fix that, I introduced the text_like property for each math fragment, which replaces the is_character_box check. This property is set to true for

  • frame fragments created in layout_text
  • glyph and variant fragments if they aren't of class "large"
    (to keep current behavior of attachments for large operators like sum and integral)
  • fragments created in accent, cancel and op if the underlying fragment is text like

A more difficult contender is MathRow as there is no single base fragment from where the property values can be inherited.

There are some small differences, as previously all "atomic text frames" were character boxes, whereas now that is only the case for frame fragments with text_like set to true. This means that when wrapping a text-like fragment in a box or similar, the properties are not preserved. For example:

$ #box[$f$]_a^a != f_a^a $

renders as (left: old behavior, right: new behavior)

image

As can be seen, the boxed version is no longer considered a character box as the text_like property is lost with the box, thus the top attachment is shifted up more.

Maybe this solution is a bit too naive, but until a bigger refactor is planned, it should be alright.

@Leedehai

Copy link
Copy Markdown
Contributor

Nice! Does this fix #3043 ? If so, could you please add a test case for it as well? If not, don't let that issue block the PR.

@EpicEricEE

Copy link
Copy Markdown
Contributor Author

No, unfortunately it doesn't. As primes are attached with the attach element, it would likely require some special handling, so that attach(x^2, t: 3) doesn't end up looking like x^23.

As a workaround, you can use something like A^('2) for now.

@laurmaedje
laurmaedje added this pull request to the merge queue Jan 4, 2024
@laurmaedje

Copy link
Copy Markdown
Member

Thank you!

Merged via the queue into typst:main with commit 55536e2 Jan 4, 2024
@EpicEricEE
EpicEricEE deleted the accent-attach branch January 4, 2024 15:18
Dikluwe pushed a commit to Dikluwe/typst-crystalline that referenced this pull request Sep 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong sub-/superscript alignment with accents

3 participants