GmailTeX is a plugin which adds (La)TeX capability to Gmail and Gmail Chat.

GmailTeX is not associated with Google in any way. It is written by a volunteer in his spare time. For many years, Google has not responded to numerous pleadings from scientifically minded Gmail users for a similar solution. This may be too small of a niche for them.

GmailTeX uses MathJax as a TeX typesetting engine for received emails, and CodeCogs for creating web-hosted images in the outgoing emails (with permission).

Sever down issues: If you consistently get the Wrong equation image or a rotaing green circle when composing an email, this may mean that the CodeCogs LaTeX server is down, and no new equations are generated. (The already generated equations are kept in a cache and continue to be served for several months.) You can verify if that is the case by going to the server's web page and entering your equation there. I have no control over that server.

March 15, 2014

Current version: 5.15.6

  • 1.0, Jun 7, 2010: The initial release.

  • New in v.4.*: WYSIWYG (what you see is what you get) editing of outgoing messages. Your addressee does not have to have GmailTeX installed or use Gmail in order to view the math. Math is viewable in most mail readers and browsers, including mobile ones.

  • New in v.5*: also works with Chat. Also adds auto mode.

    v.5.9: fixed the links to math images broken by Google's proxy.

    v.5.10: visible actions, improvements in Simple Math.

    v.5.11: support for theorem-like environments.

    v 5.12: better resolution for web images.

Installation

Usage

After clearing the browser cache and restarting Gmail, you should see the collapsible GmailTeX menu in the Gmail Navigation Bar on the left. (If you used the alternative installation, you need to click on the newly created Gmail bookmarklet first.) The menu should have the following items:

  • rich math (F8)
  • simple math (F9)
  • auto: off 1 2 4 8, rich / simple
  • help & about

Reading email


When you receive an email containing LaTeX-encoded math, hit the link simple math or rich math, or press F9, resp. F8. LaTeX in your emails will be transformed into something more readable (only temporarily, until you close the message).

For rich math to work, LaTeX must be properly enclosed in $...$ or $$...$$. For simple math, it does not have to be: the program will guess which part is math, and which part is not.

The simple math method only supports a subset of LaTeX (subscripts, superscripts, greek letters, \sqrt, \sum, \prod, \cap, \cup, etc.) and may not work on every input (after all, it is guessing). But it is useful when you receive an email with pseudo-LaTeX which is not enclosed in proper delimiters.

Sending email in "Rich format" mode


The easiest is to compose an email in Rich format. Hitting the link or rich math or pressing F8 will transform your LaTeX into images with equations.

To turn an image back into LaTeX, do the following: single-click the image to select it. Blue corners appear together with the options "Small", "Best fit", etc., to resize the image. Now double-click on one of the blue corners. That should turn the image back into LaTeX.

If you are composing using new Compose/Reply, make sure you are NOT in "Plain text mode"!

Hitting the link simple math or pressing F9 will transform your LaTeX into simple HTML with subscripts, superscripts, greek letters etc. Ctrl-Z works for "undo".

Exactly the same as for reading, for rich math to work, LaTeX must be properly enclosed in $...$ or $$...$$. For simple math, it does not have to be: the program will guess which part is math, and which part is not.

Occasionally, after hitting F9 you may have trouble exiting out of subscript or superscript mode. (Pro tip: putting a dot "." after a superscript or subscript before hitting F9 works well to avoid this problem.) If it happens, select the text that should not be subscripted or superscripted, and press the button "Remove Formatting" from Gmail HTML editor's toolbar.

Whichever method you use, your addressee does not need to have GmailTeX installed. The math should be directly viewable in most browsers, including mobile browsers.

Here are some things to consider when choosing between HTML or images in the outgoing emails:

  • simple math is just standard HTML, which any browser or email client can read, online or offline.
  • rich math means links to images hosted by CodeCogs on their server, and used in this app with their explicit permission. The images are not available offline, unless they have been cached by your computer.
  • If a server goes down or the service is discontinued (as Google's LaTeX engine is going to do soon), the images will no longer render.
  • The server at CodeCogs has a daily fair usage limit, currently 3,000 equations (per IP address?)

Note:

  1. Color works with F8. Try writing $\color{Red}{\mathbb C^n}$ and pressing F8 to get . Other available colors: Blue, Green, Yellow, Pink, Orange, Purple, Maroon, Teal.
  2. TeX accents work with F9. Try writing H\'el\`ene and pressing F9 to get Hélène.

Sending email in "Plain Text" mode


When composing in Plain Text mode, pressing F8 will open a preview window for your LaTeX (and Shift-F8 will close it). The email is sent out as is, without any modifications. To view math nicely typeset, your addressee also needs to have GmailTeX installed.

Now that there is a WYSIWYG way of sending emails, I may remove this method.

auto: off 1 2 4 8, rich / simple


Turning this on produces the following effect. When composing a message, math expressions properly enclosed in $...$, $$...$$, \(...\), or \[...\] will be automatically typeset. If the rich mode is chosen, they will be replaced by (links to) images. If the simple mode is chosen, they will be replaced by simple HTML.

Thus, this is roughly equivalent to pressing F8 or F9 every 1, 2, 4, or 8 seconds. But not quite. When you press F9, the whole text of the message is transformed, including math expressions and TeX accents not properly enclosed in $...$, etc. In the auto mode, only the expressions in $...$ etc. are affected.

A side note is that in the auto mode, when the simple mode is chosen, GmailTeX adds a blank space at the end of the formula. Otherwise, Gmail frequently gets stuck in the subscript or superscript mode. Once you know about this, with a little practice this should not be an inconvenience.

Novice LaTeX users may also find CodeCogs' Online LaTeX Equation Editor useful. The link is available at the bottom of GmailTeX's window. You can compose your formula there and then paste it in the Compose window.


Support for theorem-like environments

Writing

\begin{theorem}The equation $$x^n+y^n=z^n$$ has no solutions in positive integers x,y,z,n with $n\ge3$. \end{theorem}
produces
Theorem. The equation
xn+yn=zn
has no solutions in positive integers x,y,z,n with n≥3.   

Note that '\begin{theorem}...\end{theorem}' should not be enclosed in $$...$$. On the other hand, the usual math environments such as matrix, pmatrix, bmatrix, still work as before in Rich Math mode if they are properly enclosed in $$...$$.

There is an optional argument for the theme: red, blue, green, gray, yellow (default). For example, writing

\begin{theorem}{green}The equation $$x^n+y^n=z^n$$ has no solutions in positive integers x,y,z,n with $n\ge3$. \end{theorem}
gives
Theorem. The equation
xn+yn=zn
has no solutions in positive integers x,y,z,n with n≥3.   

The optional argument can also be used to add any legal CSS. In particular, for the color names you can use something like #FFFFF0 or rgb(248,248,248), or named colors. See also this page for a large database of colors. For example,
\begin{theorem}{background: pink; border: 2px solid crimson;
font-family: 'Times New Roman'; font-size: 120%; border-radius:2ex}The equation $x^n+y^n=z^n$
has no solutions  in positive integers x,y,z,n with $n\ge3$.
\end{theorem} 
gives
Theorem. The equation
xn+yn=zn
has no solutions  in positive integers x,y,z,n with n≥3.  

For a box without a title, use '\begin{} ... \end{}'. Works both in Simple and Rich modes.

If you need to insert a line break inside an environment, do not press ENTER, since it performs a complicated function in Gmail Compose Box, with various side effects. Press SHIFT-ENTER (in Chrome) or CTRL-ENTER (in Safari) instead. There must be an equivalent in Firefox but I haven't figured it out. If things go wrong, you can use Gmail Undo (control-Z).


More formatting options

In addition, the main function of the Simple Math mode is to make any expression in $...$ into an HTML span. As a byproduct, most HTML constructions inside $...$ produce correctly-formatted HTML, e.g.

$<b>Bold</b>, $<i>Italic</i>, <del>Strike-through</del>$
give

Bold, Italic, Strike-through

when Simple Math mode is used. $<h2>Headers</h2>$ work, too. Also, $----$ (four or more) gives a horizontal line, $--$ gives an n-dash –, and $---$ an em-dash —. And of course TeX accents work, too: $H\'el\`ene$ gives Hélène.



Using LaTeX with Chat


Just include your math in $...$ or $$...$$. It should automatically show upon entering.

Tips

  • The following method works well when reading emails with a mixed math contents, some enclosed in $...$ and some not (for example daily arXiv emails). Press F8 and then in a couple of seconds F9. Both types of math content will be typeset.

  • If you need to reformat an old email message, for example a message with math images broken by Google proxy, you can do the following:

    Change to Rich Math, turn the auto mode off. Forward the message to yourself. In the Compose window, press F8 once. Now all math images are clickable. Turn them back to plain text following instructions here. They should turn back into TeX source. Now press F8 again. The formulas will be replaced with new images. Email the resulting message to yourself.

Troubleshooting

  • May 19, 2014: Double clicking on the images to turn them back into LaTeX used to work fine but now something is wrong. Oh well, Gmail changed their code again. See these instructions.

  • Sever down issues: If you consistently get the Wrong equation image when composing an email, this may mean that the CodeCogs LaTeX server is down, and no new equations are generated. (The already generated equations are kept in a cache and continue to be served for several months.) You can verify if that is the case by going to the server's web page and entering your equation there. I have no control over that server.

  • Dec. 7, 2013: Starting Dec 3, Gmail rewrites the web links to images in the incoming messages to point them to a proxy server googleusercontent.com, see this official explanation for the reasons behind this move.

    In any case, the Google proxy breaks the old links to math images. (For the curious: the blank spaces in the links, even encoded as '%20' are turned into '+', and latex.codecogs.com fails to understand them. Most links to math images contain blank spaces since they all start with 'inline%20' or 'display%20'.)

    The links generated by GmailTeX version ≥5.9 should work with Google proxy, at least until they decide to break something again. To read the old emails, you can press F8 which should fix the links. An alternative is to forward the emails to an non-Gmail account or read them in another mail reader, e.g. in Mac OSX native mail reader. Google only rewrites the links shown in Gmail itself.

    The SVG images do not work at all with the new Google proxy, so the option to create SVG images was removed in GmailTeX v.5.9; all the images are now in GIF. (Which could be for the best, since the SVG server on codecogs.com remains to be glitchy.)

  • I received reports that the GmailTeX addon for Firefox leads to multiple error messages in the new version 22 of Firefox, such as: "Illegal Operation on Wrapped native Object".
    Please note that I removed this addon from the Firefox addons store in October 2012, and it is no longer supported. The recommended way to use GmailTeX in Firefox is to install Greasemonkey and then a Greasemonkey userscript.
  • The new Hangouts interface for Google Chats broke the GmailTeX's functionality for Chats. I may try to update GmailTeX to address this in the future but I don't know when I will have time for this.
  • If you are upgrading from a previous version of GmailTex, you need to clear the cache and restart the browser, to make sure that the new version is loading.
  • If you used the alternative installation as a bookmarklet, and the control panel does not appear, try going to the http address in your bookmark manually, to make sure that it exists and that you have the necessary permissions to access it.
  • To typeset multiline equations, for example with a matrix or \cases: simply remove the linebreaks. GmailTeX is optimized to work with each text block separately, otherwise it would work much slower and would take up more resources. So it does not look across the line breaks.
  • If some formulas do not typeset correctly, switching from SVG to GIF output may fix it (The SVG engine at CodeCogs is glitchy.)

Privacy and security

GmailTeX, as written by me, does nothing beyond the basic functions explained in the Usage section above. It does not collect or send out any information about its users, does not make any XMLHttpRequests, and does not load any external code other than MathJax, and now also images from CodeCogs.

And of course GmailTeX is an open source human-readable Javascript program, so you can examine it yourself.

Beware of installing GmailTeX from anywhere but the sources listed in Installation. I uploaded GmailTeX to those sites myself. But I do not control any of the 3rd party web sites, such as Softpedia etc. and their content.

Thanks

  • To the MathJax project for providing a superb TeX typesetting engine.
  • To CodeCogs for providing the engine for images, and for hosting them.
  • To Kristi Tsukida for writing wrappers for a Chrome extension and Greasemonkey userscript.

About the author

My name is Valery Alexeev, and I am a mathematician at the University of Georgia. I wrote this program for myself, but I am releasing it here for free in the hope that it could be useful to others, mathematics students and researchers alike. For feedback or bug reports on GmailTeX, you may use this email.