Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with \sum #928

Closed
ghostiek opened this issue Mar 19, 2020 · 3 comments
Closed

Problems with \sum #928

ghostiek opened this issue Mar 19, 2020 · 3 comments

Comments

@ghostiek
Copy link

ghostiek commented Mar 19, 2020

  1. Steps to reproduce the issue (e.g. the command you ran)

This is the piece of code

from manimlib.imports import *

class SumProblem(Scene):
    def construct(self):
        xj = TexMobject(
        r"""\left[""",
        r"""\sum_{j=0}^\infty x_j""",
        r"""\right]"""
        )
        self.play(Write(xj[1]))
        self.wait(2)
        self.play(Write(xj[0]),
                  Write(xj[2]))


class NoProblem(Scene):
    def construct(self):
        xj = TexMobject(
        r"""\left[""",
        r"""x_j""",
        r"""\right]"""
        )
        self.play(Write(xj[1]))
        self.wait(2)
        self.play(Write(xj[0]),
                  Write(xj[2]))
  1. The unexpected behavior that occurred (e.g. error messages or screenshots)

When I run this piece of code, I get an unexpected result. It should be writing out \sum_{j=0}^\infty x_j fully then after two seconds adding brackets around it, but it draws half of the left one first and then completes it. In fact, the subscript of x doesn't get written out initially.

I initially had this issue on jupyter_manim so I installed this version to make sure where the problem originated from.

Vu7LuBQUOH

The problem lies with \sum I assume because running this works just fine

hHPcx1rjx1

  1. The environment (e.g. operating system and version of manim)

Windows, latest version of manim

@Elteoremadebeethoven
Copy link
Contributor

Elteoremadebeethoven commented Mar 20, 2020

It is a good question, what happens is that since the brackets are very big, they take up two places of space in the arrangement instead of one, in fact you can realize that if you look at the central part of the brackets, there is a kind of black stripe. This is because, as I said before, the brackets are using two spaces.
The solution is not very elegant, you would have to do something like this:

class SumProblem(Scene):
    def construct(self):
        xj = TexMobject(
        r"\left[",
        r"\sum_{j=0}^\infty x_j",
        r"\right]..",
        )
        self.play(Write(xj[1]))
        self.wait(2)
        self.play(Write(xj[0]),
                  Write(xj[2]),
                  #Write(xj[3])
                  )
        self.wait()

ej1
But in case you want to expand the equation it will give you problems:

class SumProblem(Scene):
    def construct(self):
        xj = TexMobject(
        r"\left[",
        r"\sum_{j=0}^\infty x_j",
        r"\right]..",
        "= x+y"
        )
        self.play(Write(xj[1]))
        self.wait(2)
        self.play(Write(xj[0]),
                  Write(xj[2]),
                  Write(xj[3])
                  )
        self.wait()

ej1
And to solve this we would have to do:

class SumProblem(Scene):
    def construct(self):
        xj = TexMobject(
        r"\left[",
        r"\sum_{j=0}^\infty x_j",
        r"\right]..",
        "= x+y"
        ).scale(3)
        xj[3].shift(LEFT)
        self.play(Write(xj[1]))
        self.wait(2)
        self.play(Write(xj[0]),
                  Write(xj[2]),
                  Write(xj[3][2:])
                  )
        self.wait()

ej1

Conclusion: It is a waste of time, what I recommend to do in case the equation is very large is to do the following:

class SumProblem(Scene):
    def construct(self):
        xj = TexMobject(
            r"\left[\sum_{j=0}^\infty x_j\right]= x+y"
        )[0].scale(3)
        self.get_formula_numbers(xj)
        self.add(xj,xj.t_numbers)
        self.wait()

    def get_formula_numbers(self,
                     formula,
                     f_kwargs={"height":2,"font":"Arial","stroke_width":0,"color":RED},
                     nt_kwargs={"direction":UP,"buff":0.1}
                     ):
        n = 0
        formula.t_numbers = VGroup()
        for f in formula:
            t = Text(f"{n}",**f_kwargs)
            t.next_to(f,**nt_kwargs)
            formula.t_numbers.add(t)
            n += 1

SumProblem
With that information we can use it, and do this:

class SumProblem(Scene):
    def construct(self):
        xj = TexMobject(
            r"\left[\sum_{j=0}^\infty x_j\right]= x+y"
        )[0].scale(3)
        self.play(Write(xj[2:9]))
        self.wait()
        self.play(
            Write(xj[:2]),
            Write(xj[9:]),
        )
        self.wait()

@ghostiek
Copy link
Author

Thanks for the reply. So I tried your example and it worked perfectly but when I try to run my longer Tex Function it fails to give me the right formula numbers

class SumProblem(Scene):
    def construct(self):
        xj = TexMobject(
        r"""\left[\varphi_{Y_1}\left(\frac{t}{\sqrt{n}}\right)\right] = \left[
        \sum_{j=0}^\infty \frac{(i\frac{t}{\sqrt{n}})^j}{j!}\Bbb{E}\left[ {{Y_1}^j} \right]\right]""").to_edge(LEFT)
        self.get_formula_numbers(xj)
        self.add(xj,xj.t_numbers)
        self.wait(3)

    def get_formula_numbers(self,
                     formula,
                     f_kwargs={"height":2,"font":"Arial","stroke_width":0,"color":RED},
                     nt_kwargs={"direction":UP,"buff":0.1}
                     ):
        n = 0
        formula.t_numbers = VGroup()
        for f in formula:
            t = Text(f"{n}",**f_kwargs)
            t.next_to(f,**nt_kwargs)
            formula.t_numbers.add(t)
            n += 1

image

@ghostiek
Copy link
Author

Nvm I forgot to add the [0] after my TexMobject(...)

image

Much appreciated for all the help, and many thanks for the tutorials! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants