Skip to content
Snippets Groups Projects
Commit 92983123 authored by Brendan Taylor's avatar Brendan Taylor
Browse files

detect latex support at startup

parent 02659358
No related branches found
No related tags found
No related merge requests found
......@@ -176,6 +176,65 @@ else:
if system('gpg -h >/dev/null 2>&1'):
HAVE_GPG = False
import os
import random
from tempfile import gettempdir
from subprocess import Popen
def check_for_latex_support():
'''check is latex is available and if it can create a picture.'''
exitcode = 0
random.seed()
tmpfile = os.path.join(gettempdir(), "gajimtex_" + \
random.randint(0,100).__str__())
# build latex string
texstr = '\\documentclass[12pt]{article}\\usepackage[dvips]{graphicx}'
texstr += '\\usepackage{amsmath}\\usepackage{amssymb}\\pagestyle{empty}'
texstr += '\\begin{document}\\begin{large}\\begin{gather*}test'
texstr += '\\end{gather*}\\end{large}\\end{document}'
file_ = open(os.path.join(tmpfile + ".tex"), "w+")
file_.write(texstr)
file_.flush()
file_.close()
try:
if os.name == 'nt':
# CREATE_NO_WINDOW
p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'],
creationflags=0x08000000, cwd=gettempdir())
else:
p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'],
cwd=gettempdir())
exitcode = p.wait()
except Exception:
exitcode = 1
if exitcode == 0:
try:
if os.name == 'nt':
# CREATE_NO_WINDOW
p = Popen(['dvipng', '-bg', 'white', '-T', 'tight',
tmpfile + '.dvi', '-o', tmpfile + '.png'],
creationflags=0x08000000, cwd=gettempdir())
else:
p = Popen(['dvipng', '-bg', 'white', '-T', 'tight',
tmpfile + '.dvi', '-o', tmpfile + '.png'], cwd=gettempdir())
exitcode = p.wait()
except Exception:
exitcode = 1
extensions = ['.tex', '.log', '.aux', '.dvi', '.png']
for ext in extensions:
try:
os.remove(tmpfile + ext)
except Exception:
pass
if exitcode == 0:
return True
return False
HAVE_LATEX = check_for_latex_support()
gajim_identity = {'type': 'pc', 'category': 'client', 'name': 'Gajim'}
gajim_common_features = [xmpp.NS_BYTESTREAM, xmpp.NS_SI, xmpp.NS_FILE,
xmpp.NS_MUC, xmpp.NS_MUC_USER, xmpp.NS_MUC_ADMIN, xmpp.NS_MUC_OWNER,
......
......@@ -1141,7 +1141,8 @@ class ConversationTextview:
else:
if not show_ascii_formatting_chars:
special_text = special_text[1:-1] # remove _ _
elif special_text.startswith('$$') and special_text.endswith('$$'):
elif gajim.HAVE_LATEX and special_text.startswith('$$') and \
special_text.endswith('$$'):
try:
imagepath = self.latex_to_image(special_text)
except LatexError, e:
......
......@@ -31,10 +31,6 @@ import gtkgui_helpers
from common import gajim
from common import helpers
import random
from tempfile import gettempdir
from subprocess import Popen
class FeaturesWindow:
'''Class for features window'''
......@@ -255,56 +251,7 @@ class FeaturesWindow:
return sleepy.SUPPORTED
def latex_available(self):
'''check is latex is available and if it can create a picture.'''
exitcode = 0
random.seed()
tmpfile = os.path.join(gettempdir(), "gajimtex_" + \
random.randint(0,100).__str__())
# build latex string
texstr = '\\documentclass[12pt]{article}\\usepackage[dvips]{graphicx}'
texstr += '\\usepackage{amsmath}\\usepackage{amssymb}\\pagestyle{empty}'
texstr += '\\begin{document}\\begin{large}\\begin{gather*}test'
texstr += '\\end{gather*}\\end{large}\\end{document}'
file_ = open(os.path.join(tmpfile + ".tex"), "w+")
file_.write(texstr)
file_.flush()
file_.close()
try:
if os.name == 'nt':
# CREATE_NO_WINDOW
p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'],
creationflags=0x08000000, cwd=gettempdir())
else:
p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'],
cwd=gettempdir())
exitcode = p.wait()
except Exception:
exitcode = 1
if exitcode == 0:
try:
if os.name == 'nt':
# CREATE_NO_WINDOW
p = Popen(['dvipng', '-bg', 'white', '-T', 'tight',
tmpfile + '.dvi', '-o', tmpfile + '.png'],
creationflags=0x08000000, cwd=gettempdir())
else:
p = Popen(['dvipng', '-bg', 'white', '-T', 'tight',
tmpfile + '.dvi', '-o', tmpfile + '.png'], cwd=gettempdir())
exitcode = p.wait()
except Exception:
exitcode = 1
extensions = ['.tex', '.log', '.aux', '.dvi', '.png']
for ext in extensions:
try:
os.remove(tmpfile + ext)
except Exception:
pass
if exitcode == 0:
return True
return False
return gajim.HAVE_LATEX
def pycrypto_available(self):
return gajim.HAVE_PYCRYPTO
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment