Scienco.org » Blog Archive » Watexy – Latex robot for Google Wave

Watexy - Latex robot for Google Wave

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

I finally got access to a Google Wave sandbox account, making it possible to start experimenting. The first thing I made was a Latex robot. By adding the robot, it's possible to write Latex in Waves. Afterwards, simply by putting Latex between two $'s:

<span style=\lim_{n \to \infty} \frac{1}{n} = 0$$

Watexy then changes the Wave and inserts the Latex as an image instead of the text.

You can try it yourself by adding watexy [this-funny-curly-a] appspot.com to your Wave-conversations. You can download the source here.

There's still a quite big bug: It's only the first Latex-image that gets substituted correctly. The following gets inserted some positions wrong, and the deletion of the text isn't correct neither. But the images itself are correct, only the substitution isn't working properly. But I'm working on that!

The more technical part: the robot is written in Python, hence using the Google Wave Python API. It's the first time I've tried that (thought it was a good possibility to learn it). The robot basically works by getting triggered when a new blip is submitted. Then it searches for Latex-code in that and substitutes it with pictures. Although the code is quite simple, it shows some very basic concepts on how to alter/change the contents of Waves on-the-fly (deleting text and inserting images, but it could be other things as well) with robots. The Latex-source-to-image is done by the http://www.forkosh.dreamhost.com/source_mathtex.html#webservice service.

The core Python comprising the robot is this:

# 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
 
""" 
Known bugs:
- From (and including) the second Latex-fragment, the positioning gets wrong
  > Probably the document needs some kind of updatering
  > Even though it's a bit strange since the re matches all the Latex correctly
"""  
 
__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. This robot uses the http://www.forkosh.dreamhost.com/source_mathtex.html#webservice service.)
 
def OnBlipSubmitted(properties, context):
  """Invoked when a blip has been added."""
  blip = context.GetBlipById(properties['blipId']) 
  blip_text_view = blip.GetDocument()
 
  latex_regex = re.compile('\$\$(.+?)\$\$')
  m = latex_regex.search(blip_text_view.GetText())
 
  """ 
  Only replace one Latex-fragment at a time, because replaceing one fragment
  changes the text positions in the rest. That's why re.finditer isn't used.  
  """
  while m != None:
    """
    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://www.forkosh.dreamhost.com/mathtex.cgi?' + m.group(1), caption=m.group(1))
    blip_text_view.InsertElement(m.start(1)-2, image)    
    m = latex_regex.search(blip_text_view.GetText())
 
if __name__ == '__main__':
  myRobot = robot.Robot('watexy', 
      image_url='http://watexy.appspot.com/assets/icon.png',
      version='9',
      profile_url='http://watexy.appspot.com/')  
  myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded)
  myRobot.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSubmitted)
  myRobot.Run()

39 Responses

  1. Mikkel Meyer Andersen Says:

    A live-demo is available at:
    https://wave.google.com/a/wavesandbox.com/#restored:wave:wavesandbox.com!w%252BnW6AFIIa%2525A

  2. Mikkel Meyer Andersen Says:

    Well, you have to copy the entire URL - for some reason WordPress apparantly doesn't think ! is valid in a URL.

  3. .yankee Says:

    If you added linefeed and caret return to the regex, wouldn't it work with multi-line entries as well? That'd be very useful for matrices for example.

  4. Mikkel Meyer Andersen Says:

    Yes, if the LaTeX-webservice supports it. But I'll give it a try. Thanks!

  5. Mikkel Meyer Andersen Says:

    I'll also change the way the robot introduces itself so that the waves doesn't get too messy/spammed.

  6. Google Wave Blogger Says:

    Tried it out. Cool Robot. Good work!

    Your invited to join our forums at http://www.googlewaveblogger.com and share your development efforts. I then blog about the developers that have joined the forums.

    Cheers! Good luck with the work.

  7. Gustav Delius Says:

    The robot works well. Are you planning to develop it further? For example it would be even nicer if it could show the original LaTeX source when I am editing a blip.

  8. Mikkel Meyer Andersen Says:

    Hi Gustav. Thanks. Yes, I am planning to develop it further, but have been really busy the last couple of weeks, but hopefully I'll find the time very soon :) .

  9. Nathan Triplett Says:

    This is great, I'm going to have to give it a go soon. If you'll allow me to share my dream LaTeX plug-in, perhaps it will inspire someone.

    First start off with your robot.

    Now let your robot help me when I'm confused. Say I type in helpme or something.

    Then I'd love it to do something like this:
    http://detexify.kirelabs.org/classify.html

    While just having it link me to that site would be ok, in my dream I imagine that it would include a drawing pad into the wave. Then let me draw a symbol. And then I could click the one I like and it would include the correct LaTeX for me.

    /dream

    Cheers and thanks for the plug-in

  10. AcidFlask Says:

    Try http://chart.apis.google.com/chart?cht=tx&chs=1x0&chf=bg,s,FFFFFF00&chco=000000&chl=$$ $$

    Someone on Reddit mentioned it.

  11. AcidFlask Says:

    I mean,

    http://www.reddit.com/r/math/comments/9pxpm/looks_like_google_docs_added_latex_support/

  12. alejandro Says:

    Hi,
    I like your bot. If there is one major thing it needs its this. I'm frequently revising the LaTeX command and the bot deletes it. It would be great if it inserted the original command in small grey print so I can reuse it. alejandro.erickson googlewave.com

  13. Jonathan Hunt Says:

    Hi,

    I've made a similar robot, but also an Equation gadget to go with it, this means rather than replacing the equations with images, I replace them with an editable gadget. I'd be keen to collaborate with others on making Wave more useful for scientists.

    If you have access to Wave preview you can learn more about the gadget/bot here:
    https://wave.google.com/wave/#restored:wave:googlewave.com!w%252B4muyQgqQR.2

    otherwise I will be putting more info up soon at http://waveyscience.appspot.com .

  14. Bry Says:

    Hi,

    I had some time to spare today and I decided to port the robot over to Java. I hope you don't mind. ;)

    I also added the grey out feature that some of the commenters here requested. It's a bit wonky due to the current state of wave, though.

  15. Fleischlego Says:

    I just thought about the advances of a bot like this in my car today.

    Amazing work, thank you!

  16. Dmitriy Says:

    Great robot. One thing that I'm really missing when using it is the ability to define my own commands (in the preamble). For instance, I like to give the symbols I commonly use short names (e.g. \newcommand{\Rsp}{\mathbb{R}}).

    Is it possible to add such an ability to watexy?

    I skimmed through the mathtex page, they clearly let one add \usepackage, but I don't know about \newcommand.

    Ideally, I think one could put commands into preamble within watexy's original response (or in reply to it), and they'd be used in all subsequent parsings.

  17. miniBill Says:

    THIS ROBOT ROCKS!!!

  18. Michael Says:

    Hi! Great robot!

    The 2 equations problem is a bit annoying, though. It is hard to write only one eq. per blip.

    Did you try to go through m in reverse order? Last to first? Then the positions of all the preceding equations will not be changed...

  19. Mikkel Meyer Andersen Says:

    Please notive the update at
    http://www.scienco.org/2009/watexy-version-12-now-supporting-multiple-equations-in-one-blip/

  20. Maarten Derickx Says:

    It would be nice to also have a version of watexy which behaves more like a latex editor.

    I.e, that watexy replies to your wave, and watexy updates it's reply as soon as you edit your original message. In this way you could use watexy really as a collaborative latex editing tool.

    Like watexy is now it's easy for in chat like an mail like usage. But the ability to be able to edit your latex code afterwards would really enable collaborative edditing.

  21. lostella Says:

    i agree with Maarten Derickx. also, will it say hello with that message every time i'm gonna add it to a wave? that would so boring

  22. Mikkel Meyer Andersen Says:

    Thanks for the comment, lostella. You're probably right. I better remove it, but because I'm travelling at the moment it'll take some weeks before it's done.

  23. Pablo Arias Says:

    Congratulations, great robot!!

    I have I suggestion. Has anyone though about having different waves for the source (.tex wave) and the compiled version of it (.dvi wave)?

    The latter could be read-only.

    Watexy as it is now is a great tool for discussion.

    However, if at a certain point you decide you want to write a proper latex document, you cannot do it in collaboration.

    Furthermore, now you can't reuse the wave to write a tex. At least not easily. Having access to the source would allow its reuse.

    I just throw the idea. Don't have any clue on its viability.

    Tanks for watexy!
    Pablo Arias

  24. Claus Says:

    Very nice bot! In order to be able to use the document which has been elaborated in the wave, it would be very nice to be able to export the text with the original latex code contained. The

    mode seems to store the original latex, so it should be quite easy to get the document with latex code out of the wave? (In order to run it with latex and pubish the paper for example) The bot could answer to a command with this complete text+latex code.

  25. Oyvind Says:

    Nice!

    $$ doesn't work for me, and the images aren't completely rendered always, but heck; wave isn't out yet :)

  26. Mikkel Meyer Andersen Says:

    That sounds a bit strange. I just checked it and the images showed up as usual. I haven't checked the actual $$ to image conversion, but I haven't change anything. But maybe Wave have been updated and bugs have been introduced. It's certainly been seen before. Let's give it some time.

  27. Domenico Says:

    First of all, thanks for your work. I have tosay that I have the
    same problem here too. Formulas between  don't show at all and these in ! only show as missing picture icons.

  28. More on open notebooks « Semantic Werks Says:

    [...] agents/bots and arbitrary Javascript extensions is more useful. For example, someone has written ‘Watexy’, a Wave bot which can interpret Latex [...]

  29. Jeff Gray Says:

    This is a really neat robot. We're trying to use this in class to post homework solutions. It's wonderful to have real equations in the text. And students can comment or even correct the solutions which is fun.

    However, we're having a lot of trouble with images not being rendered. There seem to be some serious bugs in the current version. Images show up as lines, and I have to double-click on them to get the edit box and then the rendering is shown. I know the students are going to complain (and blame me!).

    Am I doing something wrong? Are there any bot updates / bugfixes to correct this?

    Thanks again for your effort with this important project.

  30. Mikkel Meyer Andersen Says:

    Thanks. I'm sorry for the trouble. It seems like the server can't always cope with the pressure, although I'm not entirely sure that's the real problem. The reason is that right now Wave doesn't allow robots to attach images inline in waves, hence the wave has to get the image from the server every single time. This is not optimal - not at all - but it's the only solution for now.

    Another solution is to use MathML, and I'm also working on that. But for know it's really not that supported, so I'm not planning on releasing anything shortly.

    The problem with you having to click the image can be caused by two things: either it's simply not generated (which I don't think is the case, because then you probably wouldn't be able to see it when editing), or wave's auto-height adjusting is terrible (sorry, Google). As far as I have experience, it's only an issue with block math, so maybe try with inlining equations (although it doesn't give you the possibility to edit, again because Waves doesn't support inline Gadgets).

    So there's still som bugs, but as you can read, I believe that the most is caused by Google :-) .

    Please keep commenting and posting experiences!

  31. Jeff Gray Says:

    Thanks for the reply. Let us know if there's any way we can pressure Google to address this.

    I like the MathML idea--would this give us real fonts rather than images? That would be much nicer on the eyes.

    The LaTeX input form is wonderful and I think the best solution for writing equations.

    Would cut-and-paste from the Word equation editor ever be possible? Seems like that could be encoded in MathML. Its LaTeX-like entry and immediate conversion to math fonts is wonderful and might be a goal to strive toward with this package.

    Thanks again.

  32. Mikkel Meyer Andersen Says:

    Yes, I'll do that. Thanks.

    Yes, that is what MathML would mean. You can take a look at e.g. http://en.wikipedia.org/wiki/MathML . But the downside is that additional fonts is required to be installed for MathML to work.

    Regarding c'n'p from Word, I'm not sure. I actually haven't thought about it before you mention it. I'll keep it in my mind, but it's a low priority if it's even possible.

  33. Jeff Gray Says:

    Hi Mikkel,

    We are experiencing even more trouble today. Perhaps we just have too much watexy content on one page?

    Would you consider examining our page to see how we are using it and see if you can identify why the robot is being crazy?

    My wave account is jeffreyjgray@googlewave.com -- or email me at jgray@jhu.edu and I can invite you to the wave with our homework solutions.

    I would appreciate any insight you could offer. It's really important for us to have equations in this document and the wave+watexy seemed like a great way to do it, but at this point the problems are making it very difficult for us.

    Thank you for considering the help.

    Jeff

  34. Lerngruppe 2.0 » Das Uni Blog Says:

    [...] Durch Plugins bzw. Extensions lassen sich sogar Mathematische Formeln einfügen und bearbeiten (Watexy). Besonders in der Phase der Prüfungsvorbereitung haben wir gute Erfahrungen damit gemacht. So [...]

  35. Konstantin Ardakov Says:

    Hi there,

    Thanks for writing your Watexy robot - I'm already using it for collaborating with my colleagues.

    If I might may a small request/suggestion --- would it be possible to make inline TeX formulas (thus those invoked using  ) appear slightly lower in the line? They look a bit out of place at the moment.

    Thanks again,

    Konstantin

  36. Collaborative work with LaTeX « The Lumber Room Says:

    [...] Update [2009-10-03]: Some other things worth a mention: online LaTeX editors like MonkeyTex (but no one really likes editing in anything other than their familiar environment), a page at Wikibooks based on one of the PracTeX articles mentioned above, and, coming Real Soon Now, support for LaTeX in Google Wave.(link.) [...]

  37. Eddy Parkinson Says:

    There is a LaTeX and Google docs - online viewer, pdf compiler, editor

    http://docs.latexlab.org

  38. Mikkel Meyer Andersen Says:

    Thanks for the link!

  39. SynBioWave: Google Wave extension for synthetic biology | Abhishek Tiwari Says:

    [...] Watexy- A Google wave robot for Latex writing (watexy@appspot.com) [...]

Leave a Comment

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