Changeset 8111
- Timestamp:
- 04/25/07 23:51:08 (20 months ago)
- Location:
- trunk/src
- Files:
-
- 3 modified
-
common/config.py (modified) (1 diff)
-
conversation_textview.py (modified) (3 diffs)
-
gajim.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/common/config.py
r8015 r8111 226 226 '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')], 227 227 '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.')], 228 '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.')], 228 229 } 229 230 -
trunk/src/conversation_textview.py
r7959 r8111 14 14 ## GNU General Public License for more details. 15 15 ## 16 17 import random 18 from tempfile import gettempdir 19 from subprocess import Popen 16 20 17 21 import gtk … … 572 576 573 577 return index # the position after *last* special text 578 579 def latex_to_image(self, str): 580 result = None 581 582 str = str[2:len(str)-2] 583 584 random.seed() 585 tmpfile = os.path.join(gettempdir(), "gajimtex_" + random.randint(0, 100).__str__()) 586 587 # build latex string 588 texstr = "\\documentclass[12pt]{article}\\usepackage[dvips]{graphicx}\\usepackage{amsmath}\\usepackage{amssymb}\\pagestyle{empty}" 589 texstr += "\\begin{document}\\begin{large}\\begin{gather*}" 590 texstr += str 591 texstr += "\\end{gather*}\\end{large}\\end{document}" 592 593 file = open(os.path.join(tmpfile + ".tex"), "w+") 594 file.write(texstr) 595 file.flush() 596 file.close() 597 598 p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'], cwd=gettempdir()) 599 exitcode = p.wait() 600 601 if exitcode == 0: 602 p = Popen(['dvips', '-E', '-o', tmpfile + '.ps', tmpfile + '.dvi'], cwd=gettempdir()) 603 exitcode = p.wait() 604 605 if exitcode == 0: 606 p = Popen(['convert', tmpfile + '.ps', tmpfile + '.png'], cwd=gettempdir()) 607 exitcode = p.wait() 608 609 extensions = [".tex", ".log", ".aux", ".dvi", ".ps"] 610 611 for ext in extensions: 612 try: 613 os.remove(tmpfile + ext) 614 except Exception: 615 pass 616 617 if exitcode == 0: 618 result = tmpfile + '.png' 619 620 return result 621 574 622 575 623 def print_special_text(self, special_text, other_tags): … … 657 705 if not show_ascii_formatting_chars: 658 706 special_text = special_text[1:-1] # remove _ _ 707 elif special_text.startswith('$$') and special_text.endswith('$$'): 708 imagepath = self.latex_to_image(special_text) 709 end_iter = buffer.get_end_iter() 710 anchor = buffer.create_child_anchor(end_iter) 711 if imagepath != None: 712 img = gtk.Image() 713 img.set_from_file(imagepath) 714 img.show() 715 # add 716 self.tv.add_child_at_anchor(img, anchor) 717 # delete old file 718 try: 719 os.remove(imagepath) 720 except Exception: 721 pass 722 else: 723 buffer.insert(end_iter, special_text) 724 use_other_tags = False 659 725 else: 660 726 #it's a url -
trunk/src/gajim.py
r8100 r8111 1824 1824 r'(?<!\w)' r'_[^\s_]' r'([^_]*[^\s_])?' r'_(?!\w)' 1825 1825 1826 latex = r'|\$\$.*\$\$' 1827 1826 1828 basic_pattern = links + mail 1829 1830 if gajim.config.get('use_latex'): 1831 basic_pattern += latex 1832 1827 1833 if gajim.config.get('ascii_formatting'): 1828 1834 basic_pattern += formatting
