Repository: ManimCommunity/manim
File: manim/mobject/text/tex_mobject.py (Python)

Code before:
        matched_string = first_match.group(2)
        post_match = first_match.group(3)
        pre_string = rf"\special{{dvisvgm:raw <g id='unique{ssIdx:03d}ss'>}}"
        post_string = r"\special{dvisvgm:raw </g>}"
        self.matched_strings_and_ids.append((matched_string, f"unique{ssIdx:03d}ss"))
        processed_string = pre_match + pre_string + matched_string + post_string
        unprocessed_string = post_match
        return processed_string, unprocessed_string

    def _break_up_by_substrings(self) -> Self:
        """
        Reorganize existing submobjects one layer
        deeper based on the structure of tex_strings (as a list
        of tex_strings)
        """
        new_submobjects: list[VMobject] = []
        try:
            for tex_string, tex_string_id in self.matched_strings_and_ids:
                if tex_string_id[-2:] == "ss":
                    continue
                mtp = MathTexPart()
                mtp.tex_string = tex_string
                mtp.add(*self.id_to_vgroup_dict[tex_string_id].submobjects)
                new_submobjects.append(mtp)
        except KeyError as e:
            print(f"KeyError: {e}")
            new_submobjects.append(self.id_to_vgroup_dict["root"])
        self.submobjects = new_submobjects
        return self

    def get_part_by_tex(self, tex: str, **kwargs: Any) -> VGroup | None:
        for tex_str, match_id in self.matched_strings_and_ids:
            if tex_str == tex:
                return self.id_to_vgroup_dict[match_id]
        return None

    def set_color_by_tex(
        self, tex: str, color: ParsableManimColor, **kwargs: Any
    ) -> Self:
        for tex_str, match_id in self.matched_strings_and_ids:
            if tex_str == tex:
                self.id_to_vgroup_dict[match_id].set_color(color)
        return self

    def set_opacity_by_tex(
        self,
        tex: str,
        opacity: float = 0.5,
        remaining_opacity: float | None = None,
        **kwargs: Any,
    ) -> Self:

Review comment (suggestion):
Again, more context + logger?


```suggestion
            logger.error(f"MathTex: Could not find SVG group for tex part '{tex_string}' (id: {tex_string_id}). Using fallback to root group.")
```

Code after:
    def _handle_match(self, ssIdx: int, first_match: re.Match) -> tuple[str, str]:
        pre_match = first_match.group(1)
        matched_string = first_match.group(2)
        post_match = first_match.group(3)
        pre_string = (
            rf"\special{{dvisvgm:raw <g id='unique{ssIdx:03d}{MATHTEX_SUBSTRING}'>}}"
        )
        post_string = r"\special{dvisvgm:raw </g>}"
        self.matched_strings_and_ids.append(
            (matched_string, f"unique{ssIdx:03d}{MATHTEX_SUBSTRING}")
        )
        processed_string = pre_match + pre_string + matched_string + post_string
        unprocessed_string = post_match
        return processed_string, unprocessed_string

    @property
    def _substring_matches(self) -> list[tuple[str, str]]:
        """Return only the 'ss' (substring_to_isolate) matches."""
        return [
            (tex, id_)
            for tex, id_ in self.matched_strings_and_ids
            if id_.endswith(MATHTEX_SUBSTRING)
        ]

    @property
    def _main_matches(self) -> list[tuple[str, str]]:
        """Return only the main tex_string matches."""
        return [
            (tex, id_)
            for tex, id_ in self.matched_strings_and_ids
            if not id_.endswith(MATHTEX_SUBSTRING)
        ]

    def _break_up_by_substrings(self) -> Self:
        """
        Reorganize existing submobjects one layer
        deeper based on the structure of tex_strings (as a list
        of tex_strings)
        """
        new_submobjects: list[VMobject] = []
        try:
            for tex_string, tex_string_id in self._main_matches:
                mtp = MathTexPart()
                mtp.tex_string = tex_string
                mtp.add(*self.id_to_vgroup_dict[tex_string_id].submobjects)
                new_submobjects.append(mtp)
        except KeyError:
            logger.error(
                f"MathTex: Could not find SVG group for tex part '{tex_string}' (id: {tex_string_id}). Using fallback to root group."
            )
            new_submobjects.append(self.id_to_vgroup_dict["root"])