FlipTack
FlipTack

Reputation: 423

LaTeX Surd Colouring Issues in Manim

I have the following scene:

from manimlib.imports import *

class Surds(Scene):
    def construct(self):
        text_1 = TexMobject("\\sqrt{", "a", "\\times", "b", "} ")

        text_1.set_color_by_tex("a", BLUE)
        text_1.set_color_by_tex("b", YELLOW)

        self.play(Write(text_1))

Which is meant to write the latex expression

\sqrt{a \times b}

With a coloured blue, and b coloured yellow.

Instead, something strange happens. The times symbol is coloured yellow, the 'top' of the surd is coloured blue, and the b doesn't render at all:

enter image description here

I'm certain that the surd is messing things up as the same colouring technique worked as intended in a different scene:

enter image description here

So how can I get colouring to work with the surd?

Side note: I also noticed that adding an additional 'b' on the end of the LaTeX expression makes the penultimate one render, but this isn't really a fix as the \sqrt spacing and colouring are still off:

enter image description here

Upvotes: 2

Views: 280

Answers (1)

FlipTack
FlipTack

Reputation: 423

Although this is more of a workaround than a fix, I have noticed that adding parenthesis does seem to make things render correctly. Coding the scene like this:

class Surds(Scene):
    def construct(self):
        text_1 = TexMobject("\\sqrt{(","a","\\times","b",")}")

        text_1.set_color_by_tex("a", BLUE)
        text_1.set_color_by_tex("b", YELLOW)

        self.play(Write(text_1))

Produces this:

enter image description here

Ideally it would be possible to do this without additional parenthesis, but if not, this might be the best you can do.

Upvotes: 2

Related Questions