如何绕过 manim 代码或对其进行故障排除

问题描述 投票:0回答:1
class AreaCalculation(Scene):
    def construct(self):
        quadrilateral = Polygon(
            ORIGIN, 6 * RIGHT, 6 * RIGHT + 8 * UP, 8 * UP,
            stroke_color=WHITE, fill_color=BLUE, fill_opacity=0.5
        )


        self.play(Create(quadrilateral))
        self.wait(1)


        diagonal = Line(ORIGIN, 6 * RIGHT + 8 * UP, color=WHITE)
        self.play(Create(diagonal))
        self.wait(1)


        labels = VGroup(
            Tex("6", color=WHITE).next_to(quadrilateral.get_edge_center(UP), UP),
            Tex("8", color=WHITE).next_to(quadrilateral.get_edge_center(RIGHT), RIGHT),
            Tex("7", color=WHITE).next_to(quadrilateral.get_edge_center(DOWN), DOWN),
            Tex("9", color=WHITE).next_to(quadrilateral.get_edge_center(LEFT), LEFT)
        )
        self.play(Create(labels))
        self.wait(1)


        triangle_left = Polygon(
            ORIGIN, 6 * RIGHT, 8 * UP,
            stroke_color=WHITE, fill_color=GREEN, fill_opacity=0.5
        )
        triangle_right = Polygon(
            ORIGIN, 6 * RIGHT + 8 * UP, 7 * DOWN,
            stroke_color=WHITE, fill_color=RED, fill_opacity=0.5
        )
        self.play(ReplacementTransform(quadrilateral, triangle_left))
        self.play(ReplacementTransform(diagonal.copy(), triangle_right))
        self.wait(1)


        area_formula = Tex("A = \\frac{1}{2} \\times \\text{base} \\times \\text{height}", color=WHITE)
        area_formula.to_corner(UP + LEFT)
        self.play(Create(area_formula))
        self.wait(1)


        area_left = Tex("A_1 = \\frac{1}{2} \\times 6 \\times 8", color=GREEN)
        area_left.next_to(area_formula, DOWN, buff=0.5)
        self.play(Create(area_left))
        self.wait(1)

        area_right = Tex("A_2 = \\frac{1}{2} \\times 8 \\times 7", color=RED)
        area_right.next_to(area_left, DOWN, buff=0.5)
        self.play(Create(area_right))
        self.wait(1)


        total_area = Tex("Total Area = A_1 + A_2", color=WHITE)
        total_area.next_to(area_right, DOWN, buff=0.5)
        self.play(Create(total_area))
        self.wait(1)
^Z
[08/24/23 06:58:44] WARNING  Didn't find an import statement for Manim. Importing automatically...      module_ops.py:24
                    INFO     Rendering animation from typed code...                                     module_ops.py:28
[08/24/23 06:58:45] ERROR                                                                               module_ops.py:90
                                version is not in the script

                    INFO     Animation 0 : Using cached data (hash :                                cairo_renderer.py:78
                             1413466013_4162449880_223132457)
                    INFO     Animation 1 : Using cached data (hash :                                cairo_renderer.py:78
                             1672018281_345352296_2968648654)
                    INFO     Animation 2 : Using cached data (hash : 1672018281_20178812_660319849) cairo_renderer.py:78
                    INFO     Animation 3 : Using cached data (hash :                                cairo_renderer.py:78
                             1672018281_345352296_3548532017)
[08/24/23 06:58:47] ERROR    LaTeX compilation error: Package babel Error: Unknown option        tex_file_writing.py:285
                             'english'. Either you misspelled it

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ C:\Python311\Lib\site-packages\manim\cli\render\commands.py:115 in render                        │
│                                                                                                  │
│   112 │   │   │   try:                                                                           │
│   113 │   │   │   │   with tempconfig({}):                                                       │
│   114 │   │   │   │   │   scene = SceneClass()                                                   │
│ ❱ 115 │   │   │   │   │   scene.render()                                                         │
│   116 │   │   │   except Exception:                                                              │
│   117 │   │   │   │   error_console.print_exception()                                            │
│   118 │   │   │   │   sys.exit(1)                                                                │
│                                                                                                  │
│ C:\Python311\Lib\site-packages\manim\scene\scene.py:223 in render                                │
│                                                                                                  │
│    220 │   │   """                                                                               │
│    221 │   │   self.setup()                                                                      │
│    222 │   │   try:                                                                              │
│ ❱  223 │   │   │   self.construct()                                                              │
│    224 │   │   except EndSceneEarlyException:                                                    │
│    225 │   │   │   pass                                                                          │
│    226 │   │   except RerunSceneException as e:                                                  │
│ in construct:20                                                                                  │
│                                                                                                  │
│ C:\Python311\Lib\site-packages\manim\mobject\text\tex_mobject.py:449 in __init__                 │
│                                                                                                  │
│   446 │   def __init__(                                                                          │
│   447 │   │   self, *tex_strings, arg_separator="", tex_environment="center", **kwargs           │
│   448 │   ):                                                                                     │
│ ❱ 449 │   │   super().__init__(                                                                  │
│   450 │   │   │   *tex_strings,                                                                  │
│   451 │   │   │   arg_separator=arg_separator,                                                   │
│   452 │   │   │   tex_environment=tex_environment,                                               │
│                                                                                                  │
│ C:\Python311\Lib\site-packages\manim\mobject\text\tex_mobject.py:295 in __init__                 │
│                                                                                                  │
│   292 │   │   │   │   │   │   """,                                                               │
│   293 │   │   │   │   │   ),                                                                     │
│   294 │   │   │   │   )                                                                          │
│ ❱ 295 │   │   │   raise compilation_error                                                        │
│   296 │   │   self.set_color_by_tex_to_color_map(self.tex_to_color_map)                          │
│   297 │   │                                                                                      │
│   298 │   │   if self.organize_left_to_right:                                                    │
│                                                                                                  │
│ C:\Python311\Lib\site-packages\manim\mobject\text\tex_mobject.py:274 in __init__                 │
│                                                                                                  │
│   271 │   │   self.brace_notation_split_occurred = False                                         │
│   272 │   │   self.tex_strings = self._break_up_tex_strings(tex_strings)                         │
│   273 │   │   try:                                                                               │
│ ❱ 274 │   │   │   super().__init__(                                                              │
│   275 │   │   │   │   self.arg_separator.join(self.tex_strings),                                 │
│   276 │   │   │   │   tex_environment=self.tex_environment,                                      │
│   277 │   │   │   │   tex_template=self.tex_template,                                            │
│                                                                                                  │
│ C:\Python311\Lib\site-packages\manim\mobject\text\tex_mobject.py:83 in __init__                  │
│                                                                                                  │
│    80 │   │                                                                                      │
│    81 │   │   assert isinstance(tex_string, str)                                                 │
│    82 │   │   self.tex_string = tex_string                                                       │
│ ❱  83 │   │   file_name = tex_to_svg_file(                                                       │
│    84 │   │   │   self._get_modified_expression(tex_string),                                     │
│    85 │   │   │   environment=self.tex_environment,                                              │
│    86 │   │   │   tex_template=self.tex_template,                                                │
│                                                                                                  │
│ C:\Python311\Lib\site-packages\manim\utils\tex_file_writing.py:54 in tex_to_svg_file             │
│                                                                                                  │
│    51 │   if tex_template is None:                                                               │
│    52 │   │   tex_template = config["tex_template"]                                              │
│    53 │   tex_file = generate_tex_file(expression, environment, tex_template)                    │
│ ❱  54 │   dvi_file = compile_tex(                                                                │
│    55 │   │   tex_file,                                                                          │
│    56 │   │   tex_template.tex_compiler,                                                         │
│    57 │   │   tex_template.output_format,                                                        │
│                                                                                                  │
│ C:\Python311\Lib\site-packages\manim\utils\tex_file_writing.py:201 in compile_tex                │
│                                                                                                  │
│   198 │   │   if exit_code != 0:                                                                 │
│   199 │   │   │   log_file = tex_file.with_suffix(".log")                                        │
│   200 │   │   │   print_all_tex_errors(log_file, tex_compiler, tex_file)                         │
│ ❱ 201 │   │   │   raise ValueError(                                                              │
│   202 │   │   │   │   f"{tex_compiler} error converting to"                                      │
│   203 │   │   │   │   f" {output_format[1:]}. See log output above or"                           │
│   204 │   │   │   │   f" the log file: {log_file}",                                              │

我可以运行简单的动画,但是当我开始充分利用它时,它给了我一个错误。

python animation pdflatex manim
1个回答
0
投票

为了使用数学表达式,您需要将它们括在

Tex()
对象中的美元符号之间,

Tex("$A = \\frac{1}{2} \\times \\text{base} \\times \\text{height}$")

或使用

MathTex()
对象

MathTex("A = \\frac{1}{2} \\times \\text{base} \\times \\text{height}")

如果你甚至使用Python的原始字符串,你可以跳过双

\\

MathTex("A = \frac{1}{2} \times \text{base} \times \text{height}")
© www.soinside.com 2019 - 2024. All rights reserved.