Replies: 1 comment
-
best would be if you came over to Discord and presented a complete and runable short code snippet, instead of loose bits... In general you cannot run two different animations on the same object at the same time as you are trying. Secondly the most flexible way to modify Splitting a Using class binomnom(Scene):
def construct(self):
binom_n_2 = MathTex(r"\binom{n+1}{2}", font_size=30)
# uncomment for index labels
#self.add(binom_n_2)
#self.add(index_labels(binom_n_2[0]).set_color(RED))
#return
self.play(Write(binom_n_2))
self.play(
binom_n_2[0][1:4].animate.set_color(PURE_RED),
run_time=1.5
)
self.wait() binomnom.mp4 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I’m working on a didactic Manim scene where I’m transitioning from a specific binomial identity to a general one using symbolic expressions.
One of the expressions I use is:
binom_n_2 = MathTex(r"\binom{n+1}{2}", font_size=30)
Problem:
I want to highlight only the numerator (n+1) in this binomial coefficient. For example:
self.play(binom_n_2[1].animate.set_color(GOLD))
But this throws an IndexError or doesn’t isolate just the numerator — because the MathTex object only contains a single submobject for the entire \binom{n+1}{2}. When I do something like:
for i, part in enumerate(binom_n_2): print(i, part)
it only prints one part (index 0), so accessing binom_n_2[1] fails.What I've already tried:
teil1 = MathTex(r"\binom{", font_size=30) teil2 = MathTex(r"n+1", font_size=30).set_color(GOLD) teil3 = MathTex(r"}{2}", font_size=30)
but it doesn't work.
binom_n_2 = MathTex( r"\binom{n+1}{2}", substrings_to_isolate=["n+1"], font_size=30 )
but surprisingly, this does not work inside the binomial: the n+1 part is not separately accessible, and it still appears as a single group.MathTex(r"\binom{", r"n+1", r"}{2}")
binom[1].set_color(GOLD)
but this crashes LaTeX or fails to render correctly (Missing } inserted error).Goal:
I want to synchronously highlight two expressions.
The second one woks with this
n1_zeile = MathTex(r"(", r"n+1", r")\text{-te Zeile}", font_size=32, color=WHITE)
followed by thisself.play( Transform(fünfzehn, binom_n_2), n1_zeile[1].animate.set_color(GOLD), # ✅ works! binom_n_2[1].animate.set_color(GOLD), # ❌ fails or ignored! run_time=1.5 )
My question:
How can I safely and correctly color and than Indicate only the numerator (n+1) in a binomial coefficient and how can I ensure that happens in sync with another highlight (as in my self.play(...))?
Any suggestions or examples would be super appreciated. Thanks!
Isa
Beta Was this translation helpful? Give feedback.
All reactions