3b1b / manim

Animation engine for explanatory math videos
MIT License
61.81k stars 5.75k forks source link

Latex Error Converting DVI problem #610

Open JackDusch opened 5 years ago

JackDusch commented 5 years ago

Hello, I have been choogling along with manim and am struggling like many to get the text functional. I managed to implement the changes suggested in #36 which is reiterated in several other threads. I am still able to run commands such as

python3 ./manim.py example_scenes.py SquareToCircle -pl

However, I am experiencing an error message relating to the fix involving TEX_DIR that I am unsure how to fix. I tried pointing directly to the Tex directory within manim but didn't think that was consistent with the advice here either. My current tex_file_writing.py looks like:

def tex_to_dvi(tex_file):
    result = tex_file.replace(".tex", ".xdv")
    if not os.path.exists(result):
        commands = [
            "xelatex",
            "-no-pdf",
            "-interaction=batchmode",
            "-halt-on-error",
            "-output-directory=" TEX_DIR,
            tex_file,
            ">",
            get_null()
        ]
        exit_code = os.system(" ".join(commands))
        if exit_code != 0:
            log_file = tex_file.replace(".tex", ".log")
            raise Exception(
                "Latex error converting to dvi."
                "See log output above or the log file: %s" % log_file)
    return result   

def dvi_to_svg(dvi_file, regen_if_exists=False):
    """
    Converts a dvi, which potentially has multiple slides, into a
    directory full of enumerated pngs corresponding with these slides.
    Returns a list of PIL Image objects for these images sorted as they
    where in the dvi
    """
    result = dvi_file.replace(".xdv", ".svg")
    if not os.path.exists(result):
        commands = [
            "dvisvgm",
            dvi_file,
            "-n",
            "-v",
            "0",
            "-o",
            result,
            ">",
            get_null()
        ]
        os.system(" ".join(commands))
    return result

But, when I attempt to run

python3 ./manim.py example_scenes.py Write Stuff -pl

as a test,

Screen Shot 2019-06-28 at 10 55 19 PM

This is all I can muster. I can still run code not involving text. I tried messing around and removing the TEX_DIR portion, which yields the following message:

Screen Shot 2019-06-28 at 10 59 49 PM

I can't wait to share my work if we can get through this! I appreciate everyone's consideration.

Kolloom commented 5 years ago

Not sure what version you are using. It should be https://github.com/3b1b/manim/blob/master/manimlib/utils/tex_file_writing.py#L47

JackDusch commented 5 years ago

So I am using OS X and it should be the latest version. On blog posts and throughout these issues I see mostly people on OS X using the format of text_to_dvi and dvi_to_svg that I posted. So I should be changing back? There were some issues using dvi on OS X I thought I understood these changes were working around the issues, as in #300, #36.

Additionally, despite error messages pointing to logs in Output or Tex I find both directories are empty. During installation I did set the proper Output according to http://bhowell4.com/manic-install-tutorial-for-mac/

This blog post guided me through installation, and setting the output, then it instructs me to make the changes above for fixing Latex on OS X. I have the latest MacTex installed as of two days ago.

If anyone has any ideas based on my info and the steps in the blog post I would really appreciate it.

Kolloom commented 5 years ago

the two issues you linked are due to missing latex packages, which is not what your error output suggests.

JackDusch commented 5 years ago

Yes that is true, these were the issues I was experiencing that led me to this point, I'm just looking for guidance on what to do from here. Appreciated!

JackDusch commented 5 years ago

With the form you provided, the output changes to this: Screen Shot 2019-06-30 at 5 57 28 PM

Then, I tried to completely replace the tex_file_writing.py method with the one linked, and got this:

Screen Shot 2019-06-30 at 6 00 32 PM

I attempted to replace the result = tex_file.replace(".tex", ".dvi" if not TEX_USE_CTEX else ".xdv") with result = tex_file.replace(".tex", ".xdv") as in #300 for adjusting to OS X, but got

Screen Shot 2019-06-30 at 6 04 09 PM

I'm not sure because either I go revert back to the tex_to_dvi that I started with from #300 or I do what you suggest and fix it from there, I am having major trouble.

Kolloom commented 5 years ago

Modifying the code without understanding how they fit together would not likely yield much result.

The article is not dated. Judging from the comment section its from December last year. There has been a few changes to the file writing so the modification from the article should no longer be needed. Please give this a try: https://github.com/3b1b/manim/blob/master/docs/source/installation/mac.rst

https://pypi.org/project/manimlib/

yoshiask commented 5 years ago

Before you replaced tex_file_writing.py, the error message was AttributeError: module 'manimlib.constants' has no attribute 'TEXT_DIR'.

Line 48 in tex_to_dvi should have consts.TEX_DIR, not consts.TEXT_DIR. If you can, revert back to the form that @Kolloom suggested and change line 48.

AamodJ commented 5 years ago

I am running manim on OS X and I just cloned the repo and everything works fine (if you have all the dependencies right). I think you might have a wrong version of LaTeX. Did you install MikTeX or MacTeX? I've installed MacTeX by brew cask install mactex. If you don't have MacTeX, try installing and trying again. And also, revert your tex_file_writing.py file to the latest one from https://github.com/3b1b/manim/blob/master/manimlib/utils/tex_file_writing.py

gargVader commented 5 years ago

i am having same problem. please help at #623