The effect I'm looking for is equivalent to creating a rectangle around an object and uncreating it (in reverse) before the first animation is over. I faked the result by drawing another rectangle over the first with black stroke, but that creates new problems for my scene. Is there a more sensible way of doing this? Below is my fakery attempt.
class Test(Scene):
def construct(self):
contfrac = MathTex("[2;4,1,2]")
surrect1 = SurroundingRectangle(contfrac[0][1], buff=0.05, stroke_width=2.5)
surrect1a = SurroundingRectangle(contfrac[0][1], buff=0.05, stroke_width=3.5, stroke_color=BLACK)
anim1 = AnimationGroup(Create(surrect1), Create(surrect1a), lag_ratio=.15)
self.play(Write(contfrac))
self.play(anim1)
self.remove(surrect1, surrect1a)
self.wait()
It sounds like you are looking for the Circumscribe
animation.