ManimCommunity / manim

A community-maintained Python framework for creating mathematical animations.
https://www.manim.community
MIT License
25.27k stars 1.76k forks source link

Crash: Using a font with ligatures crashes manim-code #3959

Open gbin opened 1 week ago

gbin commented 1 week ago

Description of bug / unexpected behavior

If I try to render some Rust code with a ligature font like Fira Mono and add a :: it crashes

Expected behavior

Should render the code

How to reproduce the issue

Code for reproducing the problem ```py def play_rust(self): rust = """ impl<'cl> CuTask<'cl> for GenericPIDTask { type Input = input_msg!('cl, f32); type Output = output_msg!('cl, PIDControlOutput); fn process( &mut self, clock: &RobotClock, input: Self :: Input, output: Self :: Output) -> CuResult<()> { } } """ rendered_code = Code(code=rust, tab_width=2, background="window", language="Rust", font="Fira Code", font_size=20) self.add(rendered_code) self.wait(1) ```

Additional media files

Images/GIFs

Logs

Terminal output ``` File "/home/gbin/projects/CopperPitch/pres.py", line 461, in scene.render() File "/home/gbin/.local/share/virtualenvs/CopperPitch-aZYkSC0m/lib/python3.11/site-packages/manim_slides/slide/manim.py", line 132, in render super().render(*args, **kwargs) File "/home/gbin/.local/share/virtualenvs/CopperPitch-aZYkSC0m/lib/python3.11/site-packages/manim/scene/scene.py", line 229, in render self.construct() File "/home/gbin/projects/CopperPitch/pres.py", line 18, in construct self.play_rust() File "/home/gbin/projects/CopperPitch/pres.py", line 450, in play_rust rendered_code = Code(code=rust, tab_width=2, background="window", language="Rust", font="Fira Code", font_size=20) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/gbin/.local/share/virtualenvs/CopperPitch-aZYkSC0m/lib/python3.11/site-packages/manim/mobject/text/code_mobject.py", line 227, in __init__ self.code = self._gen_colored_lines() ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/gbin/.local/share/virtualenvs/CopperPitch-aZYkSC0m/lib/python3.11/site-packages/manim/mobject/text/code_mobject.py", line 350, in _gen_colored_lines code = Paragraph( ^^^^^^^^^^ File "/home/gbin/.local/share/virtualenvs/CopperPitch-aZYkSC0m/lib/python3.11/site-packages/manim/mobject/text/text_mobject.py", line 163, in __init__ self.lines_text = Text(lines_str, line_spacing=line_spacing, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/gbin/.local/share/virtualenvs/CopperPitch-aZYkSC0m/lib/python3.11/site-packages/manim/mobject/text/text_mobject.py", line 520, in __init__ self.submobjects = [*self._gen_chars()] ^^^^^^^^^^^^^^^^^ File "/home/gbin/.local/share/virtualenvs/CopperPitch-aZYkSC0m/lib/python3.11/site-packages/manim/mobject/text/text_mobject.py", line 621, in _gen_chars chars.add(self.submobjects[submobjects_char_index]) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ IndexError: list index out of range list index out of range ```

System specifications

System Details - OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): - RAM: - Python version (`python/py/python3 --version`): - Installed modules (provide output from `pip list`): ``` PASTE HERE ```
LaTeX details + LaTeX distribution (e.g. TeX Live 2020): + Installed LaTeX packages:

Additional comments

OliverStrait commented 1 week ago

Currently there is no support for ligature fonts in Code blocks because it will mess coloring indexing like so: Fira_mono_broken_colors Crashing is due to unexpected ligature text in Text-Mobject builder.

To resolve this, there is need for custom Paragraph builder that can store proper color indexing with ligatures.