# MathGen
A tool which allows the user to generate a manim animation from an natural language prompt without having to write a single line of code.
[Try Demo →](your-demo-link-here)

## Description
Type "derivative of sin(x)" and MathGen will generate the manim code for you and display the animation, along with the code so that you can change it or try out different prompts.
MathGen is ideal for people who have struggled to grasp mathmatical concepts visually, and who dont want to spend hours learning an animation library just to produce a quick explainer video.
## Process
1. The user types in a prompt
2. This prompt is validated before being passed to an LLM
3. The LLM (we used chatgpt 5.6 and claude fable 5) produces the manim code based on the prompt
4. This code is then run and debugged on replit
5. Finally, the animation is displayed along with the code used to produce it
The stack includes HTML/CSS/JS for the frontend, FastAPI, Flask, Node for the backend, and Manim, Matplotlib, and sympy for the math and animations.
## Example
Prompt: "derivative of sin(x)"
Code:
from manim import *
import numpy as np
class SinTangent(Scene):
def construct(self):
axes = Axes(x_range=[-4, 4, 1], y_range=[-2, 2, 1])
curve = axes.plot(lambda x: np.sin(x), color=BLUE)
self.play(Create(axes), Create(curve))
x_tracker = ValueTracker(-4)
def get_tangent_line():
x = x_tracker.get_value()
slope = np.cos(x)
point = axes.c2p(x, np.sin(x))
return Line(
point + np.array([-1, -slope, 0]),
point + np.array([1, slope, 0]),
color=YELLOW,
)
tangent = always_redraw(get_tangent_line)
self.play(Create(tangent))
self.play(x_tracker.animate.set_value(4), run_time=6, rate_func=linear)
This produces a 30 second long animation of a tangent line tracing around the curve y=sin(x).
## Installation
git clone
cd mathgen
pip install -r requirements.txt
# add any missing setup commands for the frontent/backend here, and test them
python app.py
## What was challenging
Getting the LLM to produce working manim code in the first place was challenging, as there was a lot of trial and error involved in prompting it.
The sympy dependency also proved to be somewhat challenging to setup, as one syntax error took several days to fix.
Finally, making sure that the animation looked good while also being mathematically correct was also a balancing act.
## Future work
The ability to change what rendering engine is used, and what mathematical fields are supported, with the ultimate goal of making a general purpose visual reasoning assistant for math.
- 1 devlog
- 1h