Skip to content

Commit

Permalink
Fix sphinx-doc#9868: imgmath: Crashed if the dvisvgm command failed t…
Browse files Browse the repository at this point in the history
…o convert equation
  • Loading branch information
tk0miya committed Nov 23, 2021
1 parent c8f019a commit 9988b62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -25,6 +25,7 @@ Bugs fixed
having invalid __doc__ atribute
* #9872: html: Class namespace collision between autodoc signatures and
docutils-0.17
* #9868: imgmath: Crashed if the dvisvgm command failed to convert equation
* #9864: mathjax: Failed to render equations via MathJax v2. The loading method
of MathJax is back to "async" method again

Expand Down
9 changes: 5 additions & 4 deletions sphinx/ext/imgmath.py
Expand Up @@ -43,11 +43,11 @@
class MathExtError(SphinxError):
category = 'Math extension error'

def __init__(self, msg: str, stderr: bytes = None, stdout: bytes = None) -> None:
def __init__(self, msg: str, stderr: str = None, stdout: str = None) -> None:
if stderr:
msg += '\n[stderr]\n' + stderr.decode(sys.getdefaultencoding(), 'replace')
msg += '\n[stderr]\n' + stderr
if stdout:
msg += '\n[stdout]\n' + stdout.decode(sys.getdefaultencoding(), 'replace')
msg += '\n[stdout]\n' + stdout
super().__init__(msg)


Expand Down Expand Up @@ -135,7 +135,8 @@ def compile_math(latex: str, builder: Builder) -> str:
command.append('math.tex')

try:
subprocess.run(command, stdout=PIPE, stderr=PIPE, cwd=tempdir, check=True)
subprocess.run(command, stdout=PIPE, stderr=PIPE, cwd=tempdir, check=True,
encoding='ascii')
return path.join(tempdir, 'math.dvi')
except OSError as exc:
logger.warning(__('LaTeX command %r cannot be run (needed for math '
Expand Down

0 comments on commit 9988b62

Please sign in to comment.