From b3284a57138cb5646c23a070d01c0b606e6f4c17 Mon Sep 17 00:00:00 2001 From: Taksh Date: Wed, 1 Jul 2026 20:26:17 +0530 Subject: [PATCH 1/2] fix(svg): propagate constructor z_index to glyph submobjects Glyphs are added after super().__init__ stored self.z_index, so a z_index passed to Text/MathTex/SVGMobject never reached the glyphs and was ignored when rendering z-order. Propagate it to the whole family. Fixes #4667 Co-authored-by: Cursor --- manim/mobject/svg/svg_mobject.py | 5 +++++ tests/module/mobject/text/test_text_mobject.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/manim/mobject/svg/svg_mobject.py b/manim/mobject/svg/svg_mobject.py index c296130a27..23b6170712 100644 --- a/manim/mobject/svg/svg_mobject.py +++ b/manim/mobject/svg/svg_mobject.py @@ -158,6 +158,11 @@ def __init__( ) self.move_into_position() + # Glyph submobjects are added after super().__init__ set self.z_index, + # so a z_index passed to the constructor never reached them. Propagate + # it so the whole SVG (e.g. Text/MathTex) shares one z_index. + self.set_z_index(self.z_index) + def init_svg_mobject(self, use_svg_cache: bool) -> None: """Checks whether the SVG has already been imported and generates it if not. diff --git a/tests/module/mobject/text/test_text_mobject.py b/tests/module/mobject/text/test_text_mobject.py index 2e656b90ae..a3f446e019 100644 --- a/tests/module/mobject/text/test_text_mobject.py +++ b/tests/module/mobject/text/test_text_mobject.py @@ -17,6 +17,21 @@ def test_font_size(): assert round(markuptext_string.font_size, 5) == 14.4 +def test_z_index_propagates_to_glyphs(): + """A z_index passed to the constructor must reach the glyph submobjects, + otherwise the z-ordering is ignored during rendering (see issue #4667). + """ + text = Text("AB", z_index=3) + assert text.z_index == 3 + assert all(glyph.z_index == 3 for glyph in text.family_members_with_points()) + + markup = MarkupText("AB", z_index=3) + assert all(glyph.z_index == 3 for glyph in markup.family_members_with_points()) + + # The default must remain unchanged. + assert all(glyph.z_index == 0 for glyph in Text("AB").family_members_with_points()) + + def test_font_warnings(): def warning_printed(font: str, **kwargs) -> bool: io = StringIO() From 9ac7fa3a0ed22927d1def33fddab9a21fcfe9257 Mon Sep 17 00:00:00 2001 From: Taksh Date: Fri, 3 Jul 2026 17:24:29 +0530 Subject: [PATCH 2/2] fix(svg): propagate z_index without set_z_index for OpenGL compatibility Assign z_index on the family directly and guard with getattr so the OpenGL renderer (which lacks set_z_index / a z_index attribute) no longer crashes. Co-authored-by: Cursor --- manim/mobject/svg/svg_mobject.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/manim/mobject/svg/svg_mobject.py b/manim/mobject/svg/svg_mobject.py index 23b6170712..26834f7e0e 100644 --- a/manim/mobject/svg/svg_mobject.py +++ b/manim/mobject/svg/svg_mobject.py @@ -160,8 +160,12 @@ def __init__( # Glyph submobjects are added after super().__init__ set self.z_index, # so a z_index passed to the constructor never reached them. Propagate - # it so the whole SVG (e.g. Text/MathTex) shares one z_index. - self.set_z_index(self.z_index) + # it so the whole SVG (e.g. Text/MathTex) shares one z_index. Guard with + # getattr since the OpenGL renderer does not track z_index as an attribute. + z_index = getattr(self, "z_index", None) + if z_index is not None: + for submob in self.get_family(): + submob.z_index = z_index def init_svg_mobject(self, use_svg_cache: bool) -> None: """Checks whether the SVG has already been imported and