{"record":{"id":"9a12b89a6a0092f6","repo":"3b1b/manim","slug":"latex-compilation-failed","errorCode":null,"errorMessage":"LaTeX compilation failed","messagePattern":"LaTeX compilation failed","errorType":"exception","errorClass":"LatexError","httpStatus":null,"severity":"error","filePath":"manimlib/utils/tex_file_writing.py","lineNumber":135,"sourceCode":"            \"-interaction=batchmode\",\n            \"-halt-on-error\",\n            f\"-output-directory={temp_dir}\",\n            tex_path.as_posix(),\n        ],\n        capture_output=True,\n        text=True,\n    )\n\n    if process.returncode != 0 and not dvi_path.exists():\n        # Handle error\n        error_str = \"\"\n        log_path = tex_path.with_suffix(\".log\")\n        if log_path.exists():\n            content = log_path.read_text()\n            error_match = re.search(r\"(?<=\\n! ).*\\n.*\\n\", content)\n            if error_match:\n                error_str = error_match.group()\n        raise LatexError(error_str or \"LaTeX compilation failed\")\n\n    # Run dvisvgm and capture output directly\n    process = subprocess.run(\n        [\n            \"dvisvgm\",\n            dvi_path,\n            \"-n\",  # no fonts\n            \"-v\",\n            \"0\",  # quiet\n            \"--stdout\",  # output to stdout instead of file\n        ],\n        capture_output=True,\n    )\n\n    # Return SVG string\n    result = process.stdout.decode(\"utf-8\")\n\n    if message:","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/3b1b/manim/blob/dee01804d47b9f94402d71472674710dcac125b8/manimlib/utils/tex_file_writing.py#L117-L153","documentation":"Raised as LatexError by full_tex_to_svg (tex_file_writing.py:135) when the TeX subprocess exits non-zero AND no dvi/xdv output was produced. The message is extracted from the .log file by regex ('! ' error lines); when extraction finds nothing the generic 'LaTeX compilation failed' text is used.","triggerScenarios":"MathTex(r'\\fra{a}{b}') — an undefined command makes latex exit non-zero with no dvi; missing LaTeX packages (e.g. standalone or preview not installed); using Unicode text with the default 'latex' compiler instead of xelatex.","commonSituations":"Fresh environments without a full LaTeX installation (only basic latex, no dvisvgm/standalone); typos in commands; special characters (&, %, #) unescaped in math mode; CJK content requiring xelatex while config says latex.","solutions":["Read the raised LatexError message — it quotes the '! ' line from the working.tex log; also open <latex_cache>/working.tex and .log to reproduce locally","Fix the reported LaTeX syntax error (typo, missing brace, escape & % # with backslash)","For Unicode/CJK, switch the compiler to xelatex in the manim config","Ensure required LaTeX packages are installed (standalone, preview, dvisvgm toolchain)"],"exampleFix":"# before\nMathTex(r'\\fra{a}{b}')  # undefined command -> LatexError\n\n# after\nMathTex(r'\\frac{a}{b}')","handlingStrategy":"try-catch","validationCode":"import subprocess\n\ndef latex_available() -> bool:\n    return subprocess.run(['latex', '--version'], capture_output=True).returncode == 0","typeGuard":null,"tryCatchPattern":"from manimlib.utils.tex_file_writing import LatexError\ntry:\n    tex = MathTex(src)\nexcept LatexError as e:\n    print('TeX error:', e)\n    tex = MathTex(r'\\text{TeX error}')","preventionTips":["Test small LaTeX snippets with a local latex run first when debugging","Escape special characters (& % #) in math mode","Keep a full LaTeX toolchain (latex/xelatex + dvisvgm + standalone) installed in render environments"],"tags":["manim","latex","compilation","environment","tex"],"backgroundTag":null,"analyzedSha":"dee01804d47b9f94402d71472674710dcac125b8","analyzedAt":"2026-08-14T19:53:44.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}