Text and math¶
manimgx sets text and formulas itself, with Typst and fonts that come with it. You don't install LaTeX or fonts, and your text looks the same on every computer.
Text¶
m.Text shows text exactly as you write it. A new line (\n) starts a new line:
font_sizesets the size: 48 unless you give another.fontsets the font:"sans-serif","monospace", or the name of a font on your computer. The default is New Computer Modern, the font of LaTeX.t2ccolors parts of the text:m.Text("red and blue", t2c={"red": m.RED, "blue": m.BLUE}).
Text is a mobject like any other: you can move it, scale it, color it and animate it.
Formulas¶
m.MathTex shows a formula, written in LaTeX math. Write it in a raw string, r"...",
so that Python keeps its backslashes:
Fractions, roots, sums and integrals, matrices, cases, Greek letters, \mathbb and
\text work. LaTeX packages and \def don't. If manimgx doesn't know a command, its
error names the command.
m.Tex is for text with math in it: m.Tex(r"The area is $\pi r^2$.").
Parts of a formula¶
Give m.MathTex several strings, and each one becomes a part that you can color or
animate on its own. formula[2] is the third part:
Change a formula into another¶
m.TransformMatchingTex moves each part of a formula to the part with the same LaTeX
in another formula. The parts that don't match fade out and in:
import manimgx as m
class Rearrange(m.Scene):
def construct(self) -> None:
before = m.MathTex("a^2", "+", "b^2", "=", "c^2", font_size=96)
after = m.MathTex("a^2", "=", "c^2", "-", "b^2", font_size=96)
before[2].set_color(m.YELLOW)
after[4].set_color(m.YELLOW)
self.play(m.Write(before))
self.play(m.TransformMatchingTex(before, after))
self.wait()
Numbers¶
m.DecimalNumber(3.14) shows a number. Its set_value shows a different one in its
place, so a number can count up or down as a scene plays: Updaters shows
how.
Typst¶
If you know Typst, write in it directly: m.Typst takes Typst
markup, and m.MathTypst a formula in Typst's math syntax.
Next¶
Graphs shows how to draw axes and plot functions, with labels.