Mathematical Notation and LaTeX
Source:vignettes/mathematical-notation.Rmd
mathematical-notation.RmdIntroduction
Mathematical notation is at the heart of manimR. This vignette covers how to work with LaTeX expressions, animate equations, and create beautiful math visualizations.
Basic LaTeX
Add LaTeX expressions with add_latex():
Note that you don’t need the $ delimiters—manimR handles
that automatically.
Equation Transformations
One of manimR’s most powerful features is animating between equations:
scene("equation_transform") %>%
add_latex("(x + y)^2") %>%
write_in() %>%
pause(1) %>%
transform_to("x^2 + 2xy + y^2", duration = 2) %>%
pause(1) %>%
render()Positioning Equations
Place multiple equations on screen:
scene("positioning") %>%
# Title
add_text("Quadratic Formula", position = c(0, 3, 0), size = 48) %>%
write_in() %>%
# Standard form
add_latex("ax^2 + bx + c = 0", position = c(0, 1, 0)) %>%
write_in() %>%
pause(1) %>%
# Solution
add_latex("x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}",
position = c(0, -1, 0), size = 1.2) %>%
write_in(duration = 2) %>%
pause(1) %>%
# Highlight discriminant
highlight_term("b^2 - 4ac", color = "yellow") %>%
render()Best Practices
1. Escape Backslashes
In R strings, backslashes must be escaped:
# Correct
add_latex("\\frac{1}{2}")
# Wrong - will cause errors
# add_latex("\frac{1}{2}")LaTeX Requirements
For full LaTeX support, you need LaTeX installed on your system:
# Install TinyTeX (recommended)
install.packages("tinytex")
tinytex::install_tinytex()
# Or install full TeX Live/MiKTeX from:
# https://www.latex-project.org/get/Without LaTeX, manimR will render mathematical notation using basic text rendering, which may not look as polished.
Next Steps
-
vignette("transformations"): More about morphing and transformations -
vignette("tidyverse-integration"): Data-driven math animations