[ PROMPT_NODE_27754 ]
latex
[ SKILL_DOCUMENTATION ]
# Manim 中的 LaTeX
Manim 原生支持渲染 LaTeX,非常适合制作数学动画和教育内容。
## MathTex - 数学公式
python
from manim import *
class BasicMath(Scene):
def construct(self):
# 简单方程
equation = MathTex(r"E = mc^2")
self.play(Write(equation))
self.wait(2)
## Tex - 文本与数学混合
python
class TexExample(Scene):
def construct(self):
# 混合文本与数学
formula = Tex(r"The famous equation: $E = mc^2$")
self.play(Write(formula))
self.wait(2)
## 复杂方程
python
class ComplexEquations(Scene):
def construct(self):
# 二次公式
quadratic = MathTex(
r"x = frac{-b pm sqrt{b^2 - 4ac}}{2a}"
)
# 积分
integral = MathTex(
r"int_0^{infty} e^{-x^2} dx = frac{sqrt{pi}}{2}"
)
# 矩阵
matrix = MathTex(
r"begin{bmatrix} a & b \ c & d end{bmatrix}"
)
formulas = VGroup(quadratic, integral, matrix)
formulas.arrange(DOWN, buff=1)
self.play(Write(formulas))
self.wait(2)
## 着色部分
为方程的特定部分着色:
python
class ColoredMath(Scene):
def construct(self):
# 将方程拆分为多个部分
equation = MathTex(
r"a^2", "+", "b^2", "=", "c^2"
)
# 为各个部分着色
equation[0].set_color(RED) # a^2
equation[2].set_color(BLUE) # b^2
equation[4].set_color(GREEN) # c^2
self.play(Write(equation))
self.wait(2)
## 方程间的变换
python
class EquationTransform(Scene):
def construct(self):
# 从一个方程开始
eq1 = MathTex(r"x^2 + y^2 = r^2")
# 变换到另一个
eq2 = MathTex(r"(x-h)^2 + (y-k)^2 = r^2")
self.play(Write(eq1))
self.wait(1)
self.play(TransformMatchingShapes(eq1, eq2))
self.wait(2)
## 分步推导
python
class Derivation(Scene):
def construct(self):
# 创建一系列方程
line1 = MathTex(r"x + 5 = 10")
line2 = MathTex(r"x + 5 - 5 = 10 - 5")
line3 = MathTex(r"x = 5")
# 排列它们
equations = VGroup(line1, line2, line3)
equations.arrange(DOWN, buff=0.8)
# 分步展示推导过程
self.play(Write(line