Continued fractions in manim

50 views Asked by At

I'm new to using manim and I try to implement a simple animation for a continued fraction expansion of a fraction. My code so far is as follows:

from manim import *

class Eq(Scene):
    def construct(self):
        f1=MathTex(
            r"{75 \over ",
            r"33",
            "}"
            )
        f2=MathTex(
            r"{66+9 \over ",
            "33",
            "}"
            )
        f3=MathTex(
            r"{2+}",r"{9 \over ",
            "33",
            "}"
            )
        f4=MathTex(
            r"{2+}",r"{1 \over ",
            r"{33 \over",
            "9",
            "}","}"
            )
        self.add(f1)
        self.wait(2)
        self.play(ReplacementTransform(f1[0],f2[0]))
        self.wait(2)
        self.play(ReplacementTransform(f1,f3))
        self.wait(2)
        self.play(ReplacementTransform(f3,f4))
        self.wait(2)
        

Probably not as efficient as it could be, but that's not my problem. When I move my fraction in the denominator the \over produces a textsytle fraction that is smaller than the original fraction making it look awkward. Is there a possibility to avoid this?

I found videos where the continued fraction expansion stays the same size, so it has to be possible. Unfortunately, I was not able to find a guide for this particular problem. Help would be appreciated.

Edit: Here is a picture of the situation enter image description here

As you can see the fraction in the denominator is smaller. I want it to be the same size as the original fraction.

1

There are 1 answers

2
CodingWithMagga On

In general, this is more of a "LaTeX" question than a "manim/python" question. Manim just renders the LaTeX equation to a *.svg file and adds this file to the scene. So the real question is, how to render a LaTeX equation in the way you want it. Here you can find possible solutions.

Applying the first one to your example can lead to this:

...
f4=MathTex(
    r"{2+}",r"\begin{array}{@{\,}c@{\,}} 1\\ \hline 33\\ \hline 9\end{array}"
)
...

Which looks like this:

Example result