Skip to content

Commit dbba0ae

Browse files
committed
Fix #9868: imgmath: Crashed if the dvisvgm command failed to convert equation
1 parent c8f019a commit dbba0ae

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Bugs fixed
2525
having invalid __doc__ atribute
2626
* #9872: html: Class namespace collision between autodoc signatures and
2727
docutils-0.17
28+
* #9868: imgmath: Crashed if the dvisvgm command failed to convert equation
2829
* #9864: mathjax: Failed to render equations via MathJax v2. The loading method
2930
of MathJax is back to "async" method again
3031

sphinx/ext/imgmath.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import re
1313
import shutil
1414
import subprocess
15-
import sys
1615
import tempfile
1716
from os import path
1817
from subprocess import PIPE, CalledProcessError
@@ -43,11 +42,11 @@
4342
class MathExtError(SphinxError):
4443
category = 'Math extension error'
4544

46-
def __init__(self, msg: str, stderr: bytes = None, stdout: bytes = None) -> None:
45+
def __init__(self, msg: str, stderr: str = None, stdout: str = None) -> None:
4746
if stderr:
48-
msg += '\n[stderr]\n' + stderr.decode(sys.getdefaultencoding(), 'replace')
47+
msg += '\n[stderr]\n' + stderr
4948
if stdout:
50-
msg += '\n[stdout]\n' + stdout.decode(sys.getdefaultencoding(), 'replace')
49+
msg += '\n[stdout]\n' + stdout
5150
super().__init__(msg)
5251

5352

@@ -135,7 +134,8 @@ def compile_math(latex: str, builder: Builder) -> str:
135134
command.append('math.tex')
136135

137136
try:
138-
subprocess.run(command, stdout=PIPE, stderr=PIPE, cwd=tempdir, check=True)
137+
subprocess.run(command, stdout=PIPE, stderr=PIPE, cwd=tempdir, check=True,
138+
encoding='ascii')
139139
return path.join(tempdir, 'math.dvi')
140140
except OSError as exc:
141141
logger.warning(__('LaTeX command %r cannot be run (needed for math '

0 commit comments

Comments
 (0)