Ticket #2796 (closed enhancement: fixed)

Opened 2 years ago

Last modified 18 months ago

LaTeX support

Reported by: cieplik Owned by: asterix
Priority: normal Milestone: 0.12
Component: chat Version:
Severity: normal Keywords:
Cc: OS: All

Description

Hi, it would be really nice to have LaTeX support in Gajim. Have you thought of adding this feature?

Attachments

gajim.patch (3.0 kB) - added by thecurse@… 21 months ago.
gajim-0.11.1-latex.patch
gajim.2.patch (3.8 kB) - added by thecurse@… 21 months ago.
gajim-0.11.1-latex-with-filter.patch

Change History

  Changed 22 months ago by nk

  • status changed from new to closed
  • resolution set to wontfix
  • milestone set to 0.12

why is this useful?

Maybe when GTK textview has MathML support (in 2030) it would be useful. I don't think people that use Latex also IM, and if they do, I doubt they need to IM math types.. And if they need once, they can send the rendered images.

  Changed 22 months ago by DoomHammer

  • status changed from closed to reopened
  • resolution wontfix deleted

And what about GtkMathView? rendering MathML?

follow-up: ↓ 4   Changed 22 months ago by anonymous

  • status changed from reopened to closed
  • resolution set to wontfix

I don't think many people will spend time on typing formulas in IM-Chats and also not very much other clients support LaTeX.

in reply to: ↑ 3   Changed 21 months ago by anonymous

Replying to anonymous:

I don't think many people will spend time on typing formulas in IM-Chats and also not very much other clients support LaTeX.

Well, I am a computer science student and all of the students I know would love that feature! So if you would implement that feature you would make me and many others very happy

  Changed 21 months ago by thecurse@…

  • status changed from closed to reopened
  • resolution wontfix deleted

I've made an example patch for 0.11.1 how it could be implemented. Would be nice if someone could have a look at it:

--- src/conversation_textview.py        2007-02-18 22:37:15.000000000 +0100
+++ src/conversation_textview.py        2007-04-25 19:42:47.000000000 +0200
@@ -14,6 +14,10 @@
 ## GNU General Public License for more details.
 ##
 
+import random
+from tempfile import gettempdir
+from subprocess import Popen
+
 import gtk
 import pango
 import gobject
@@ -572,6 +576,50 @@
 
                return index # the position after *last* special text
 
+       def latex_to_image(self, str):
+               result = None
+
+               str = str[2:len(str)-2]
+           
+               random.seed()
+               tmpfile = os.path.join(gettempdir(), "gajimtex_" + random.randint(0, 100).__str__())
+
+               # build latex string
+               texstr = "\\documentclass[12pt]{article}\\usepackage[dvips]{graphicx}\\usepackage{amsmath}\\usepackage{amssymb}\\pagestyle{empty}"
+               texstr += "\\begin{document}\\begin{large}\\begin{gather*}"
+               texstr += str
+               texstr += "\\end{gather*}\\end{large}\\end{document}"
+
+               file = open(os.path.join(tmpfile + ".tex"), "w+")
+               file.write(texstr)
+               file.flush()
+               file.close()
+
+               p = Popen(['latex', '--interaction=nonstopmode', tmpfile + '.tex'], cwd=gettempdir())
+               exitcode = p.wait()
+
+               if exitcode == 0:           
+                       p = Popen(['dvips', '-E', '-o', tmpfile + '.ps', tmpfile + '.dvi'], cwd=gettempdir())
+                       exitcode = p.wait()
+
+               if exitcode == 0:
+                   p = Popen(['convert', tmpfile + '.ps', tmpfile + '.png'], cwd=gettempdir())
+                   exitcode = p.wait()
+           
+               extensions = [".tex", ".log", ".aux", ".dvi", ".ps"]
+           
+               for ext in extensions:
+                       try:
+                               os.remove(tmpfile + ext)
+                       except Exception:
+                               pass
+           
+               if exitcode == 0:
+                       result = tmpfile + '.png'
+           
+               return result
+
+
        def print_special_text(self, special_text, other_tags):
                '''is called by detect_and_print_special_text and prints
                special text (emots, links, formatting)'''
@@ -656,6 +704,24 @@
                        else:
                                if not show_ascii_formatting_chars:
                                        special_text = special_text[1:-1] # remove _ _
+               elif special_text.startswith('$$') and special_text.endswith('$$'):
+                       imagepath = self.latex_to_image(special_text)
+                       end_iter = buffer.get_end_iter()
+                       anchor = buffer.create_child_anchor(end_iter)
+                       if imagepath != None:
+                               img = gtk.Image()
+                               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 a url
                        tags.append('url')
--- src/gajim.py        2007-02-18 22:37:15.000000000 +0100
+++ src/gajim.py        2007-04-25 19:23:10.000000000 +0200
@@ -1713,7 +1713,13 @@
                        r'(?<!\w|\<)' r'/[^\s/]' r'([^/]*[^\s/])?' r'/(?!\w)|'\
                        r'(?<!\w)' r'_[^\s_]' r'([^_]*[^\s_])?' r'_(?!\w)'
 
+               latex = r'|\$\$.*\$\$'
+
                basic_pattern = links + mail
+
+               #FIXME: make config for latex
+               basic_pattern += latex
+
                if gajim.config.get('ascii_formatting'):
                        basic_pattern += formatting
                self.basic_pattern_re = re.compile(basic_pattern, re.IGNORECASE)

follow-up: ↓ 7   Changed 21 months ago by asterix

hey sounds good ! could you attach it to the ticket as a file attachement instead of in a comment ? I'll test that and add the ACE option for it

Changed 21 months ago by thecurse@…

gajim-0.11.1-latex.patch

in reply to: ↑ 6   Changed 21 months ago by thecurse@…

Replying to asterix:

hey sounds good ! could you attach it to the ticket as a file attachement instead of in a comment ? I'll test that and add the ACE option for it

File attached

follow-up: ↓ 9   Changed 21 months ago by asterix

  • status changed from reopened to closed
  • resolution set to fixed

(In [8111]) [thecurse] add latex support (run dvips and convert externaly) through use_latex ACE option. fixes #2796

Changed 21 months ago by thecurse@…

gajim-0.11.1-latex-with-filter.patch

in reply to: ↑ 8   Changed 21 months ago by thecurse@…

Replying to asterix:

(In [8111]) [thecurse] add latex support (run dvips and convert externaly) through use_latex ACE option. fixes #2796

I have just seen that latex seems to have some very bad commands (someone told me that something like \include rm -rf is absolutely ok for latex) so I took a blacklist from the tomboy-latex plugin and now filter for such words. New patch attached

  Changed 21 months ago by asterix

(In [8114]) [thecurse] blacklist of latex commands. fixes #2796

  Changed 18 months ago by roidelapluie

  • status changed from closed to reopened
  • resolution fixed deleted
  • os set to All

  Changed 18 months ago by roidelapluie

should be added in features window

  Changed 18 months ago by roidelapluie

  • status changed from reopened to closed
  • resolution set to fixed

(In [8415]) [darkwod and I] Add LaTeX in features window. Fix #2796.

Add/Change #2796 (LaTeX support)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.