Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 6c6b332

Browse files
committedNov 4, 2021
32650: independent and improved method latex().is_functional()
1 parent 345c760 commit 6c6b332

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed
 

Diff for: ‎src/sage/features/latex.py

+26-9
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,34 @@ def is_functional(self):
4545
sage: latex().is_functional() # optional: latex
4646
FeatureTestResult('latex', True)
4747
"""
48-
from sage.misc.latex import _run_latex_, _latex_file_
48+
lines = []
49+
lines.append(r"\documentclass{article}")
50+
lines.append(r"\begin{document}")
51+
lines.append(r"$\alpha+2$")
52+
lines.append(r"\end{document}")
53+
content = '\n'.join(lines)
54+
55+
# create a simple tex file with the content
4956
from sage.misc.temporary_file import tmp_filename
50-
try:
51-
f = tmp_filename(ext='.tex')
52-
O = open(f, 'w')
53-
O.write(_latex_file_('2+3'))
54-
O.close()
55-
_run_latex_(f)
57+
base_filename_tex = tmp_filename(ext='.tex')
58+
with open(base_filename_tex, 'w') as f:
59+
f.write(content)
60+
import os
61+
base, filename_tex = os.path.split(base_filename_tex)
62+
63+
# running latex
64+
from subprocess import run
65+
cmd = ['latex', '-interaction=nonstopmode', filename_tex]
66+
cmd = ' '.join(cmd)
67+
result = run(cmd, shell=True, cwd=base, capture_output=True, text=True)
68+
69+
# return
70+
if result.returncode == 0:
5671
return FeatureTestResult(self, True)
57-
except Exception:
58-
return FeatureTestResult(self, False, reason="Running latex on a sample file raised an exception")
72+
else:
73+
return FeatureTestResult(self, False, reason="Running latex on "
74+
"a sample file returned non-zero "
75+
"exit status {}".format(result.returncode))
5976

6077
class pdflatex(Executable):
6178
r"""

0 commit comments

Comments
 (0)