views:

220

answers:

2

I want to display LaTeX math in the gmail messages that I receive, so that for example $\mathbb P^2$ would show as a nice formula. Now, there are several Javascripts available (for example, this one, or MathJax which would do the job, I just need to call them at the right time to manipulate the gmail message.

I know that this is possible to do in "basic HTML" and "print" views. Is it possible to do in the standard Gmail view? I tried to insert a call to the javascript right before the "canvas_frame" iframe, but that did not work.

My suspicion is that manipulating a Gmail message by any Javascript would be a major security flaw (think of all the malicious links one could insert) and that Google does everything to prevent this. And so the answer to my question is probably 'no'. Am I right in this?

Of course, it would be very easy for Google to implement viewing of LaTeX and MathML math simply by using MathJax on their servers. I made the corresponding Gmail Lab request, but no answer, and no interest from Google apparently.

So, again: is this possible to do without Google's cooperation, on the client side?

+1  A: 

Well, there are already greasemonkey scripts that do things to GMail as far as i know (like this one). Is this a possible security hole? Of course, anything you'd do with executable code has that risk. Google seems to move a glacial speeds on things they're not interested in. They really do seem to function based on internal championing of ideas, so best way forward is to go find sympathetic googlers, if you want them to include something into GMail. Otherwise stick to Greasemonkey, at least you'll have an easy install path for other people who'd like to see the same functionality.

knowtheory
There are no greasemonkey scripts that I know of that would *work on the body of the message.*
saturn
+3  A: 

I think one of the better ways to do this might be to embed images using the Google Charts API.

<img src="http://chart.apis.google.com/chart?cht=tx&amp;chl=x=\frac{-b%20\pm%20\sqrt{b^2-4ac}}{2a}"&gt;

To Learn more: http://code.google.com/apis/chart/docs/gallery/formulas.html

If you really must use LaTeX and some js library, I think one way you could accomplish this is by injecting a script tag into the iframe. I hope this is a good starting point.

Example:

// ==UserScript==
// @name           Test Gmail Alterations
// @version        1
// @author         Justen
// @description    Test Alter Email
// @include        https://mail.google.com/mail/*
// @include        http://mail.google.com/mail/*
// @license        GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==
(function GmailIframeInject() {

    GM_log('Starting GMail iFrame Injection');
    var GmailCode = function() {
        // Your code here;
        // The ':pd' (div id) changes, so you might have to do some extra work
        var mail = document.getElementById(':pd');
        mail.innerHTML = '<h1>Hello, World!</h1>';
    };

    var iframe = document.getElementById('canvas_frame');
    var doc = null;
    if( iframe ) {
        GM_log('Got iFrame');
        doc = iframe.contentDocument;
    } else {
        GM_log('ERROR: Could not get iframe with id canvas_frame');
        return
    }

    if( doc ) {
        GM_log('Injecting GmailCode');
        var code = "(" + GmailCode + ")();"
        doc.body.appendChild(doc.createElement('script')).innerHTML=code;
    } else {
        GM_log('ERROR: Could not get iframe content document');
        return;
    }
})();
Justen
I tested it. At first, I saw nothing. After inserting some alert(), the "Hello World" did appear. This must be a timing issue. My javascript did not work on the message, though. Again, this must be an issue of timing, or the order of execution. But great job, anyway! This is the first time I see a script doing something to a Gmail message.
saturn