manim/tests
Benjamin Hackl d999d422c9
Introduce first-class support for rendering text and markup via Typst (optional dependency) (#4681)
* feat: add TypstMobject and TypstMathMobject for first-class Typst support

Implement the initial TypstMobject proposal (see agents/typst.md):

- TypstMobject: renders arbitrary Typst markup to SVG via the 'typst'
  Python package (self-contained Rust binary, no system install needed),
  then imports through SVGMobject.
- TypstMathMobject: convenience subclass that wraps input in Typst math
  delimiters ($ ... $).

Pipeline: user string → wrap in minimal Typst document (auto-sized page,
transparent background) → write .typ file → compile to SVG via
typst.compile() → import via SVGMobject → scale/center/recolor.

Key details:
- Compilation helper in manim/utils/typst_file_writing.py with SHA-256
  content-hash caching (same scheme as the LaTeX pipeline).
- font_size property mirrors SingleStringMathTex: compile at fixed 11pt,
  scale after import using initial_height / SCALE_FACTOR_PER_FONT_POINT.
- init_colors() recolors black submobjects to self.color (Typst default
  fill is black), preserving any explicit Typst colors.
- path_string_config enables curve subdivision for smooth animation.
- 'typst' added as optional dependency group in pyproject.toml.
- 10 tests covering creation, font_size, caching, preamble, and repr.

* feat(typst): add sub-expression selection via {{ }} groups and .select()

- Override modify_xml_tree in Typst to convert data-typst-label
  attributes to id attributes before svgelements parsing (avoids
  attribute inheritance issue with data-* attributes)
- Add Typst.select(key) method accepting str labels or int indices
  to retrieve VGroup sub-expressions from id_to_vgroup_dict
- Implement {{ }} double-brace preprocessor on TypstMath:
  - {{ content }} → manimgrp("_grp-N", content) (auto-numbered)
  - {{ content : label }} → manimgrp("label", content) (named)
  - Skips {{ }} inside string literals and [...] content blocks
  - Uses math-mode call convention (no # prefix) to keep args in
    math mode
- Auto-inject manimgrp preamble when groups are detected
- Add 12 new tests covering label mapping, nesting, select(),
  error handling, and preprocessor edge cases

* Remove unneeded assert line

* Generalize some more critical hard-coded LaTeX assumptions

* Fix syntax error

* Support Typst labels in existing APIs

* Add ManimTextLabel typing alias

* Preserve Typst SVG stroke widths by default

* Calibrate Typst font sizing against TeX

* Add Typst mobject documentation

* Track Typst baseline frames

* Document Typst baseline frame tracking

* Add Typst section to text guide

* Polish Typst docs and label handling

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Improve Typst stroke scaling and docs examples

* Tune Typst SVG stroke scaling

* Restore Typst math example wording

* Fix pre-commit issues for Typst branch

* Fix number line runtime typing import

* Exclude Typst autogenerated .rst files

* Use Manim directive in docstrings and fix wrong key in Typst.select() docstring

* Fix GroupedMath comments

---------

Co-authored-by: Toon Verstraelen <Toon.Verstraelen@UGent.be>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
Co-authored-by: Francisco Manríquez Novoa <francisco.manriquezn@usm.cl>
2026-06-11 03:54:21 +00:00
..
control_data Rewrite MathTex to make it more robust regarding splitting (#4515) 2026-02-16 14:22:56 +01:00
helpers Resolve more race conditions potentially happening during directory creation (#4589) 2026-02-12 08:18:26 +01:00
interface Bump minimum Python to 3.11 and av to 14.0.1 (#4385) 2026-01-12 14:27:48 +01:00
miscellaneous Update dependency constraints, fix deprecation warnings (#3376) 2023-12-06 14:44:13 +01:00
module Introduce first-class support for rendering text and markup via Typst (optional dependency) (#4681) 2026-06-11 03:54:21 +00:00
opengl Fix YELLOW_C and add PURE_CYAN, PURE_MAGENTA and PURE_YELLOW (#4562) 2026-02-16 20:07:09 -03:00
test_graphical_units Add support for negative z-index in AnimationGroup (#4389) 2026-02-22 11:24:32 +00:00
test_logging Use ruff for pytest style (#3872) 2024-07-21 14:37:57 +00:00
test_plugins Resolve more race conditions potentially happening during directory creation (#4589) 2026-02-12 08:18:26 +01:00
test_scene_rendering feat: add a 'seed' option for reproducible outputs (#4532) 2026-01-20 22:24:32 +01:00
utils Enable strict=True for zip() where safe (#4547) 2026-02-11 10:39:25 +01:00
__init__.py CI: Add support for using Opengl in Subprocess (Windows) (#1987) 2021-08-31 13:16:20 +01:00
assert_utils.py Migrate more os.path to pathlib in tests (#2991) 2022-10-26 19:51:38 +02:00
conftest.py Add support for Python 3.13 (#3967) 2024-12-02 08:50:14 +01:00
standard_config.cfg Add OpenGLMobject tests (#2080) 2021-09-28 07:47:06 +08:00
template_generate_graphical_units_data.py Upgraded typehints (#2429) 2022-01-20 12:26:21 +08:00
test_camera.py Allow using :meth:.MovingCamera.auto_zoom without animation (#2693) 2022-04-22 23:07:52 +02:00
test_code_mobject.py Better parsing of color styles in CodeMobject (#4454) 2025-10-26 08:47:47 +01:00
test_config.py Fix scene skipping for config.upto_animation_number (-n flag in CLI) set to 0 to end after first animation (#4013) 2024-11-13 21:23:50 -03:00
test_ipython_magic.py Change from tempconfig to a config fixture in tests (#3853) 2024-07-12 22:41:51 +02:00
test_linear_transformation_scene.py Use ruff for pytest style (#3872) 2024-07-21 14:37:57 +00:00