Skip to content

Fix MathTypst grouping changing expression layout - #4935

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

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

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

1 participant