3b1b / manim

Animation engine for explanatory math videos
MIT License
62.64k stars 5.81k forks source link

IndexError on TransformMatchingTex when use another latex font #2136

Open xiaoni0v0 opened 4 months ago

xiaoni0v0 commented 4 months ago

When I use Tex and play TransformMatchingTex animations, an error occurred. The error is: IndexError: list index out of range.

Code and Error

Code:

a = Tex(r'a+b=c').scale(3)
b = Tex(r'a+b=c,c\in\mathbb{Z}').scale(3)
self.add(a)
self.play(TransformMatchingTex(a, b, matched_keys=['a+b=c']))

Error:

           WARNING  Estimated size of a+b=c,c\in\mathbb{Z}   tex_mobject.py:222
                    does not match true size                                   

...

  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "E:\Programs\python_tips_animation\.venv\Scripts\manimgl.exe\__main__.py", line 7, in <module>
  File "E:\Programs\python_tips_animation\manimlib\__main__.py", line 25, in main
    scene.run()
  File "E:\Programs\python_tips_animation\manimlib\scene\scene.py", line 163, in run
    self.construct()
  File "E:\Programs\python_tips_animation\for_tips\learning_transform_match.py", line 10, in construct
    self.play(TransformMatchingTex(a, b, matched_keys=['a+b=c']))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Programs\python_tips_animation\manimlib\animation\transform_matching_parts.py", line 135, in __init__
    *self.matching_blocks(source, target, matched_keys, key_map),
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Programs\python_tips_animation\manimlib\animation\transform_matching_parts.py", line 166, in matching_blocks
    if target[j] in sub_target.family_members_with_points():
       ~~~~~~^^^
  File "E:\Programs\python_tips_animation\manimlib\mobject\svg\string_mobject.py", line 551, in __getitem__
    return super().__getitem__(value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\Programs\python_tips_animation\manimlib\mobject\mobject.py", line 399, in __getitem__
    return self.split().__getitem__(value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: list index out of range

It's very strange that when I remove the specified font \mathbb{Z} and just use Z, the errors and warnings disappear.

Environment

OS System: Win 10 manim version: Latest Version of Manim python version: 3.12.1