Skip to content

Conversation

@henrikmidtiby
Copy link
Contributor

Overview: What does this pull request change?

This is a work in progress for being able to access groups in objects created from SVG files.
I hope that this could be useful for addressing the following issues and pull requests:

When reading data from a SVG file, maintain the groupings of the document, which also allows the user to select (groups of) elements by their id.

Motivation and Explanation: Why and how do your changes improve the library?

Links to added or changed documentation pages

Further Information and Comments

The following example demonstrates how custom grouping of elements inside a latex equation can be achieved. This is based on an idea presented by @behackl in the discord dev-chat the 18th of august 2025.

from manim import *

class SvgTest3(Scene):
    def construct(self):
        t = MathTex(r'\frac{a}{b \special{dvisvgm:raw <g id="unique02">}\cdot c \special{dvisvgm:raw </g>}}')
        t.set_color(WHITE)
        t.id_to_vgroup_dict['unique02'].set_color(RED)
        self.add(t)

renders like

SvgTest3_ManimCE_v0 19 0

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@henrikmidtiby
Copy link
Contributor Author

henrikmidtiby commented Nov 11, 2025

Currently the PR triggers the following 27 errors in the testsuite.

Group 1
FAILED tests/module/animation/test_creation.py::test_run_time_for_non_empty_text - AssertionError: assert np.float64(0.9) == np.float64(0.5)

Group 2
FAILED tests/module/mobject/svg/test_svg_mobject.py::test_single_path_turns_into_sequence_of_points - AssertionError: [VGroup(VGroup of 1 submobjects), VGroup(VGroup of 1 submobjects), VGroup(VGroup of 2 submobjects), VGroup(VGroup of 0 ...
FAILED tests/module/mobject/svg/test_svg_mobject.py::test_closed_path_does_not_have_extra_point - AssertionError: [VGroup(VGroup of 1 submobjects), VGroup(VGroup of 1 submobjects), VGroup(VGroup of 1 submobjects), VGroup(VGroup of 1 ...
FAILED tests/module/mobject/svg/test_svg_mobject.py::test_close_command_closes_last_move_not_the_starting_one - AssertionError: [VGroup(VGroup of 1 submobjects), VGroup(VGroup of 1 submobjects), VGroup(VGroup of 1 submobjects), VGroup(VGroup of 1 ...

Group 3
FAILED tests/module/mobject/text/test_texmobject.py::test_tex_whitespace_arg - AssertionError: assert 0 == 5
FAILED tests/module/mobject/text/test_texmobject.py::test_tex_non_whitespace_arg - AssertionError: assert 5 == 6
FAILED tests/opengl/test_texmobject_opengl.py::test_tex_whitespace_arg - AssertionError: assert 0 == 5
FAILED tests/module/mobject/text/test_texmobject.py::test_tex_white_space_and_non_whitespace_args - AssertionError: assert 5 == 7
FAILED tests/opengl/test_texmobject_opengl.py::test_tex_non_whitespace_arg - AssertionError: assert 5 == 6
FAILED tests/opengl/test_texmobject_opengl.py::test_tex_white_space_and_non_whitespace_args - AssertionError: assert 5 == 7
FAILED tests/test_graphical_units/test_tex_mobject.py::test_preserve_tex_color - AssertionError: assert 6 == 10

Group 4
FAILED tests/test_code_mobject.py::test_code_initialization_from_string - IndexError: list index out of range
FAILED tests/test_code_mobject.py::test_code_initialization_from_file - IndexError: list index out of range
FAILED tests/test_code_mobject.py::test_line_heights_initial_whitespace - IndexError: list index out of range
FAILED tests/test_code_mobject.py::test_code_initialization_style_correct_color - IndexError: list index out of range

Group 5
FAILED tests/module/mobject/test_table.py::test_highlight_cell_in_table - RecursionError: maximum recursion depth exceeded

Group 6
FAILED tests/test_graphical_units/test_img_and_svg.py::test_Arcs02 - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_MultipleTransform - AssertionError: 
FAILED tests/test_graphical_units/test_text.py::test_Text2Color - IndexError: list index out of range
FAILED tests/test_graphical_units/test_img_and_svg.py::test_SkewXTransform - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_SkewYTransform - AssertionError: 
FAILED tests/test_graphical_units/test_img_and_svg.py::test_RotateTransform - AssertionError: 
FAILED tests/test_graphical_units/test_tex_mobject.py::test_set_opacity_by_tex - AssertionError: 

Group 7
FAILED tests/test_graphical_units/test_transform_matching_parts.py::test_TransformMatchingTex - ValueError: operands could not be broadcast together with shapes (80,3) (108,3)
FAILED tests/test_graphical_units/test_transform_matching_parts.py::test_TransformMatchingTex_FadeTransformMismatches - ValueError: operands could not be broadcast together with shapes (80,3) (108,3)
FAILED tests/test_graphical_units/test_transform_matching_parts.py::test_TransformMatchingTex_TransformMismatches - ValueError: operands could not be broadcast together with shapes (80,3) (108,3)
FAILED tests/test_graphical_units/test_transform_matching_parts.py::test_TransformMatchingTex_FadeTransformMismatches_NothingToFade - ValueError: operands could not be broadcast together with shapes (116,3) (108,3)

The error in group 1 is a direct consequence from maintaining the tree structure in the SVG.
The VGroups that are added to maintain the grouping, is also animated which increases the time to animate the test example.

The errors in group 2 are also related to the tree structure from the SVG.

Errors in group 3 seems related to passing multiple tex strings to the Tex mobject.

Group 4 errors are related to Code mobject.

The recursion depth exceeded in group 5, is associated with the color initialization.

The failed graphical unit tests in group 6 are either related to color and opacity issues or the Text object in the imported SVG file.

Finally the errors in group 7 are all related to the number of points that is being interpolated when interpolating between two mobjects. Apparently the number of points change from one object to the next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

1 participant