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

Error running the command, related to latex2svg.py #39

Closed
jjnilton opened this issue May 2, 2021 · 8 comments
Closed

Error running the command, related to latex2svg.py #39

jjnilton opened this issue May 2, 2021 · 8 comments
Labels
bug - error Fails with an error

Comments

@jjnilton
Copy link

jjnilton commented May 2, 2021

Hi, thanks for sharing this software!

However, I'm not able to run it, even running just gh-md-to-html or gh-md-to-html -d gives an error. I'm using the version gh-md-to-html-1.11.6 and Python 3.9.2 on Debian Bullseye.

Traceback (most recent call last):
  File "/home/jj/.local/lib/python3.9/site-packages/gh_md_to_html/latex2svg.py", line 101, in latex2svg
    ret.check_returncode()
  File "/usr/lib/python3.9/subprocess.py", line 460, in check_returncode
    raise CalledProcessError(self.returncode, self.args, self.stdout,
subprocess.CalledProcessError: Command '['latex', '-interaction', 'nonstopmode', '-halt-on-error', 'code.tex']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 188, in _run_module_as_main
    mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
  File "/usr/lib/python3.9/runpy.py", line 147, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.9/runpy.py", line 111, in _get_module_details
    __import__(pkg_name)
  File "/home/jj/.local/lib/python3.9/site-packages/gh_md_to_html/__init__.py", line 1, in <module>
    from .__main__ import *
  File "/home/jj/.local/lib/python3.9/site-packages/gh_md_to_html/__main__.py", line 247, in <module>
    raw_formula2svg_offline("w")
  File "/home/jj/.local/lib/python3.9/site-packages/gh_md_to_html/__main__.py", line 236, in raw_formula2svg_offline
    return latex2svg(formula)["svg"]
  File "/home/jj/.local/lib/python3.9/site-packages/gh_md_to_html/latex2svg.py", line 84, in latex2svg
    return latex2svg(code, params, working_directory=tmpdir)
  File "/home/jj/.local/lib/python3.9/site-packages/gh_md_to_html/latex2svg.py", line 103, in latex2svg
    raise Exception("LaTeX failed with error:", str(ret.stderr, encoding="UTF-8"),
Exception: ('LaTeX failed with error:', '', '\nThis happened whilst rendering formula $w$.')
@phseiff
Copy link
Owner

phseiff commented May 2, 2021

Hi! Thanks for sharing this issue, I'm taking a look at it right now.

So every time you run this command, even if it's just gh-md-to-html -h, you get this error? Or is it just whenever you try to convert a markdown file?

@phseiff
Copy link
Owner

phseiff commented May 2, 2021

Does this happen with every markdown file, or just one specific one? Did you try running it on a semi-empty file, with nothing but e.g. "foo" inside?

@phseiff phseiff added the bug - error Fails with an error label May 2, 2021
@jjnilton
Copy link
Author

jjnilton commented May 2, 2021

Yes, it happens even when using gh-md-to-html without any options. It seems to happen with any markdown file too:

j@jj-mpc:~/Downloads$ echo "foo" > test.md
jj@jj-mpc:~/Downloads$ gh-md-to-html test.md 
Traceback (most recent call last):
  File "/home/jj/.local/lib/python3.9/site-packages/gh_md_to_html/latex2svg.py", line 101, in latex2svg
    ret.check_returncode()
  File "/usr/lib/python3.9/subprocess.py", line 460, in check_returncode
    raise CalledProcessError(self.returncode, self.args, self.stdout,
subprocess.CalledProcessError: Command '['latex', '-interaction', 'nonstopmode', '-halt-on-error', 'code.tex']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:
[...]

@phseiff phseiff closed this as completed in ccbb941 May 2, 2021
@phseiff
Copy link
Owner

phseiff commented May 2, 2021

Okay, I think I found the problem:

What happens is that gh-md-to-html always checks whether LaTeX is installed or not, to see whether it should use the local installation of LaTeX or an online conversion tool to embed LaTeX formulas into the document (which probably isn't even relevant to you if you don't have any formulas within your document).

It does this by testing out whether LaTeX conversion works, and by then catching the error and processing it.
The mistake I made was that I forgot to properly catch some errors that latex2svg.py raises, causing gh-md-to-html to crash on some devices without a compatible LaTeX installation.


This issue should be fixed now; could you try updating to v1.11.7 (via pip3 install --upgrade gh-md-to-html>=1.11.7) and see if the issue is fixed?

@jjnilton
Copy link
Author

jjnilton commented May 2, 2021

It works now, the error is gone. I still see a warning, though:

$ gh-md-to-html 
/usr/lib/python3.9/runpy.py:127: RuntimeWarning: 'gh_md_to_html.__main__' found in sys.modules after import of package 'gh_md_to_html', but prior to execution of 'gh_md_to_html.__main__'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))

But the conversion works. Thanks for the explanation!

@phseiff
Copy link
Owner

phseiff commented May 2, 2021

The warning has been bugging me for a long time now, but I haven't managed to get rid of it, unfortunately.
It's related to how gh-md-to-html is a Python module run by a script wrapper, I think; though I should probably try to re-look into it eventually.

Thanks for the explanation!

You're welcome :)

@phseiff
Copy link
Owner

phseiff commented Jun 17, 2021

@jjnilton
Hello,

It works now, the error is gone. I still see a warning, though:

I know it probably isn't even relevant to you anymore, but the warning you mentioned should be gone now, if you update to v1.11.11 (via pip3 install --upgrade gh-md-to-html>=1.11.11).

@jjnilton
Copy link
Author

Nice! Thanks for letting me know.

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

No branches or pull requests

2 participants