How relations work

A relation turns one formula into the next. It links two clips and says, glyph by glyph, where each glyph goes, how it travels and when. Every animation on this page plays in your browser, and four small tools let you try the ideas yourself.

The idea

On the timeline a formula is a clip. A relation links two clips: the source, which is on screen first, and the target, which takes over. While the relation runs, the glyphs of the source move to their places in the target.

A relation is made of three things.

The two clips must be on different tracks, and they must overlap in time: the source has to be on screen (after its intro) while the target is already there (before its outro). The window lies inside that overlap.

A clip can be in several relations. The target of one and the source of the next make a chain, the way a derivation goes from line to line (the quadratic formula tutorial chains six). A clip can also be the source of several relations, to feed several formulas.

Pairs

A pair names some glyphs of the source and some glyphs of the target, and says that the first become the second. The editor numbers the glyphs of every formula (0, 1, 2… in the order the renderer gives them) and keeps the pairs by those numbers. You make pairs in the relation editor, by clicking glyphs. Here you only look at what they mean.

One-to-one

The simplest pair joins one glyph to one glyph. The glyph goes to its place, and its shape and its colour change into those of its partner. The swap above has three of them.

The relation editor's drawing of the swap: a + b on top, b + a below, and three coloured links that cross, each with a badge; the three sources are outlined in red dashes.
The swap in the relation editor. The source is on top, the target below. Each pair is a link with a colour of its own and a badge: its number, and its style (I:T means Transform, inherited from the relation). The red dashes round the sources say that their pairs consume them (below).

One-to-many

A glyph of the source can go to several glyphs of the target in one pair. It splits.

The relation editor's drawing of a(b+c) and ab+ac: the a has two links, one to each a below; the parentheses have none; every linked source is outlined in red dashes.
The same relation in the editor. The a of the source has two links, one to each a of the target; the parentheses have none.

Manim makes it work by padding the shorter side with invisible copies of its glyphs until both sides have the same number. The second a is such a copy: it starts invisible, on top of the first, and shows as it moves away. The exported Python shows the pair as one animation of two groups:

ReplacementTransform(VGroup(before_g[0]), VGroup(after_g[0], after_g[3])),

Many-to-one

Several glyphs of the source can go to one glyph of the target. They merge.

The relation editor's drawing of xx over x squared: the two x of the source, outlined in red dashes, link to the x of the target through one badge; the 2 has no link.
The two x of xx link to the x of x², through one badge. The 2 belongs to no pair.

A glyph of the target arrives through one pair only, so the sources of this pair share it. How they reach it is a choice, and the next section shows it.

Several sources, one target: how they arrive

A pair with several sources and one target has an extra choice in the pair list, Sources. It decides how the sources beyond the first reach the target. The three players below run the same relation, xx into x², with each choice.

Play the three together, on the same pair, and compare how the second x reaches the target:

ChoiceWhat happensIn the exported Python
Separate Each source makes its own transform onto the target. All of them arrive. ReplacementTransform(source_g[0], target_g[0]), Transform(source_g[1], target_g[0], remover=True),
Merge (Manim) Manim aligns the group of sources with the group of targets: the first source becomes the target, and the others fade into it. ReplacementTransform(VGroup(source_2_g[0], source_2_g[1]), VGroup(target_2_g[0])),
Copies The first source, the principal, transforms. Each other source sends a copy and stays. ReplacementTransform(source_3_g[0], target_3_g[0]), Transform(source_3_g[1].copy(), target_3_g[0], remover=True),

The editor shows which source is the principal (Principal: x (0)), and keeps it when the glyphs are renumbered. In a Transform or Fade pair, Separate and Merge (Manim) consume every source; Copies consumes only the principal. With Copies the principal plays the style of the pair, and the other sources send a plain copy, whatever that style.

What a pair cannot do

These rules count over the whole project, not inside one relation: two relations into the same clip cannot bring the same glyph, whichever clips they come from. The relation editor refuses the links it can tell are wrong, dims the glyphs another relation has taken, and lists the other problems before you save. The relation editor shows them.

Try it: link the glyphs yourself

This is a light version of the editor, built on the example of the one-to-many section. Click a glyph of the source and a glyph of the target to link them, then press Play to see what your pairs do.

Styles

The style of a pair says how its glyphs get from the source to the target. The relation has a Default style, and each pair either follows it (Inherit) or has a style of its own.

StyleWhat the glyphs doThe source glyphsIn Manim
Transform Move and change shape into the target glyphs. Consumed: gone afterwards. ReplacementTransform(source_g[0], target_g[0])
Copy (source stays) A copy of each glyph moves and changes shape into the target glyph. Stay where they are, until the outro of the source clip. ManimCE: ReplacementTransform(source_2_g[0].copy(), target_2_g[0])
ManimGL: TransformFromCopy(source_2_g[0], target_2_g[0])
Fade transform The source fades out while it stretches onto the box of the target, and the target fades in from the box of the source. The shapes are not morphed into each other. Consumed. FadeTransform(source_3_g[0], target_3_g[0])
Fade copy (source stays) A copy of each glyph fades out while it stretches onto the box of the target, and the target fades in. Stay where they are, until the outro of the source clip. FadeTransform(source_4_g[0].copy(), target_4_g[0])

Here is the same pair of formulas, a + b above and α + β below, with each style in turn, and then with three of them in a single relation.

The relation editor's drawing of a+b and alpha+beta with three links whose badges read 1 I:T, 2 C and 3 F; the a and the b are outlined in red dashes.
The last relation in the editor. The badges give the number and the style of each pair: I:T is Transform inherited from the relation, C is Copy and F is Fade transform; a Fade copy reads FC. The a and the b, which their pairs consume, are outlined in red dashes; the plus sign, copied, is not.

Use Copy to repeat a glyph or a term somewhere else without losing the original. Use Fade transform when two glyphs have nothing in common: a morph between unrelated shapes looks strange, a fade does not. Use Fade copy when the source must stay and the two glyphs have nothing in common to morph. Try the four on a relation of your own:

Glyphs that belong to no pair

Not every glyph has a partner. The glyphs of the source that no pair consumes leave, and the glyphs of the target that no pair brings arrive. They do it with the animations of their clips:

A glyph that a block of its clip takes care of is the block's: one that a Disappear or a Morph block of the source takes away before the outro, or one that an Appear or a Morph block of the target brings in. The outro and the intro leave it alone, and the relation editor does not count it with them.

In the example below, a + b = c becomes a = c − b. The plus sign belongs to no pair and fades out; the minus sign belongs to none and fades in. The relation editor counts them in the line over the drawing, for example 4 linked pairs · 1 glyph leaves · 1 glyph arrives.

The Animation tab of the relation editor: the timing fields, then the Unpaired glyphs with an Outro list, a checkbox that runs it during the relation window, the Starts empty box and an Intro list.
The settings in the relation editor. (1) The outro of the source clip: what the unpaired glyphs of the source do. (2) Whether it runs during the relation window. (3) Whether the target starts empty. (4) The intro of the target clip.

Choose another animation in the lists (Unwrite, ShrinkToCenter, Write, GrowFromCenter…), or None (disappear) and None (appear) so that the glyphs vanish or show up at once. The outro and the intro belong to the clips: changing them here changes those clips.

The outro of a clip sits at its end. If the source clip goes on after the window, its unpaired glyphs stay until the outro begins. Below, the clip goes on for almost three seconds after the window: the plus sign hangs over the equals sign until it fades.

Two things fix it. Shorten the source clip so that it ends with the window, or tick Run it during the relation window (ends with the source clip): the outro then starts with the window and ends with the clip. Run it up to the end of the relation window (starts with the target clip) does the same for the intro of the target.

Only what the pairs bring: a target that starts empty

Sometimes the glyphs of the target that no pair brings should not arrive at all, or not yet. Below, a = b becomes a² = b², and no pair brings the two exponents. With an intro of None (appear) they show up at once, when the target clip starts, before anything has moved:

Tick Starts empty for the target, and no glyph of that clip comes in with its intro. Each glyph appears only when something brings it: a pair of a relation, a Morph block of the clip, or an Appear block. A glyph nothing brings never shows. This is what a Morph block does inside one formula, between two clips.

The box is in two places, and both set the same thing on the target clip:

With the box ticked, the line over the drawing counts those glyphs as staying out, for example 3 linked pairs · 0 glyphs leave · 2 glyphs stay out. The intro of the clip keeps its animation and its time but has nothing to animate, so its fields in the editor wait. To bring a glyph in later, add an Appear block to the target clip and choose the glyph: Hidden at start, in the block’s glyph picker, picks every glyph of a clip that starts empty.

Timing

The window of a relation is the stretch of time in which its glyphs move. It is counted from the start of the target clip: the Offset is how long after the target starts the window opens, and the Duration is how long it lasts.

The window has to lie inside the overlap of the clips: after the intro of the source, and before the end of the source; after the start of the target, and before its outro. The Animation tab of the editor says it in words, for example Window 3.50 → 5.00 s (allowed 2.00 → 7.00 s).

A new relation is made where the playhead is. When you ask for one, its window starts at the yellow line of the timeline, one second long or as long as the clips leave after it. When no window fits there, because the playhead is outside the overlap or too close to its end, the window starts as soon as both clips allow, and the Animation tab says so under the window: No window fits at the playhead (0.00 s): the two clips allow one within 2.00–7.00 s. It starts at 2.00 s instead.

With a region marked on the timeline’s ruler, the window of a new relation is the region instead, wherever the playhead is. When the two clips do not allow a window all along the region, no relation is made, and the editor says why.

Drag the handles below to move the window. The scene plays with the timing you choose.

On the timeline

A relation is drawn over the two clips: a band on the source clip and a band on the target clip mark the window, and an arrow joins the two clips. The relations of the selected clips are drawn in full; the others are faint. Click an arrow or a band to select the relation. A relation with an error is drawn in red, the edges of its bands and its arrow, and one with only warnings in amber; select it to read them at the end of the Animations panel, under Problems or Warnings.

A timeline with two tracks: a long clip called source above a clip called target, joined by an arrow, with a dashed band on the source and a hatched band on the target.
The selected relation on the timeline. (1) The window on the source clip. (2) The arrow that leaves the source. (3) The window on the target clip.

Drag the band to move the window, and its edges to change its length. A readout above the band gives the start, the end and the length while you drag. With Snap on, the window sticks to the ticks of the ruler, to the playhead, and to the edges of the blocks, the intros, the outros and the relation windows of the two clips; hold Shift to move freely. The window stops where it would leave the overlap, and where it would clash with an animation block or another relation on the same glyphs.

The whole window moves, then its right edge shortens it. Each drag is one undo step, and the clip undoes both.

The window follows the clips. The offset counts from the start of the target, so the window moves with the target clip when you move it. When you move or trim a clip so that the overlap shrinks, the window is shifted and then shortened to stay inside it. A relation with a clip on a locked track is the exception: it is not changed, so its window stays where it plays, and a move or a trim of its other clip stops where the window would no longer fit (The timeline).

The same numbers are in two panels. Select the relation and the Animations panel shows them, with the pairs; the Animation tab of the relation editor has them too. Easing is the rate function of the transformation: how its speed changes between the start and the end of the window. It is smooth unless you change it.

The Animations panel for a relation: a diagram of the two formulas with their links, the list of pairs with their style and path, and the Timing and style section with Offset, Duration, Easing, Default style and Path arc.
The Animations panel for the selected relation: its pairs, then its timing and style.

More than once between the same two clips

A formula does not have to turn into another all at once. Two clips can have several relations: the same source and the same target, each relation with its own pairs, its own window and its own style. Below, a first relation takes the c and the equals sign; a moment later a second one, between the same two clips, takes the rest. The target starts empty, so it is made of what the two relations bring.

The rules of the pairs are what keeps such relations apart. Each glyph of the target arrives through one pair, and each glyph of the source is consumed by one, whichever relation the pair belongs to. So their windows can follow each other, as above, or even overlap, as long as they move different glyphs.

The Default style of a relation decides what its pairs without a style of their own consume, so changing it can break those rules: a pair that copied a source, made a Transform, would consume a glyph another relation consumes already. A default style that would give the project such an error is not set, and the notice Default style not changed says why. Give the pairs that clash a style of their own in Edit pairs…, or keep the default style.

To make the second one, ask for a relation between the two clips again, from the Relations tab or with a link port. Because they are related already, a menu asks what you mean: Edit relation 1…, or Add another relation…. Its window starts at the playhead, or where the last one of theirs ends when no window fits there. The relation editor shows it. The relations of two clips are numbered by when they play, the first on the timeline being 1, and the number tells them apart where the names of the formulas cannot: Relation 2 of 2: source → target in the title of the editor, 2 of 2 in the list of the Relations tab.

Path arc

Glyphs move in straight lines unless the relation says otherwise. Path arc bends the lines into arcs. It is a number of degrees, Manim’s path_arc: 0 is a straight line, and the bigger the number, the rounder the arc, up to a full turn, 360°, either way.

The sign decides the side. A glyph that moves to the right dips below its straight line with a positive arc, and goes over the top with a negative one. Below, the same swap three times: with an arc of 0°, of 90° and of −90°.

The arc belongs to the relation, so every pair follows it. To shape the path of one pair, draw it by hand: custom paths explains how.

Finding, editing and removing relations

The Relations tab of the Animations panel lists the relations of the selected clip, with a diagram of the two formulas and their links. Edit… opens the relation editor, Edit path… goes to the path of a pair, and × deletes the relation. All related… shows every relation connected to the clip, as one chain. The form under the list makes a new relation, or, between two clips that are related already, asks whether to edit one of theirs or add another: the relation editor tells how. A relation is between formulas and texts: a brace, a shape or a line is one piece, and its clip has no Relations tab and no link port.

A project made with an earlier version may still hold a relation with a brace, a shape or a line on one side. It plays and exports as it is, but it cannot be edited: its band is drawn in amber, its warning says what the object is, Edit pairs… and Edit path… are greyed out with the reason in their tooltip, and a drag of its band leaves it where it is. Delete relation, in the menu of its band, removes it.

The Relations tab of the Animations panel for the clip called source: a diagram, one relation with Edit, Edit path and a cross, and the form with Relate with, Direction and Create relation.
The Relations tab of a clip.

Right-click the band of a relation on the timeline for its menu: Edit pairs…; under Edit path, each of its pairs (with more than five, one entry, Choose a pair…, opens a list of them); and Delete relation.

The menu of a relation: its header, Edit pairs, a list of the pairs with their paths, and Delete relation.
The menu of a relation’s band.

You can remove a relation in four ways:

The menu of a clip, with Remove relations marked.
Remove relations (1) in the menu of a clip.

In the exported Python

The exported scene plays a relation with a self.play(…) over its window, one animation for each pair. The glyphs that belong to no pair leave or arrive in that call when their outro or intro runs during the window, as in the scene below; anything that starts or ends inside the window cuts the play into slices (_Part). This is the scene of the one-to-many example, as the editor exports it:

The preview and the export agree: what you see in the player is what Manim renders. The page The generated Python explains the rest of the scene.

The examples of this page

Download a project and open it with File ▸ Open…, then Other file… in the dialog that opens (Projects explains it), to take it apart: select a relation, open its editor, and change a pair.

Where to go next