Watexy version 12 - now supporting multiple equations in one blip

icon3 , , , ,
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...
Posted November 11, 2009 at 00:00 (UTC)

First of all, thanks for the feed-back in [1].

I've now fixed three things:
1) It's now possible to put more than one equation in a blip, and they all get nicely/properly displayed, thanks to Michael, post 18 in [1] for a possible solution
2) Instead of using http://www.forkosh.dreamhost.com/mathtex.cgi , I've now installed the program on one of my own servers (thanks a lot for both the software and the service)
3) Multi-line is supported, such that the equation can be written over multiple lines and still be matched correctly

Please do not hesitate to comment this version as well!

By the way, I'm sorry for the delay with this new version. My life as an exchange student in Australia has been a bit hectic with all the travelling besides the studies.

[1]: http://www.scienco.org/2009/watexy-latex-robot-for-google-wave/

The new code is as follows:

# Python reference:
# http://wave-robot-python-client.googlecode.com/svn/trunk/pydocs/index.html
 
# Shortcut to the important OpBasedDocument
# http://wave-robot-python-client.googlecode.com/svn/trunk/pydocs/waveapi.ops.OpBasedDocument-class.html
 
__author__ = 'mikl@mikl.dk (Mikkel Meyer Andersen)'
 
import re
 
from waveapi import events
from waveapi import model
from waveapi import robot
from waveapi import document
 
def OnRobotAdded(properties, context):
  """Invoked when the robot has been added."""
  root_wavelet = context.GetRootWavelet()
  root_wavelet.CreateBlip().GetDocument().SetText("Hi. My name is Watexy and I'm here to help you presenting Latex in waves. Just put the latex between  and , e.g. 2+2=5.")
 
def reversed_iterator(iter):
    return reversed(list(iter))
 
def OnBlipSubmitted(properties, context):
  """Invoked when a blip has been added."""
  blip = context.GetBlipById(properties['blipId']) 
  blip_text_view = blip.GetDocument()
 
  matches = re.finditer('\$\$(.+?)\$\$', blip_text_view.GetText(), re.DOTALL)
 
  """
  Reverse list such that the last items will be changed first, such that
  the positions for the first items doesn't change
  """
  matches = reversed_iterator(matches)
 
  for m in matches:
    """
    The +/- 2 is because of the length of the $$'s. 
    If not removed, the loop will run infintely! 
    """
    blip_text_view.DeleteRange(document.Range(m.start(1)-2, m.end(1)+2))
    image = document.Image('http://meyer.fm/cgi-bin/mathtex.cgi?' + m.group(1), caption=m.group(1))
    blip_text_view.InsertElement(m.start(1)-2, image)
 
if __name__ == '__main__':
  myRobot = robot.Robot('watexy',
      image_url='http://watexy.appspot.com/assets/icon.png',
      version='12',
      profile_url='http://watexy.appspot.com/')
  myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded)
  myRobot.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSubmitted)
  myRobot.Run()

7 Responses

  1. yannis Says:

    1) Is it a known bug that any equation containing > or < does disappears after you compile it (ie hit done?)

    2) what do you mean multi line support?

    3) is it possible to create some kind of aligned equation?

    thanx yannis

  2. Mikkel Meyer Andersen Says:

    Thanks for the reply. I'm looking into the first issue.

    2 just means that you can write
    $ $4
    +5
    +67$ $
    over multiple lines, and it still gets parsed. This is especially helpful when writing matrices and such.

    I'll give 3 a thought. Thanks.

  3. yannis Says:

    Hello again

    1) I think the bug with < and < is fixed in the latest version. At least in most cases.

    2) This is useful indeed.

    3) -

    4) I am extensively using your bot in writing a math project. I have several remarks if you are interested, but I don't know in which direction you are taking this. Is there a plan to actually compile the code within google wave (instead of using a service and replace with picture)? Of course, I don't even know whether this is technically possible from a third party application. The gray out feature is in the right direction. However, I don't want it in the middle of the wave so I end up deleting it after I know it works. It takes a lot of space and destroys the (manual) alignment of my equations. I just copy the code before compiling (ie hit done) and save them in my clipboard (using quicksilver) so I can use them again. I don't know if you can use this idea somehow. In other words, I think the optimal thing in this direction would be to somehow save the latex code without the latter being visible in the wave.

  4. LeoTheHuman Says:

    Try urlencode the parameter in robot and urldecode it in the script itself.

  5. LeoTheHuman Says:

    Hmmm, also these could be encoded as < & > by wave editor, so the imaging software gets the wrong input. Please, check that too.

  6. Mikkel Meyer Andersen Says:

    I actually already fixed the error while is was creating some new features.

    Please take a look at http://www.scienco.org/2009/watexy-test-with-edit-and-working-and/

    Thanks for your suggestions!

  7. Mikkel Meyer Andersen Says:

    It maybe would be a possibility to convert the Latex code to MathML instead. I'll give it a thought.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.