-
Notifications
You must be signed in to change notification settings - Fork 1
Math Rendering
Math (MathTex/Tex) can be rendered in one of two modes, chosen by a module
flag in real_time_manim/vulkan_bind.py:
# real-time-manim / real_time_manim / vulkan_bind.py
_USE_NATIVE_MATHTEX = False # default: use real LaTeX| Mode | _USE_NATIVE_MATHTEX |
Fidelity | Requirements | Speed |
|---|---|---|---|---|
| LaTeX mode |
False (default) |
Full: fractions, matrices, integrals, accents, \mathbb, … |
MiKTeX or TeX Live installed | Slower (compile on first use, then cached) |
| Native Unicode mode | True |
Limited: flat Unicode text, manual super/sub-scripts | none | Fast |
Manim compiles each formula TeX → DVI → SVG and real-time-manim rasterizes the
SVG. Output is cached so unchanged formulas are compiled only once — see the
util helpers and Getting Started for warming the cache
before a batch run.
# Normal usage — nothing to configure:
tex = MathTex(r"e^{i\pi} + 1 = 0")Set _USE_NATIVE_MATHTEX = True to bypass LaTeX entirely. LaTeX commands are
translated to Unicode glyphs and rendered through Text + TrueType fonts, with
super/subscripts placed manually. It works without TeX installed but does not
produce true math layout — complex constructs render literally.
from real_time_manim.vulkan_bind import _USE_NATIVE_MATHTEX
_USE_NATIVE_MATHTEX = True # fast, Unicode-only fallbackThe translator ships mappings for common LaTeX shorthands, including:
- Greek letters (α, β, γ, δ, …)
- Binary operators (±, ×, ÷, ⊕, …)
- Relations (≤, ≥, ≠, ≈, …)
- Arrows (←, →, ↔, ⇒, …)
- Set theory (∪, ∩, ∈, ∅, …)
- Hebrew letters (ℵ, ℶ, ℸ)
- Delimiters and structural commands
Note on the default: real LaTeX rendering is kept on by default precisely because the older Unicode fallback rendered many constructs (
\frac,\sqrt,\mathbb, matrices, accents) as literal text rather than proper math glyphs. Flip the flag only when you are happy trading fidelity for a TeX-less, faster pipeline.
Repeatedly recompiling the same formula wastes time. Use the util helpers:
from real_time_manim.util import restore_tex_cache, save_tex_cache
restore_tex_cache("tex_cache") # copy cached SVGs into media/Tex before rendering
# ... render your MathTex scenes ...
save_tex_cache("tex_cache") # store any newly compiled SVGs for next timerestore_tex_cache/save_tex_cache default to .svg assets under
<cwd>/media/Tex, and accept media_dir, tex_subdir, only_ext, overwrite
and dry_run to point elsewhere or be selective. The recorders already clear the
transient media/ folder after a run; they do not touch your persistent
tex_cache, which lives on between runs.