Getting Started

Installation

If you haven't already, install the Dart SDK (tutorial).
You will also need to have LATXE\LaTeX installed.

Then, you can install the ManimWeb CLI with:

pub global activate manim_web

That's it, the Manim Web CLI is installed.

⚠️

If a directory should be added to the PATH. You will need to do it.

Creating the project

The CLI is available with the manimweb and the manim_web command. BR Both commands do the same things, choose the one you prefer.

Create a project with the default template with:

manimweb init --directory {directory}

Replace {directory} with the name of the directory to create. BR Make sure the directory is empty or doesn't exist.

Then go to the directory ( cd {directory} ).

First scene with Manim Web

You can open the src/example.dart in your favorite text editor. BR Visual Studio Code with the Dart extension works really well.

Copy and paste the code bellow.

import 'package:manim_web/manim.dart';
class ExampleScene extends Scene {
FutureOr<void> preload() {
Tex.preload('Hello World!');
}
FutureOr<void> construct() async {
var tex = Tex('Hello World!');
tex.scaleUniformly(4);
await play(FadeIn(tex));
}
}

You can then start the dev server with:

manimweb dev --file src/example.dart --html src/example.html

The server should be running on localhost:8080

How it works

import 'package:manim_web/manim.dart';
...

On line 1, you import the whole Manim Web library. It allows you to use Scene, Tex, FadeIn.

import 'package:manim_web/manim.dart';
class ExampleScene extends Scene {
FutureOr<void> preload() {
Tex.preload('Hello World!');
}
FutureOr<void> construct() async {
var tex = Tex('Hello World!');
tex.scaleUniformly(4);
await play(FadeIn(tex));
}
}

On line 3, you create a scene: ExampleScene.

Then, you define two methods: preload and construct on line 5 and 10.BR Both methods return a FutureOr<void> which is either a Future (asynchronous result) or of type void. The construct method is also async, it allows you to use the await keyword later.

The construct method

First, look at the construct method's body:

var tex = Tex('Hello World!');
tex.scaleUniformly(4);
await play(FadeIn(tex));

You first create some text "Hello World!".

💡

It's called Tex because it's the text generated with LATXE\LaTeX.
There is also MathTex which is the math formula generated with LATXE\LaTeX.

var tex = Tex('Hello World!');
tex.scaleUniformly(4);
await play(FadeIn(tex));

Then, the tex is scaled by 4 uniformly.

💡

You can also scale differently along the x and y axis with the scale method.

var tex = Tex('Hello World!');
tex.scaleUniformly(4);
await play(FadeIn(tex));

Finally, the animation part:

You start by creating a new Animation. It's a FadeIn animation.

💡
There are a lot more: FadeOut, ShowCreation...

Then, you play the animation with the play method.BR The play method is part of the Scene, so you could also write:

await this.play(FadeIn(tex));

With the this keyword referring to the scene.

Also, you use await to wait for the scene to play the animation.

Now, you should know how the construct method works.

The preload method

When running your animation, your browser can't use LATXE\LaTeX to generate the needed Math formulas and texts. You need to preload the results.

The preload method is used for that, it doesn't run in your browser but manimweb runs it. It tells which text and formulas need to be preloaded.

In this method, there is only one line:

Tex.preload('Hello World!');

You tell ManimWeb you will use Tex with the "Hello World!" text. Then, BR ManimWeb will run LATXE\LaTeX to generate the "Hello World!" text.

Mobjects

In ManimWeb, every element displayed is a Mobject.

Tex is a Mobject, but it's not the only one. There are many more mobjects: MathTex, Circle, Square, Axes, Arrow, Dot, Group, NumberPlane, SVGMobject...

But, Mobject can't be rendered, they're only used as a container. VMobject is an extension of Mobject which can be rendered. It's what most mobjects use.

Animations

When using the play method, you used the FadeIn animation. BR Every animation extends from Animation.

You can play many animations at once with the playMany method. Instead of giving a single animation, you use a list of animations. Then, all the animations will be played simultaneously.

If you want to delay the animations, you can use an AnimationGroup with the lagRatio argument. Like this:

var square1 = Square();
var square2 = Square();
square1.shift(RIGHT);
square2.shift(RIGHT);
await play(
AnimationGroup(
[
FadeIn(square1),
FadeIn(square2),
],
lagRatio: 0.02,
),
);