Manim basics: text, maths & shapes

A slow, patient walkthrough of the objects that appear in almost every Manim project: scenes, text, LaTeX mathematics, simple shapes, and positions on the screen.

This page is a detailed commentary on the early modules in the main Manim Lab. You can read this when you want the “why” behind each line of code, then jump back to the main lab to experiment in the editor.

Modules on this page

Module A • First scene, line by line

Every Manim project starts with the same pattern: import Manim, define a Scene subclass, and implement the construct method where the animation happens.

🧩 The smallest useful scene Pattern to memorise

from manim import *

class HelloNAMSSN(Scene):
    def construct(self):
        text = Tex(r"Hello, NAMSSN UI!")
        self.play(Write(text))
        self.wait(1)
  • from manim import * – brings in all the standard Manim classes.
  • HelloNAMSSN(Scene) – defines a new scene type. The name will be used in the command line.
  • construct(self) – Manim calls this method to build and play the animation.
  • Tex(...) – creates a LaTeX object (mathematical text).
  • self.play(Write(text)) – tells Manim to animate writing the text.
  • self.wait(1) – holds the final frame for one second.
How to run it: save this as hello_namssn.py, open a terminal in the same folder, and run manim hello_namssn.py HelloNAMSSN -pql. The setup guide explains this command carefully.
Exercise A.1 – Change the greeting
  • • Replace the text with a sentence that mentions your name or a course (e.g. “MTS 201 revision”).
  • • Change the final self.wait(1) to self.wait(3) and observe the difference.

Module B • Plain text, LaTeX, and alignment

Manim offers two main text classes for everyday use: Text for normal writing and MathTex / Tex for LaTeX.

✏️ Text vs. mathematical text

from manim import *

class TextAndMath(Scene):
    def construct(self):
        title = Text("Geometric series")
        formula = MathTex(r"1 + x + x^2 + \cdots = \frac{1}{1 - x}")

        title.to_edge(UP)
        formula.next_to(title, DOWN, buff=0.5)

        self.play(Write(title))
        self.play(Write(formula))
        self.wait(2)
  • Text uses your system fonts and is good for headings or narration.
  • MathTex typesets LaTeX mathematics cleanly.
  • to_edge(UP) moves the object to the top edge of the frame.
  • next_to(..., DOWN) positions one object relative to another.
If LaTeX gives errors, check that a LaTeX distribution is installed on your system and that Manim can find it. The troubleshooting section of the setup page lists the most common fixes.

🪄 Emphasising part of a formula

class HighlightTerm(Scene):
    def construct(self):
        expr = MathTex(r"x^2 + 2x + 1 = (x + 1)^2")
        expr.to_edge(UP)

        self.play(Write(expr))
        self.wait(0.5)

        brace = Brace(expr[0:3], DOWN)  # x^2 + 2x + 1
        label = brace.get_text("quadratic in x")

        self.play(Create(brace), FadeIn(label))
        self.wait(2)
  • LaTeX formulas are broken into small parts (submobjects) you can reference by index.
  • Brace and get_text help you annotate a piece of a formula.
  • This pattern is powerful for ODE, series, and algebra explanations.
Exercise B.1 – Create a mini “fact card”
  • • Use Text for a heading (e.g. “Cauchy–Schwarz inequality”).
  • • Use MathTex for the formula itself.
  • • Place the heading at the top and the formula in the centre.

Module C • Shapes, number lines, and grouping

Beyond text, Manim represents visual objects as “mobjects”: circles, rectangles, number lines, arrows, graphs, and more.

🔷 Basic shapes and colours

from manim import *

class ShapesAndColours(Scene):
    def construct(self):
        circle = Circle(radius=1, color=BLUE)
        square = Square(side_length=1.4, color=GREEN).shift(RIGHT * 2)
        triangle = Triangle().set_color(RED).shift(LEFT * 2)

        self.play(Create(circle), Create(square), Create(triangle))
        self.wait(1)

        self.play(circle.animate.set_fill(BLUE, opacity=0.3))
        self.play(square.animate.set_fill(GREEN, opacity=0.3))
        self.play(triangle.animate.set_fill(RED, opacity=0.3))
        self.wait(2)
  • Circle, Square, and Triangle are ready-made shapes.
  • shift(RIGHT * 2) moves a shape two units to the right.
  • .animate.set_fill(...) is a common pattern: animate a change of style.

📏 Number lines and dots

class NumberLineDemo(Scene):
    def construct(self):
        line = NumberLine(x_range=[-3, 3, 1])
        dot = Dot(color=YELLOW).move_to(line.n2p(0))

        self.play(Create(line))
        self.play(FadeIn(dot))
        self.wait(0.5)

        self.play(dot.animate.move_to(line.n2p(2)))
        self.wait(1)
  • NumberLine builds a 1D axis with tick marks.
  • n2p converts a numeric coordinate (e.g. 2) into a screen position.
  • Moving a dot along a number line is the basis for many “parameter” animations.
Exercise C.1 – Build a small “shape lineup”
  • • Place three shapes in a horizontal row.
  • • Give each a different colour.
  • • Animate them appearing one after another.

Module D • Styles, configuration, and reusable patterns

As you create more scenes, you do not want to repeat the same styling code everywhere. Manim lets you define helper methods and use configuration variables to keep things consistent.

🎨 Defining your own colour palette

from manim import *

NAMSSN_BLUE = "#0ea5e9"
NAMSSN_GREEN = "#22c55e"

class PaletteDemo(Scene):
    def construct(self):
        title = Text("NAMSSN palette", color=NAMSSN_BLUE)
        bar = Rectangle(width=4, height=0.3, color=NAMSSN_GREEN)
        bar.next_to(title, DOWN, buff=0.4)

        self.play(Write(title))
        self.play(GrowFromCenter(bar))
        self.wait(2)
  • Define colours once at the top of the file and reuse them across scenes.
  • This helps the visual identity of your videos match NAMSSN posters and slides.

♻️ Reusing a small helper function

def heading(text):
    return Text(text).to_edge(UP)

class WithHelper(Scene):
    def construct(self):
        title = heading("Small helper example")
        body = Text("You can reuse this heading in many scenes.")

        body.next_to(title, DOWN, buff=0.5)

        self.play(Write(title))
        self.play(Write(body))
        self.wait(2)
  • Helpers keep your code shorter and easier for collaborators to read.
  • Later, you can move common helpers into a separate file and import them.
Exercise D.1 – Design your personal title style
  • • Create a function title(text) that returns a Text object with your favourite colour.
  • • Use it in at least two different scenes.

When you feel comfortable with the patterns on this page, return to the main Manim Lab and try loading some of these examples into the editor. From there you can start combining text, shapes, and number lines into short, coherent clips.