Skip to content

Conversation

@henrikmidtiby
Copy link
Contributor

@henrikmidtiby henrikmidtiby commented Dec 17, 2025

Overview: What does this pull request change?

This PR changes a large part of the implementation of the MathTex class.
The reason is to deal with the issues related to splitting the tex string and then try to match the generated objects with parts of the original tex string.
The idea for the PR is based on this discussion on discord.
https://discord.com/channels/581738731934056449/1406977902788218892

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

Links to added or changed documentation pages

Further Information and Comments

This PR is an extension of #4473 "Maintain groups when importing svg files"

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

if mob is not None:
result.append(mob)
parent_name = vgroup_stack[-2]
for parent_name in vgroup_stack[:-2]:

Check warning

Code scanning / CodeQL

Variable defined multiple times Warning

This assignment to 'parent_name' is unnecessary as it is
redefined
before this value is used.
@henrikmidtiby
Copy link
Contributor Author

And here are some example code and the generated output.

class ExampleScene8(Scene):
    def construct(self):
        formula = MathTex(
            r"P(X=k) =",
            r"\binom{12}{k}",
            r"0.5^{k}",
            r"(1-0.5)^{12-k}",
            substrings_to_isolate=["k", "1", "12", "0.5"],
        ).scale(1.3)

        formula.set_color_by_tex("k", GREEN)
        formula.set_color_by_tex("12", RED)
        formula.set_color_by_tex("1", YELLOW)
        formula.set_color_by_tex("0.5", BLUE_D)
        self.add(formula)
ExampleScene8_ManimCE_v0 19 1
class ExampleScene11(Scene):
    def construct(self):
        t2cm = {"n": RED, "1": GREEN, "x": YELLOW}
        eq = MathTex(r"\sum_{1}^{n} x", tex_to_color_map=t2cm).scale(1.3)

        self.add(eq)
ExampleScene11_ManimCE_v0 19 1

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