From 91018930ee5156e0b59089534bf722d9fa637e4a Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Thu, 27 Aug 2009 19:23:19 +0200
Subject: [PATCH] [avm] fix decode error in latex errors. Fixes #4744

---
 src/common/latex.py | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/src/common/latex.py b/src/common/latex.py
index 82af9a1633..d60922eb8a 100644
--- a/src/common/latex.py
+++ b/src/common/latex.py
@@ -98,6 +98,18 @@ def check_for_latex_support():
 	except LatexError:
 		return False
 
+def try_run(argv):
+	try:
+		p = popen_nt_friendly(argv)
+		out = p.communicate()[0]
+		log.info(out)
+		return p.wait()
+	except Exception, e:
+		return _('Error executing "%(command)s": %(error)s') % {
+			'command': " ".join(argv),
+			'error': helpers.decode_string(e.message)}
+
+
 def latex_to_image(str_):
 	result = None
 	exitcode = 0
@@ -113,31 +125,15 @@ def latex_to_image(str_):
 	write_latex(os.path.join(tmpfile + '.tex'), str_)
 
 	# convert TeX to dvi
-	try:
-		p = popen_nt_friendly(['latex', '--interaction=nonstopmode',
-			tmpfile + '.tex'])
-		out = p.communicate()[0]
-		log.info(out)
-		exitcode = p.wait()
-	except Exception, e:
-		exitcode = _('Error executing "%(command)s": %(error)s') % {
-			'command': 'latex --interaction=nonstopmode %s.tex' % tmpfile,
-			'error': helpers.decode_string(e.message)}
+	exitcode = try_run(['latex', '--interaction=nonstopmode',
+			  tmpfile + '.tex'])
 
 	if exitcode == 0:
 		# convert dvi to png
 		latex_png_dpi = gajim.config.get('latex_png_dpi')
-		try:
-			p = popen_nt_friendly(['dvipng', '-bg', 'rgb 1.0 1.0 1.0', '-T',
+		exitcode = try_run(['dvipng', '-bg', 'rgb 1.0 1.0 1.0', '-T',
 				'tight', '-D', latex_png_dpi, tmpfile + '.dvi', '-o',
 				tmpfile + '.png'])
-			out = p.communicate()[0]
-			log.info(out)
-			exitcode = p.wait()
-		except Exception, e:
-			exitcode = _('Error executing "%(command)s": %(error)s') % {
-				'command': 'dvipng -bg rgb 1.0 1.0 1.0 -T tight -D %s %s.dvi -o '
-				'%s.png' % (latex_png_dpi, tmpfile, tmpfile), 'error': str(e)}
 
 	# remove temp files created by us and TeX
 	extensions = ['.tex', '.log', '.aux', '.dvi']
-- 
GitLab