Skip to content

Fix MathTypst grouping changing expression layout - #4935

Closed
ramgao wants to merge 1 commit into
ManimCommunity:mainfrom
ramgao:fix/4931-mathtypst-grouping-layout
Closed

Fix MathTypst grouping changing expression layout#4935
ramgao wants to merge 1 commit into
ManimCommunity:mainfrom
ramgao:fix/4931-mathtypst-grouping-layout

Conversation

@ramgao

@ramgao ramgao commented Aug 12, 2026

Copy link
Copy Markdown

Overview: What does this pull request change?

Fixes MathTypst selection groups so adding {{ ... }} metadata no longer changes the grouped expression's math style, spacing, or geometry.

Fixes #4931.

Motivation and Explanation: Why and how do your changes improve the library?

The existing manimgrp helper wrapped selected content in #box(body). That moved the body out of its surrounding math context, which changed display-style operators and glyph styling such as the x in dif x.

The helper now uses a temporary link with a private marker URL. Typst preserves the original math context and emits SVG link markers after the visible elements. During SVG post-processing, Manim converts only those private markers into labeled wrappers used by select(), then removes the links and their transparent rectangles before SVG import.

A regression test compares every rendered point of the issue's grouped integral with the identical ungrouped expression and verifies that selection still covers the full group.

Links to added or changed documentation pages

No documentation pages changed.

Testing

  • uv run pytest tests/module/mobject/text/test_typst_mobject.py -q — 35 passed
  • uv run pytest tests/module/mobject/text -q — 114 passed
  • uv run pytest --skip_slow -q — 1035 passed, 73 skipped, 6 xfailed, 2 xpassed
  • uv run pre-commit run --files manim/mobject/text/typst_mobject.py tests/module/mobject/text/test_typst_mobject.py — all hooks passed
  • Manual reproducer: grouped and ungrouped expressions both measured 3.195333371 × 1.559187513, contained 812 points, and had identical point geometry; select("integral") returned all 9 leaves.

Further Information and Comments

The implementation relies on the SVG link-marker structure emitted by the supported Typst 0.14 series. The regression and existing Typst selection tests exercise this integration.

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@behackl

behackl commented Aug 25, 2026

Copy link
Copy Markdown
Member

Thanks for taking a look at this and implementing the suggestion from #4931!

I've spent some more time checking details about this approach and unfortunately have found that it comes with a bunch of unfortunate incompatibilities: nesting of groups is not possible when using the link-based implementation, and it also breaks text ligatures in a subtle way. I'll spend some more time to find a better and more robust approach and will either update #4931 or put up a PR myself.

Closing this as it doesn't improve the overall situation in a robust way.

@behackl behackl closed this Aug 25, 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.

MathTypst grouping can change math styling and spacing

2 participants