Search code examples
pythonlatexmanim

How does one add set symbols in manim?


I'm trying to write the set of natural and real numbers in manim using MathTex, but I haven't found a way that works. Every time I try to use shortcuts I've searched up about LaTeX, such as \N, \natnums, \mathbb{N}, and such don't work, returning the error message:

TypeError: 'numpy.ndarray' object is not callable

Does anyone have a solution to this?

Here is the troublesome part in the current version of my code:

NtoR=MathTex(r"\natnums","\longrightarrow",r"\reals") self.play(Write(NtoR,RIGHT*2))

As previously mentioned, I get the following error message:

TypeError: 'numpy.ndarray' object is not callable.


Solution

  • Try adding the amsfonts package to your manim code:

    class WriteNaturalNumber(Scene):
        def construct(self):
            myTemplate = TexTemplate()
            myTemplate.add_to_preamble(r"\usepackage{amsfonts}") # adds package to construct
            # Write the symbol
            tex = Tex(
                r"$\mathbb{N}$",
                tex_template=myTemplate,
                font_size=144,
            )
            self.add(tex)
    

    Result:

    Natural number symbol