Getting Started with MathViz

MathViz is a domain-specific language designed for creating mathematical animations. It compiles to Python and integrates seamlessly with Manim, the mathematical animation engine.

Prerequisites

MathViz requires Python 3.10 or later. For animations, you'll also need Manim installed.

Installation

Using pipx (Recommended)

The recommended way to install MathViz is using pipx, which installs the CLI in an isolated environment:

Shell
pipx install mathviz

Using pip

You can also install MathViz directly from PyPI:

Shell
pip install mathviz

Using uv (Development)

For development or contributing to MathViz, clone the repository and use uv:

Shell
git clone https://github.com/CyberSnakeH/MathViz.git
cd MathViz
uv sync --dev

Verify Installation

After installation, verify MathViz is working:

Shell
mathviz --version
mathviz info

VS Code Extension

MathViz includes a VS Code extension with syntax highlighting, 18 code snippets, and smart bracket matching. Build and install the extension:

Shell
cd vscode-mathviz
npx @vscode/vsce package
code --install-extension mathviz-0.1.0.vsix

Open any .mviz or .mvz file in VS Code and the extension activates automatically.

Auto-Update

MathViz automatically checks for updates via PyPI once per day. When a new version is available, you'll see a notification in the terminal:

Shell
Update available: 0.1.7 → 0.2.0
Run: pipx upgrade mathviz

Your First Program

Create a new file called hello.mviz:

MathViz
// hello.mviz - Your first MathViz program

fn main() {
    let message = "Hello, MathViz!"
    println(message)

    // Basic math
    let x = 2 ^ 10
    println("2^10 = {}", x)

    // A simple function
    let result = add(5, 3)
    println("5 + 3 = {}", result)
}

fn add(a: Int, b: Int) -> Int {
    return a + b
}

Running Your Code

Execute Directly

Run your MathViz code directly without generating a Python file:

Shell
mathviz exec hello.mviz

Compile to Python

Compile your MathViz code to a Python file:

Shell
mathviz compile hello.mviz -o hello.py

Run with Manim

If your file contains a scene block, run it with Manim:

Shell
mathviz run animation.mviz -q m --preview

Creating Your First Animation

Create a file called circle.mviz:

MathViz
// circle.mviz - A simple animation

scene CircleDemo {
    fn construct(self) {
        // Create a circle
        let circle = Circle(radius: 2.0)
        circle.set_color(BLUE)

        // Create a label
        let label = Text("MathViz")
        label.next_to(circle, DOWN)

        // Animate!
        play(Create(circle))
        play(FadeIn(label))
        wait(2.0)
        play(FadeOut(circle, label))
    }
}

Run the animation:

Shell
mathviz run circle.mviz --preview

Next Steps