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:
$$\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()

July 31st, 2009 at 01:16 (UTC)
A live-demo is available at:
https://wave.google.com/a/wavesandbox.com/#restored:wave:wavesandbox.com!w%252BnW6AFIIa%2525A
July 31st, 2009 at 01:17 (UTC)
Well, you have to copy the entire URL – for some reason WordPress apparantly doesn’t think ! is valid in a URL.
August 2nd, 2009 at 15:49 (UTC)
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.
August 2nd, 2009 at 22:35 (UTC)
Yes, if the LaTeX-webservice supports it. But I’ll give it a try. Thanks!
August 10th, 2009 at 08:07 (UTC)
I’ll also change the way the robot introduces itself so that the waves doesn’t get too messy/spammed.
September 18th, 2009 at 19:30 (UTC)
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.
October 1st, 2009 at 14:21 (UTC)
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.
October 4th, 2009 at 22:41 (UTC)
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
.
October 6th, 2009 at 21:20 (UTC)
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
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
October 10th, 2009 at 04:21 (UTC)
Try http://chart.apis.google.com/chart?cht=tx&chs=1×0&chf=bg,s,FFFFFF00&chco=000000&chl=
Someone on Reddit mentioned it.
October 10th, 2009 at 04:26 (UTC)
I mean,
http://www.reddit.com/r/math/comments/9pxpm/looks_like_google_docs_added_latex_support/
October 11th, 2009 at 03:08 (UTC)
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
October 13th, 2009 at 14:00 (UTC)
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 .
October 13th, 2009 at 15:47 (UTC)
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.
October 23rd, 2009 at 20:44 (UTC)
I just thought about the advances of a bot like this in my car today.
Amazing work, thank you!
October 28th, 2009 at 06:10 (UTC)
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.
November 9th, 2009 at 18:09 (UTC)
THIS ROBOT ROCKS!!!
November 10th, 2009 at 18:48 (UTC)
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…
November 11th, 2009 at 00:03 (UTC)
Please notive the update at
http://www.scienco.org/2009/watexy-version-12-now-supporting-multiple-equations-in-one-blip/
November 20th, 2009 at 17:18 (UTC)
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.
December 1st, 2009 at 22:56 (UTC)
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
December 2nd, 2009 at 06:56 (UTC)
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.
December 2nd, 2009 at 19:23 (UTC)
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
December 4th, 2009 at 10:24 (UTC)
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.
December 9th, 2009 at 21:47 (UTC)
Nice!
$$ doesn’t work for me, and the images aren’t completely rendered always, but heck; wave isn’t out yet
December 10th, 2009 at 02:38 (UTC)
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.
December 10th, 2009 at 08:07 (UTC)
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.