Add support for old versions of latex (with no --output-directory option).

This commit is contained in:
Glenn Hutchings
2008-11-07 21:46:53 +00:00
parent 7b06f38f2f
commit a15329f9a3

View File

@@ -14,7 +14,7 @@ import shlex
import shutil
import tempfile
import posixpath
from os import path
from os import path, getcwd, chdir
from subprocess import Popen, PIPE
try:
from hashlib import sha1 as sha
@@ -96,9 +96,15 @@ def render_math(self, math):
tf.write(latex)
tf.close()
# build latex command. old versions of latex don't have the
# --output-directory option, so we have to manually chdir to the
# temp dir to run it.
ltx_args = shlex.split(self.builder.config.pngmath_latex)
ltx_args += ['--interaction=nonstopmode', '--output-directory=' + tempdir,
'math.tex']
ltx_args += ['--interaction=nonstopmode', 'math.tex']
curdir = getcwd()
chdir(tempdir)
try:
p = Popen(ltx_args, stdout=PIPE, stderr=PIPE)
except OSError, err:
@@ -110,6 +116,9 @@ def render_math(self, math):
self.builder.config.pngmath_latex)
self.builder._mathpng_warned_latex = True
return relfn, None
finally:
chdir(curdir)
stdout, stderr = p.communicate()
if p.returncode != 0:
raise MathExtError('latex exited with error:\n[stderr]\n%s\n[stdout]\n%s'