Tutorial: An Equation Explainer
Solve 2x + 3 = 11 one step at a time, with each step changing smoothly into the next. This is the pattern behind most algebra videos: split equations into parts, then let TransformMatchingTex move the parts that stay.
1. Write the equation
from pymations import *
title = Text("Solve for x", font_size=40).to_edge(UP)
step1 = MathTex("2x", "+", "3", "=", "11", font_size=72)
play(Write(title))
play(Write(step1))
wait()
Each string is one part of the equation. Splitting it this way is what lets the next steps move pieces separately.
2. Take 3 from both sides
step2 = MathTex("2x", "=", "11", "-", "3", font_size=72)
play(TransformMatchingTex(step1, step2))
wait()
Add this under step 1 and run it. 2x, =, 11 and 3 are parts of both equations, so they slide to their new places; + fades out and - fades in.
3. Finish it
step3 = MathTex("2x", "=", "8", font_size=72)
play(TransformMatchingTex(step2, step3))
wait()
step4 = MathTex("x", "=", "4", font_size=72)
play(TransformMatchingTex(step3, step4))
play(Circumscribe(step4, color=YELLOW))
wait()
The whole file
from pymations import *
title = Text("Solve for x", font_size=40).to_edge(UP)
step1 = MathTex("2x", "+", "3", "=", "11", font_size=72)
step2 = MathTex("2x", "=", "11", "-", "3", font_size=72)
step3 = MathTex("2x", "=", "8", font_size=72)
step4 = MathTex("x", "=", "4", font_size=72)
play(Write(title))
play(Write(step1))
wait()
play(TransformMatchingTex(step1, step2))
wait()
play(TransformMatchingTex(step2, step3))
wait()
play(TransformMatchingTex(step3, step4))
play(Circumscribe(step4, color=YELLOW))
wait()
4. Colour what changes
Colour helps the eye follow a step. Colour the 3 before it moves:
play(step1[2].animate.set_color(ORANGE))
play(TransformMatchingTex(step1, step2))
step1[2] is the third part, the 3. Give step2[4] the same colour when you make it, step2[4].set_color(ORANGE), so the 3 keeps its colour as it moves.
5. Keep each step on screen
To show the working as a list instead of replacing each line, copy the old step down rather than transforming it away:
step2.next_to(step1, DOWN, buff=0.5)
play(TransformFromCopy(step1, step2))
Try this
- Make a video of it: in the footer, Shorts for a phone. See Recording videos.
- Solve
x^2 = 9withMathTex("x^2", "=", "9")→MathTex("x", "=", r"\pm 3").