From 08fabfe02e0283cbc7c9bc129b3ee3d59ce7667b Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Mon, 30 Apr 2012 00:19:55 +0200 Subject: [PATCH] remove latex support. Will be in a plugin. Fixes #4176 --- src/common/config.py | 2 - src/common/gajim.py | 4 - src/common/latex.py | 180 ----------------------------------- src/conversation_textview.py | 25 ----- src/features_window.py | 8 -- src/gui_interface.py | 10 -- 6 files changed, 229 deletions(-) delete mode 100644 src/common/latex.py diff --git a/src/common/config.py b/src/common/config.py index b33f1c2ad..007e7e624 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -278,12 +278,10 @@ class Config: 'show_contacts_number': [opt_bool, True, _('If True, Gajim will show number of online and total contacts in account and group rows.')], 'treat_incoming_messages': [ opt_str, '', _('Can be empty, \'chat\' or \'normal\'. If not empty, treat all incoming messages as if they were of this type')], 'scroll_roster_to_last_message': [opt_bool, True, _('If True, Gajim will scroll and select the contact who sent you the last message, if chat window is not already opened.')], - 'use_latex': [opt_bool, False, _('If True, Gajim will convert string between $$ and $$ to an image using dvips and convert before insterting it in chat window.')], 'change_status_window_timeout': [opt_int, 15, _('Time of inactivity needed before the change status window closes down.')], 'max_conversation_lines': [opt_int, 500, _('Maximum number of lines that are printed in conversations. Oldest lines are cleared.')], 'attach_notifications_to_systray': [opt_bool, False, _('If True, notification windows from notification-daemon will be attached to notification icon.')], 'check_idle_every_foo_seconds': [opt_int, 2, _('Choose interval between 2 checks of idleness.')], - 'latex_png_dpi': [opt_str, '108', _('Change the value to change the size of latex formulas displayed. The higher is larger.') ], 'uri_schemes': [opt_str, 'aaa:// aaas:// acap:// cap:// cid: crid:// data: dav: dict:// dns: fax: file:/ ftp:// geo: go: gopher:// h323: http:// https:// iax: icap:// im: imap:// info: ipp:// iris: iris.beep: iris.xpc: iris.xpcs: iris.lwz: ldap:// mid: modem: msrp:// msrps:// mtqp:// mupdate:// news: nfs:// nntp:// opaquelocktoken: pop:// pres: prospero:// rtsp:// service: shttp:// sip: sips: sms: snmp:// soap.beep:// soap.beeps:// tag: tel: telnet:// tftp:// thismessage:/ tip:// tv: urn:// vemmi:// xmlrpc.beep:// xmlrpc.beeps:// z39.50r:// z39.50s:// about: apt: cvs:// daap:// ed2k:// feed: fish:// git:// iax2: irc:// ircs:// ldaps:// magnet: mms:// rsync:// ssh:// svn:// sftp:// smb:// webcal://', _('Valid uri schemes. Only schemes in this list will be accepted as "real" uri. (mailto and xmpp are handled separately)'), True], 'ask_offline_status_on_connection': [ opt_bool, False, _('Ask offline status message to all offline contacts when connection to an accoutn is established. WARNING: This causes a lot of requests to be sent!') ], 'shell_like_completion': [ opt_bool, False, _('If True, completion in groupchats will be like a shell auto-completion')], diff --git a/src/common/gajim.py b/src/common/gajim.py index 1a1c84e83..ed29a5087 100644 --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -167,10 +167,6 @@ else: if subprocess.call(gpg_cmd, shell=True): HAVE_GPG = False -# Depends on use_latex option. Will be correctly set after we config options are -# read. -HAVE_LATEX = False - HAVE_FARSTREAM = True try: farstream = __import__('farstream') diff --git a/src/common/latex.py b/src/common/latex.py deleted file mode 100644 index 6a8b08aae..000000000 --- a/src/common/latex.py +++ /dev/null @@ -1,180 +0,0 @@ -# -*- coding:utf-8 -*- -## src/common/latex.py -## -## Copyright (C) 2005 Norman Rasmussen -## Copyright (C) 2005-2006 Alex Mauer -## Travis Shirk -## Copyright (C) 2005-2007 Nikos Kouremenos -## Copyright (C) 2005-2012 Yann Leboulanger -## Copyright (C) 2006 Dimitur Kirov -## Copyright (C) 2006-2008 Jean-Marie Traissard -## Copyright (C) 2008 Jonathan Schleifer -## Julien Pivotto -## Stephan Erb -## -## This file is part of Gajim. -## -## Gajim is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published -## by the Free Software Foundation; version 3 only. -## -## Gajim is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with Gajim. If not, see . -## - -import os -import random -from tempfile import mkstemp, mkdtemp -from subprocess import Popen, PIPE - -import logging -log = logging.getLogger('gajim.c.latex') - -import gajim -from exceptions import LatexError -import helpers - -# some latex commands are really bad -blacklist = ['\\def', '\\let', '\\futurelet', - '\\newcommand', '\\renewcomment', '\\else', '\\fi', '\\write', - '\\input', '\\include', '\\chardef', '\\catcode', '\\makeatletter', - '\\noexpand', '\\toksdef', '\\every', '\\errhelp', '\\errorstopmode', - '\\scrollmode', '\\nonstopmode', '\\batchmode', '\\read', '\\csname', - '\\newhelp', '\\relax', '\\afterground', '\\afterassignment', - '\\expandafter', '\\noexpand', '\\special', '\\command', '\\loop', - '\\repeat', '\\toks', '\\output', '\\line', '\\mathcode', '\\name', - '\\item', '\\section', '\\mbox', '\\DeclareRobustCommand', '\\[', - '\\]'] -# True if the string matches the blacklist -def check_blacklist(str_): - for word in blacklist: - if word in str_: - return True - return False - -def write_latex(filename, str_): - texstr = '\\documentclass[12pt]{article}\\usepackage[dvips]{graphicx}' - texstr += '\\usepackage{amsmath}\\usepackage{amssymb}' - texstr += '\\pagestyle{empty}' - texstr += '\\begin{document}\\begin{large}\\begin{gather*}' - texstr += str_ - texstr += '\\end{gather*}\\end{large}\\end{document}' - - file_ = open(filename, "w+") - file_.write(texstr) - file_.flush() - file_.close() - -# a wrapper for Popen so that no window gets opened on Windows -# (i think this is the reason we're using Popen rather than just system()) -# stdout goes to a pipe so that it can be read -def popen_nt_friendly(command, directory): - if os.name == 'nt': - # CREATE_NO_WINDOW - return Popen(command, creationflags=0x08000000, cwd=directory, - stdout=PIPE) - else: - return Popen(command, cwd=directory, stdout=PIPE) - -def check_for_latex_support(): - """ - Check if latex is available and if it can create a picture - """ - try: - filename = latex_to_image("test") - if filename: - # we have a file, conversion succeeded - os.remove(filename) - return True - return False - except LatexError: - return False - -def try_run(argv, directory): - try: - p = popen_nt_friendly(argv, directory) - 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(str(e))} - - -def latex_to_image(str_): - result = None - exitcode = 0 - - def fg_str(fmt): - try: - return [{'hex' : '+level-colors', 'tex' : '-fg'}[fmt], - gajim.interface.get_fg_color(fmt)] - except KeyError: - # interface may not be available when we test latex at startup - return [] - except AttributeError: - # interface may not be available when we test latext at startup - return {'hex': ['+level-colors', '0x000000'], - 'tex': ['-fg', 'rgb 0.0 0.0 0.0']}[fmt] - - # filter latex code with bad commands - if check_blacklist(str_): - # we triggered the blacklist, immediately return None - return None - - try: - tmpdir = mkdtemp(prefix='gajimtex') - tmppng = mkstemp(prefix='gajim_tex', suffix='.png')[1] - except Exception: - raise LatexError('could not securely create one or more temporary files' - ' for LaTeX conversion') - - tmpfile = os.path.join(tmpdir, 'gajim_tex') - - # build latex string - write_latex(tmpfile + '.tex', str_) - - # convert TeX to dvi - exitcode = try_run(['latex', '--interaction=nonstopmode', tmpfile + '.tex'], - tmpdir) - - if exitcode == 0: - # convert dvi to png - latex_png_dpi = gajim.config.get('latex_png_dpi') - exitcode = try_run(['dvipng'] + fg_str('tex') + ['-T', 'tight', '-D', - latex_png_dpi, tmpfile + '.dvi', '-o', tmpfile + '.png'], tmpdir) - - if exitcode: - # dvipng failed, try convert - exitcode = try_run(['convert'] + fg_str('hex') + ['-trim', - '-density', latex_png_dpi, tmpfile + '.dvi', tmpfile + '.png'], - tmpdir) - - # remove temp files created by us and TeX - extensions = ['.tex', '.log', '.aux', '.dvi'] - for ext in extensions: - try: - os.remove(tmpfile + ext) - except Exception: - pass - - if exitcode == 0: - os.rename(tmpfile + '.png', tmppng) - else: - os.remove(tmppng) - - os.rmdir(tmpdir) - - if isinstance(exitcode, (unicode, str)): - raise LatexError(exitcode) - - if exitcode == 0: - result = tmppng - - return result diff --git a/src/conversation_textview.py b/src/conversation_textview.py index eed90ecc1..61b7ae5c8 100644 --- a/src/conversation_textview.py +++ b/src/conversation_textview.py @@ -1148,31 +1148,6 @@ class ConversationTextview(gobject.GObject): else: if not show_ascii_formatting_chars: special_text = special_text[1:-1] # remove _ _ - elif gajim.HAVE_LATEX and special_text.startswith('$$') and \ - special_text.endswith('$$') and graphics: - try: - imagepath = latex.latex_to_image(special_text[2:-2]) - except LatexError, e: - # print the error after the line has been written - gobject.idle_add(self.print_conversation_line, str(e), '', 'info', - '', None) - imagepath = None - end_iter = buffer_.get_end_iter() - if imagepath is not None: - anchor = buffer_.create_child_anchor(end_iter) - img = TextViewImage(anchor, special_text) - img.set_from_file(imagepath) - img.show() - # add - self.tv.add_child_at_anchor(img, anchor) - # delete old file - try: - os.remove(imagepath) - except Exception: - pass - else: - buffer_.insert(end_iter, special_text) - use_other_tags = False else: # It's nothing special if use_other_tags: diff --git a/src/features_window.py b/src/features_window.py index dff1135f9..0894cca61 100644 --- a/src/features_window.py +++ b/src/features_window.py @@ -91,10 +91,6 @@ class FeaturesWindow: _('Ability to measure idle time, in order to set auto status.'), _('Requires libxss library.'), _('Requires python2.5.')), - _('LaTeX'): (self.latex_available, - _('Transform LaTeX expressions between $$ $$.'), - _('Requires texlive-latex-base and (dvipng or ImageMagick). You have to set \'use_latex\' to True in the Advanced Configuration Editor.'), - _('Requires texlive-latex-base and (dvipng or ImageMagick) (All is in MikTeX). You have to set \'use_latex\' to True in the Advanced Configuration Editor.')), _('End to End message encryption'): (self.pycrypto_available, _('Encrypting chat messages.'), _('Requires python-crypto.'), @@ -244,10 +240,6 @@ class FeaturesWindow: from common import sleepy return sleepy.SUPPORTED - def latex_available(self): - from common import latex - return latex.check_for_latex_support() - def pycrypto_available(self): return gajim.HAVE_PYCRYPTO diff --git a/src/gui_interface.py b/src/gui_interface.py index 4d5c67efb..dff02d25c 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -1838,17 +1838,11 @@ class Interface: r'(?