Writing formulas

A formula is LaTeX typed into the formula editor. This page follows one from its first keystroke to its card in the Creator: how to type it, what the editor says when it fails, its packages, size, colour and name, and why the order in which the app numbers its glyphs matters once you start to animate.

Create a formula

The Creator, on the left, keeps every formula of the project. Press + New to write one. The formula editor opens with the cursor in its LaTeX field, and the formula has a name of its own already (f1, then f2…) that you can change whenever you like.

The Creator of a project with no formulas: its three tabs, the toolbar with the + New button, a card of glass with a sigma over the words No formulas yet and Press + New to write one, then drag it onto the timeline, and under them Or open a project: with the buttons Try an example and Sync folder….
A project with no formulas says what to press first, and offers an example to open (The examples).

The arrow beside the button lists every kind of object the Creator makes: Formula, Text (LaTeX) and Text (font). A formula is maths; the two texts have an editor of their own, described in LaTeX texts and font texts.

The + New button of the Creator and, under its arrow, a menu with Formula, Text (LaTeX) and Text (font).
+ New writes a formula. Its arrow lists the other kinds.

A formula in the Creator is not on the screen of your scene yet. It is an object that clips show: drag it onto the timeline, or choose Add to the timeline in its menu (see Working with the timeline).

The formula editor

Double-click a formula in the Creator, or press Enter on it, to open the editor again. Go through its parts one by one:

The fields of the header act on the formula at once, each change as one undo step. The LaTeX and the packages wait for Apply, so you can type for as long as you like and still see the formula as it was. Outside a text field, Ctrl+Z undoes the header's changes and the applied LaTeX while the editor is open. Drag the bar between the two columns to give the glyphs more or less room, or the corner of the dialog to resize it.

Typing LaTeX

Typing in Raw LaTeX: the visual field above it typesets the formula as you go, the line beside Apply counts its glyphs, and Apply draws them in the column on the right.

There are two fields for the same formula, and they stay in step:

A formula with several rows uses & to line the rows up and \\ to end a row, as Manim's align* reads them. The visual field shows such a formula inside an aligned block, and the raw field keeps what you typed.

When you are ready, press Apply or Ctrl+Enter. The LaTeX and the packages go into the project as one undo step, and the glyph column draws the formula. Until then the footer says Unapplied changes, Revert brings the applied formula back, and closing the dialog asks before it throws your changes away.

The on-screen keyboard

If you would rather press a fraction than type \frac, press ⌨ Keyboard, beside the LaTeX title (1). A keypad opens in the editor, under the visual field. Its four tabs (2) are Algebra, Trigonometry, Calculus and Alphabet, which has the digits, the letters and two rows of Greek ones. A key writes a digit, an operator, a function, or a structure with its holes: a fraction, a root, a power, an absolute value, a limit, an integral, a sum. A hole you have not filled yet is an empty group in the raw LaTeX (\frac{}{}), and the formula still renders. The last row (3) moves the caret, deletes backward, clears the field (AC) and applies (Apply, the same as the editor's button).

The LaTeX section of the formula editor with the keypad open. The Keyboard key beside the LaTeX title is ringed (1). The visual field holds the fraction 1 over 2. Under it, the tabs Algebra, Trigonometry, Calculus and Alphabet are ringed (2), over the keys of Algebra: a fraction and other structures drawn with empty squares for their holes, comparisons, the digits and the four operations. The last row, ringed (3), has left and right arrows, delete, AC and Apply. The Raw LaTeX field reads \frac12.
⌨ Keyboard (1) shows the keypad: its tabs (2) and its last row (3). The fraction key, 1, → and 2 wrote the formula in the visual field, and the raw LaTeX followed.

A press leaves the cursor in the visual field, so what you type next goes on in the formula. A keypad left shown is there again the next time the editor opens, until its key hides it.

The status line and the errors

About a fifth of a second after you stop typing, the editor renders your draft, before you apply it, and reports the result beside Apply:

The line saysIt means
Rendering…The draft is being typeset.
16 glyphs · MathJaxIt rendered: the number of glyphs, and which renderer drew them. See Why the order of glyphs matters.
16 glyphs · exact (LaTeX)The same, typeset by real LaTeX through the companion.
Cannot renderThe LaTeX has a problem. A panel under the line says what.

The panel names the problem in plain words, and, when it can tell, what to do about it. A brace left open:

The line beside Apply says Cannot render, and a red panel under it reads: Missing close brace
A brace that is never closed.

A command from a package you have not added names the package:

The Packages row with its Common: buttons, and under it the line Cannot render with a panel that reads: Undefined control sequence \cancel. It comes from the "cancel" package: add it under Packages. The cancel button is ringed.
The panel names the package that has the command, and the Common: row (1) offers it.
The same area after the click: a cancel chip in the Packages row, and the line beside Apply says how many glyphs the formula has and that MathJax drew them, with no panel under it.
One click on cancel adds the chip (1), and the formula renders.

With the companion running, the panel adds LaTeX's own log under the message. Warnings, such as a package MathJax cannot load, are listed under the line in the same place.

Formulas to try

Six formulas, from a plain equation to two aligned rows. Type each one into the Raw LaTeX field of a new formula, and look at what the status line says. The project with all six is at the end of this section if you would rather open it.

Plain

x + 3 = 5

Fractions

\frac{numerator}{denominator}: each braced group is one piece. Spaces in the source are for you; LaTeX sets the spacing of a formula itself.

\frac{a}{b} + \frac{c}{d} = \frac{ad + bc}{bd}

Roots, powers and symbols

\sqrt{…} draws a root, ^ raises, and \pm is one of many named symbols (\pi, \alpha, \infty…).

x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}

Sums and limits

_ lowers and ^ raises. Braces make a longer index one piece: _{k=1}.

\sum_{k=1}^{n} k = \frac{n(n+1)}{2}

Integrals

An integral, with a thin space before the dx.

\, is a thin space. It reads better before the dx.

\int_0^1 x^2 \, dx = \frac{1}{3}

Rows

One & before the sign each row is lined up on, and \\ between rows.

(a + b)^2 &= a^2 + 2ab + b^2 \\
(a - b)^2 &= a^2 - 2ab + b^2

LaTeX packages

Some commands are not plain LaTeX: \cancel belongs to the cancel package, \dv to physics, \bm to bm. A formula lists the packages it needs under Packages, one chip each.

The package picker: chips for physics and tikz-cd, a search box with the letters "mat" typed and a list of matching packages, the Common row of quick buttons, and a note that MathJax cannot load tikz-cd.
Chips with a ×, the search, its results, the Common: row and, under them, notes about what the preview cannot do.

Manim's own template already loads amsmath and amssymb, so you never add those. Packages count when you press Apply, like the LaTeX.

What every formula of the project needs, such as a \newcommand, goes in the project's LaTeX preamble instead: File ▸ Project settings…, field LaTeX preamble. It is added after the packages of each formula.

cancel: crossed-out terms.
\frac{\cancel{x}\,y}{\cancel{x}\,z} = \frac{y}{z}
physics: \dv{f}{x} is the derivative d f / d x.
\dv{f}{x} = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}
bm: bold symbols.
\bm{F} = m\,\bm{a}

When you export Python, each formula's packages become a TexTemplate (ManimCE) or an additional_preamble string (ManimGL) in the scene, and the formula is built with it. These are the lines the editor exports for the first formula above, in ManimCE:

template = TexTemplate()
template.add_to_preamble(r"\usepackage{cancel}")
…
cancelled = MathTex(r"…", font_size=72, tex_template=template)

and in ManimGL:

preamble = r"\usepackage{cancel}"
…
cancelled = Tex(r"…", font_size=74.2416, additional_preamble=preamble)

The whole file, for the three formulas, is under the tabs. The generated Python explains the rest of it.

Size

The header of the editor with five numbered fields: 1 Name, 2 Tag, 3 Size with Scale 1.5 and font size 72, 4 Colour, 5 Appears with.
The header of the editor: Name (1), Tag (2), Size (3), Colour (4) and Appears with (5).

Size (3) is one value written twice. Scale is a factor of Manim's default font size, 48, and the second field is the font size it makes: 1.5 × 48 = 72. Change either and the other follows. The scale takes a number or a fraction (3/2) from 0.1 to 10, and the font size a number from 4 to 512.

Changing the size resizes every clip of the formula where it stands. A clip also has a scale of its own, which the handles of the Preview change; the two multiply.

New formulas start at the standard scale, 1 unless you say otherwise, set in Preferences ▸ Standard scale…. That dialog can also give the same scale to every formula of the project (see Standard scale).

Colour

Colour (4) colours the whole formula, every glyph at once. Click the swatch to pick a colour in your system's picker, or type a hex value, #RRGGBB, and press Enter. The glyph column and the Preview use it straight away.

To colour only some glyphs, select them in the glyph column and choose a colour for them. A glyph with a colour of its own keeps it when you change the colour of the formula. The same formula, three ways:

Colouring glyphs and objects covers colours of single glyphs, and Palettes and Chroma Lab the named colours a project can share.

Names and tags

The Name (1) identifies the formula in the Creator, the timeline and your exported code, where it becomes a Python variable. For that reason a name has rules, and the field tells you which one it breaks as you type:

The Name field of the editor with the text my formula and, under it, in red: Use letters, digits and "_", not starting with a digit: the name becomes a Python variable.
A space is not allowed in a name. The reason shows under the field as you type; the name is kept when it is valid and you press Enter or leave the field.

The Tag (2) is a small mark for finding the formula in the lists: one of eight colours or a hex value of your own, and optionally an icon of up to eight characters (a letter, an emoji). A tag never colours the glyphs of the formula. It identifies it: the dot in the Creator, and the clips of the formula on the timeline.

Appears with (5) chooses the intro that every new clip of the formula starts with. It is explained in Appearing and disappearing.

The Creator list

Every formula of the project is a card in the Creator. In the list view a card has a row of information and a drawing of the formula on the project's background. You can drag the bar between the Creator and the Preview to give the cards room.

The Creator widened, showing the cards of plain, fractions, quadratic and series, each with a tag dot, its name, a sigma mark, a MathJax badge, a clip count and three buttons, above a drawing of the formula.
The list view, with the Creator widened by dragging the bar beside it.

Each card says:

One card of the list with six numbered parts: 1 the tag dot, 2 the name, 3 the kind mark, 4 the status badge, 5 the clip count and 6 the three buttons.
The parts of a card.
  1. Its tag: the dot, with its icon if it has one.
  2. Its name. Double-click it, or press F2 on the card, to rename it.
  3. Its kind: ∑ for a formula, T for a LaTeX text, P for a font text.
  4. Its status: MathJax or exact once it has rendered (see below), rendering… while it is being typeset, error when its LaTeX does not compile, and empty before you write anything. Point at the badge for the tooltip.
  5. How many clips use it on the timeline.
  6. Three buttons: edit (the pencil), duplicate and delete.

A click selects a card; Ctrl+click and Shift+click select several (see Finding and organizing, which also lists the keys). A double-click or Enter opens the editor. The arrow keys walk the list, and a card can be dragged onto the timeline.

List and blocks

The key beside the magnifier switches how the Creator draws its cards, between the list view and the block view: it shows the icon of the view a press brings. In the block view each formula is a small square with its tag, name, clip count, kind and status. Point at a block and a tooltip beside it shows the formula's drawing. Its edit, duplicate and delete buttons appear while the pointer or the focus is on it. The choice is a preference of the editor, and it is remembered.

The Creator in the block view: six squares in two columns, each with the dot of its tag, its name, its clip count, its kind and the badge MathJax, and a tooltip beside the fractions block with its drawing, its name, its kind and the words Double-click to edit, F2 to rename.
The block view, with the tooltip of the block the pointer is on.

A block narrower than 112 px has no room for all of that beside its name. It shows a compact face instead: the whole block is a pane of glass tinted with the colour of its tag, with the name alone on it. The rest comes at once while the pointer is on the block, in its corners: the edit, duplicate and delete buttons at the top, the kind and a letter for the status at the bottom left, the clip count at the bottom right. The blocks are that narrow whenever the Creator is wide enough for four columns or more, and often when it is narrower.

LetterThe formula is
Mdrawn by MathJax
edrawn with the exact glyphs, from the companion
?a font text that needs the companion
…not drawn yet
!in error. This one shows without the pointer, and so does the warning mark ⚠
A wide Creator in the block view: six columns of small squares, each a pane of glass tinted with the colour of its tag, with the name of its formula; the pointer is on one, which shows three buttons at the top, the kind and the letter M at the bottom left and its clip count at the bottom right.
Compact blocks: (1) the name on glass tinted with the tag’s colour; (2) the buttons, (3) the kind and the status letter and (4) the clip count of the block the pointer is on.

Larger previews

The +/− key of the toolbar, after the ∑ key, makes the previews of the view you see larger with a click and smaller with a right-click (or Shift+click): 1×, 1.5×, 2× or 3×. With the focus on it, ↑ and ↓ do the same. In the list view it sizes the drawing of every card, 52 pixels tall at 1× and 156 at 3×. In the block view it sizes the tooltip beside a block, its drawing as many times wider and taller. The formula is always drawn as large as its box allows.

The Creator in the list view with the previews at 2×: each card's drawing twice as tall as at first, and the plus-minus key of the toolbar ringed.
The list at 2×, with +/− ringed.

Each view keeps its own size: the cards of the list can stay small while the tooltips of the blocks are large. Both are preferences of the editor, and they are remembered. The tooltip of the key says the size now, and which end is reached: at 1× a right-click does nothing, at 3× a click.

Rename, duplicate and delete

To rename a formula from the list, double-click its name (or press F2 on the card): the name becomes a field, and Enter keeps the new one. The rules of a name are the editor's own.

Duplicate makes a copy right after the original, with everything the original has (its LaTeX, size, colours, hidden glyphs, packages, tag and intro) under the next free name: plain becomes plain2, and f007 becomes f008. The copy is a new formula with no clips.

The duplicate button of a card puts a copy after it.

Deleting a formula removes its clips, and the relations those clips have, with it, so the editor asks first and lists what will go. The button has to be held down: it fills while you hold it. Del on the selected formula, or Edit ▸ Delete formula, does the same. One undo step brings everything back.

The question Delete "plain"? says the formula is used on the timeline and lists the clip that would go with it, with a Cancel button and a red button, Hold to delete formula.
What deleting a formula asks, and lists.

Why the order of glyphs matters

The editor does not animate a formula as a picture. It animates its glyphs, the individual characters and rules it is made of, and everything that points at a glyph does so by its number: its colour, whether it is hidden at the start, and above all the pairs that make one formula turn into another. Hover over the glyph column in the editor, or press its list button, and each glyph shows its number.

Which number a glyph gets depends on who typeset the formula, and that is where the editor's two renderers differ.

The two orders often agree and often do not. A fraction shows it. MathJax numbers its numerator, its denominator and then its bar; LaTeX numbers the numerator, the bar and then the denominator.

The glyph column of the formula a over b: the drawing, and under it three keys numbered 0 a, 1 b and 2 with a bar, which is the order MathJax gives.
MathJax numbers the glyphs of a fraction: a (0), b (1), then the bar (2).
FormulaMathJax orderLaTeX order (as Manim builds it)
\frac{a}{b}a, b, bara, bar, b
\sum_{i=0}^{n} i^2∑, i, =, 0, n, i, 2n, ∑, i, =, 0, i, 2

You can work in the browser alone. A project that relates the glyphs of two formulas, or colours single glyphs, stores them by the numbers the editor sees. When it exports Python and those numbers are MathJax's, the exported scene finds each glyph by where it sits in the formula, which is reliable whenever the two typesettings make the same glyphs. Where they do not (tall brackets, stretchy arrows, ligatures), the scene prints a warning when you run it, and the glyphs without a counterpart are not animated.

With the companion running, the badge in the glyph column says exact, the status line says exact (LaTeX), and the exported Python uses Manim's numbers straight, with no matching. The menu bar says Renderer: MathJax, Renderer: LaTeX or Renderer: mixed, as the formulas of the project stand. A formula you made without the companion keeps working when it comes up: the editor re-numbers its glyphs and carries your colours and pairs over to the new numbers.

The View menu lets you ask for one renderer: Glyph source: Automatic (LaTeX when the companion is online), Glyph source: MathJax or Glyph source: LaTeX (companion).

Where to go next