Manim - Aligning terms in equation

Solution 1:

Here's what I ended up going with.

eq = 
[
[TexMobject("{2x}"),TexMobject("{-}"),TexMobject("{4}"),TexMobject("{=}"),TexMobject("{-3}")],
[TexMobject("{2x}"),"","",TexMobject("{=}"),TexMobject("{1}")],
[TexMobject("{x}"),"","",TexMobject("{=}"),TexMobject("{1 \\over 2}")]
]

lines = len(eq)
rails = len(eq[1])

for i in range(lines):
   for j in range(rails):
      if(eq[i][j] != ""):
         eq[i][j].move_to([j-0.5*rails+0.5,-i+0.5*lines-0.5,0])

Solution 2:

This isn't the best solution but it works...

from manimlib.imports import *

class BasicEquationsSimple(Scene):
    def construct(self):
        equation0 = TexMobject("2x - 3", "=", "{-7}")
        equation1 = TexMobject("2x", "=", "{-4}").next_to(equation0, DOWN)
        equation2 = TexMobject("x", "=", "{-2}").next_to(equation1, DOWN)

        eq0 = equation0.get_part_by_tex('=')
        eq1 = equation1.get_part_by_tex('=').align_to(eq0, LEFT)
        eq2 = equation2.get_part_by_tex('=').align_to(eq1, LEFT)

        equation0.get_part_by_tex('2x - 3').next_to(eq0, LEFT)
        equation0.get_part_by_tex('{-7}').next_to(eq0, RIGHT)
        equation1.get_part_by_tex('2x').next_to(eq1, LEFT)
        equation1.get_part_by_tex('{-4}').next_to(eq1, RIGHT)
        equation2.get_part_by_tex('x').next_to(eq2, LEFT)
        equation2.get_part_by_tex('{-2}').next_to(eq2, RIGHT)

        equation1.get_part_by_tex('2x').move_to((1.15*LEFT)+(0.6*DOWN))
        equation2.get_part_by_tex('x').move_to((1.05*LEFT)+(1.2*DOWN))

        self.play(Write(equation0,run_time=3))
        self.play(Write(equation1))
        self.play(Write(equation2))

I hope this helps!