manim/docs/source
Benjamin Hackl 000e7792bd
fix: MathTex double-brace splitting no longer fires on natural LaTeX }} (#4602)
* fix: replace double-brace splitting regex with state-machine parser

The previous re.split(r'{{|}}', ...) call split on any occurrence of
{{ or }} in the input string, which broke strings whose only }} came
from closing two nested LaTeX brace groups (e.g. ^{\frac{Mq}{M+m}}).

The new _split_double_braces() static method uses a character-level
state machine with three guards:

* Escape priority: \\ is consumed before \{ / \}, so \\}} is
  correctly read as an escaped backslash followed by a real }}, not
  misinterpreted as \ + \} + lone }.

* Whitespace-gated opener: {{ is only treated as a Manim group opener
  at the start of the string or after whitespace. Naturally-occurring
  {{ in LaTeX is usually preceded by non-whitespace (e.g. \frac{{{n}}}
  or a^{{2}}), so this eliminates the most common false positives.

* Depth-tracking closer: inside a Manim group, }} only closes the
  group when the inner brace depth is zero, so {{ a^{b^{c}} }} is
  handled correctly and nested LaTeX }} cannot trigger an early close.

Fixes #4601.

* docs: document double-brace whitespace requirement

Add a Notes section to the MathTex docstring explaining:
- how {{ }} splits a string into submobjects
- that {{ must be at start-of-string or preceded by whitespace
- that this leaves natural LaTeX like \frac{{{n}}}{k} untouched
- the { { ... } } escape hatch when a split is not wanted

Apply the same explanation to the double-brace paragraph in
docs/source/guides/using_text.rst.

* fix: use r-string for _split_double_braces docstring, halve backslash escaping
2026-02-22 10:48:51 +01:00
..
_static Add option to run examples directly with binder (#3427) 2023-11-10 21:52:43 +01:00
_templates Added support for Manim type aliases in Sphinx docs + Added new TypeAliases (#3484) 2023-12-29 19:04:31 +01:00
changelog Prepare new release, v0.20.0 (#4599) 2026-02-20 23:50:31 +01:00
contributing Add VectorNDLike type aliases (#4068) 2025-08-01 04:31:30 +00:00
faq Fix broken aquabeam OpenGL link using Wayback Machine (#4545) 2026-01-25 12:33:39 +00:00
guides fix: MathTex double-brace splitting no longer fires on natural LaTeX }} (#4602) 2026-02-22 10:48:51 +01:00
installation Revert "Set the default Python version to 3.13 in the uv installation guide (…" (#4534) 2026-01-18 08:49:10 +01:00
reference_index Add classes MethodWithArgs, SceneInteractContinue and SceneInteractRerun inside new module manim.data_structures (#4315) 2025-07-25 00:37:14 +02:00
tutorials docs: add explanation about the rate_func in the custom animation (#4278) 2025-06-11 09:50:11 +02:00
changelog.rst Prepare new release, v0.20.0 (#4599) 2026-02-20 23:50:31 +01:00
conduct.md Added code of conduct (#935) 2021-01-18 19:14:57 +05:30
conf.py Rework and consolidate release changelog script, add previously skipped changelog entries (#4568) 2026-02-04 10:10:39 +01:00
contributing.rst Improve documentation section about contributing to docs (#3555) 2023-12-30 00:22:24 +01:00
examples.rst Refactor Rotating and add docstrings to Mobject.rotate() and Rotating (#4147) 2025-06-22 04:15:12 +00:00
index.rst Added license information to documentation landing page (#3986) 2025-08-18 23:16:45 +02:00
installation.rst Rewrite installation instructions (#3930) 2024-12-06 18:50:18 -05:00
plugins.rst Change project management tool from poetry to uv (#4138) 2025-02-02 17:16:46 +01:00
reference.rst Added :class:.ChangeSpeed, an animation wrapper that allows to smoothly change the speed at which an animation is played (#2749) 2022-07-06 16:39:55 +02:00
robots.txt Flake8 Changes + Fixing Warnings (#1968) 2021-09-03 13:45:48 -04:00
tutorials_guides.rst Refactored structure of documentation; added :doc:FAQ section <faq/index> (#2732) 2022-05-27 08:45:31 +00:00