Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LaTeX compilation failed also #2314

Open
shuiyuan233 opened this issue Feb 18, 2025 · 3 comments
Open

LaTeX compilation failed also #2314

shuiyuan233 opened this issue Feb 18, 2025 · 3 comments

Comments

@shuiyuan233
Copy link

Describe the error

When I use the Tex function ,then put the error.After multiple tests, including reinstalling Texlive, cloning the source code, and modifying according to last month's issue report, I still cannot run the Tex function .

Code and Error

Code:

from manimlib import *
from os import system

class Example(Scene):
    def construct(self):
        tex1 = Tex("E = mc^2")
        tex2 = Tex("a^2 + b^2 = c^2")
        group = VGroup(tex1, tex2).arrange(DOWN)
        self.play(Write(group))
        self.wait()
if __name__ == "__main__":
    system("manimgl {}  ".format(__file__))

Error:

ManimGL v1.7.2
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "d:\App_Data\manim-master\.conda\Scripts\manimgl.exe\__main__.py", line 7, in <module>
  File "D:\App_Data\manim-master\manimlib\__main__.py", line 61, in main
    run_scenes()
  File "D:\App_Data\manim-master\manimlib\__main__.py", line 39, in run_scenes
    scene.run()
  File "D:\App_Data\manim-master\manimlib\scene\scene.py", line 155, in run
    self.construct()
  File "d:\App_Data\manim-master\123.py", line 6, in construct
    tex1 = Tex("E = mc^2")
           ^^^^^^^^^^^^^^^
  File "D:\App_Data\manim-master\manimlib\mobject\svg\tex_mobject.py", line 59, in __init__
    super().__init__(
  File "D:\App_Data\manim-master\manimlib\mobject\svg\string_mobject.py", line 69, in __init__
    svg_string = self.get_svg_string()
                 ^^^^^^^^^^^^^^^^^^^^^
  File "D:\App_Data\manim-master\manimlib\mobject\svg\string_mobject.py", line 77, in get_svg_string
    return self.get_svg_string_by_content(content)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\App_Data\manim-master\manimlib\mobject\svg\tex_mobject.py", line 70, in get_svg_string_by_content
    return latex_to_svg(content, self.template, self.additional_preamble, short_tex=self.tex_string)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\App_Data\manim-master\manimlib\utils\tex_file_writing.py", line 81, in latex_to_svg
    return full_tex_to_svg(full_tex, compiler, message)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\App_Data\manim-master\manimlib\utils\cache.py", line 27, in wrapper
    value = func(*args, **kwargs)
            ^^^^^^^^^^^^^^^^^^^^^
  File "D:\App_Data\manim-master\manimlib\utils\tex_file_writing.py", line 127, in full_tex_to_svg
    raise LatexError(error_str or "LaTeX compilation failed")
manimlib.utils.tex_file_writing.LatexError: LaTeX compilation failed>

Environment

OS System: Win 10
manim version: manim master 2025.02.18
python version:conda python 3.11.11

@pc86152
Copy link

pc86152 commented Feb 25, 2025

  1. class Example(Scene):
    def construct(self):
    tex1 = Tex("E = mc^2", template="ctex")
    tex2 = Tex("a^2 + b^2 = c^2", template="ctex")
    group = VGroup(tex1, tex2).arrange(DOWN)
    self.play(Write(group))
    self.wait()

  2. .\venv\Lib\site-packages\manimlib\utils\tex_file_writing.py
    @cache_on_disk
    def full_tex_to_svg(full_tex: str, compiler: str = "latex", message: str = ""):
    ...

    Write intermediate files to a temporary directory

    with tempfile.TemporaryDirectory() as temp_dir:
    temp_dir = temp_dir.replace(r"ADMINI~1", "Administrator")
    tex_path = Path(temp_dir, "working").with_suffix(".tex")
    dvi_path = tex_path.with_suffix(dvi_ext)
    ...

I solve it by this two change, but I don't know why.

@mryuans
Copy link

mryuans commented Feb 26, 2025

I also have had this problem for months. It seems that the .tex file can't be written, so do the .log (by the way, it seems that the problem is still there, even if I have followed the changes)

@mryuans
Copy link

mryuans commented Feb 26, 2025

I have found a solution after checking the TemporaryDirectory class:

       ...
    # provide an actual directory
    with tempfile.TemporaryDirectory(dir=r"C:\tmp\temp_latex_base") as temp_dir:
        temp_dir = temp_dir.replace(r"ADMINI~1", "Administrator")   # <- it seems that this change doesn't work out my problem
        tex_path = Path(temp_dir, "working").with_suffix(".tex")
        dvi_path = tex_path.with_suffix(dvi_ext)
       ...

But the tex is rendered slower than other items (because I provided an actual directory to save the file? I'm not sure.)

Looking forward to a better solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants