manim/docs
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
..
i18n fix 360° to 180° in quickstart tutorial (#3498) 2023-12-06 18:06:35 +01:00
source fix: MathTex double-brace splitting no longer fires on natural LaTeX }} (#4602) 2026-02-22 10:48:51 +01:00
html Fix formatting building blocks (#3515) 2023-12-12 10:45:39 +01:00
make.bat Added mixed-line-ending to .pre-commit-config.yaml (#1294) 2021-04-09 02:28:31 +02:00
Makefile Modification of the .pot files cleaning system, and ran it on the existing sources. (#2448) 2022-01-10 10:04:40 +00:00
requirements.txt Rewrite installation instructions (#3930) 2024-12-06 18:50:18 -05:00
rtd-requirements.txt Made improvements to the :doc:configuration tutorial (#2414) 2022-01-06 14:31:22 +08:00
skip-manim Fix formatting building blocks (#3515) 2023-12-12 10:45:39 +01:00