detect latex support at startup
This commit is contained in:
parent
02659358db
commit
9298312369
3 changed files with 62 additions and 55 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue