Math formulas in emails

Is there a way to enter LaTeX (or similar) formulas into an E-Mail and get them rendered as typeset formulas on the receiving side, perhaps with cooperation of the receiving party? My preferred mail client is Thunderbird, but solutions for other applications might be of interest as well, and portable solutions obviously would work best.

Things I'm hoping for but couldn't find so far:

• A way to reference the MathJax JavaScript files from within a HTML E-Mail, together with a configuration on the client side which allows execution of this particular JavaScript without opening too much of a security hole.
• Some add-on which enables MathJax on the receiving side, without any particular reference to it in the E-Mail. This might work even for plain text messages, which is a good thing.
• Some add-on which alloes the user to enter LaTeX code somewhere, and which embeds the corresponding MathML into a HTML-formatted message.
• Some add-on which allows me to mark part of my message before clicking a button. The marked text should then be interpreted as LaTeX and be replaced by the corresponding MathML. Obviously this will only work for HTML-formatted messages, too.

I'm interested in any known procedures along the lines above. In cases where not immediately obvious, information as to which applications on the sending as well as on the receiving side support this approach would be welcome. For example, I have heard that both Thunderbird and Apple Mail will support MathML for received mails, but Outlook will not. At least the part about Thunderbird rendering the formula I can confirm.

-
There are plugins for Miranda and Kopete, both chat applications, which are sort of doing, what you are looking for. –  ernestopheles Jan 15 '13 at 15:10
Is it important for the equation to survive as editable text on the recipient's end? I mean, there are plug-ins like LaTeX It! that let you send LaTeX as images. –  Dane Jan 15 '13 at 17:38
@Dane, maintaining editability isn't crucial. So LaTeX It! would be an option, although the font of the image tends to fit in rather poorly with the remainder of the email. –  MvG Jan 15 '13 at 22:45

As far as I know, there's currently nothing that quite does what you want.

Putting javascript in an email would be a really bad idea in general but the MathJax bookmarklet might help with webclients. You could use it on your webclient before sending off an email but I wouldn't suggest this -- MathJax rendering depends on the browser so this will often break on the recipient's side; it will also make it hard to re-use the mathematical content.

I think MathML will become the exchange format of choice in the future (hopefully with embedded source data like LaTeX to be able to continue authoring with it). Many equation editors produce MathML, but those with LaTeX-input and MathML-output are rare.

Frederic Wang's recent blog post is probably the best (only?) source for now when it comes to MathML support in email clients -- in particular comment 5. Fred is a contributor to Firefox's MathML implementation and is part of the MathJax team (disclaimer: as am I).

-

The practical problem is striking a balance between good experience for cooperating receiving party yet not being entirely broken for non-cooperating parties. Remember that emails may be retained for many years, read via multiple programs, and forwarded to other people.

• Currently I believe TeX for Gmail does this best — notably it lets you to render plain text formulas like $2^n$ or even (heuristically) 2^n in incoming mail which is great during back-and-forth with a person using other software.

• Markdown Here is not as flexible math-wise but also does other markdown formatting and works in many more places.

• This form on Murray Bourne's IntMath site requires you to send from it instead of your regular mail client, and uses ASCIIMathML instead of TeX notation (easier but but has the nice feature of letting the recipient view the mail in a browser - and reply there.

On a technical level, the only way to display wide range of formulas to any client (except pure-text ones) seems to be PNG images. Doing it right ought to include:

• alt text fallback.
• embedding image in mail so it's self-contained and doesn't depend on external servers. data URIs have bad support, multipart with cid: much better (see comments there).
• using high-resolution image that doesn't look horrible on high-DPI screen.
• setting height, width and vertical-align in ex units. This should be able to match size and baseline to surrounding text.

Getting all of the above to work accross clients is tricky... For example see Markdown Here's troubles.

There are multiple better ways to render math than PNG. The problem with all of them is how to fall back to image (or even text) when they don't work?

• Some simple subset of math can be rendered well with unicode+HTML+CSS. Indeed TeX for Gmail has such a mode. KaTeX raised the bar for high-quality pure CSS rendering, except it relies on webfonts which don't work in almost mail client. MathJax 2.5 has has a "CommonHTML" mode which currently uses CSS+HTML without even webfonts, but it looks ugly (they plan to start using webfonts to make prettier)...

In any case, CSS in email clients is way behind browsers and horrifyingly uneven, so complex math layouts won't work.

• MathML is great and semantically the Right Thing and even works in some clients; alas fallback to images seems hard. Of the official fallback mechanisms, even Chrome only got half in 2014 (thanks Fred Wand), so what can one expect from email clients?

• OK MathML is complex and niche format, but surely SVG ought to be a no-brainer after ~15 years in existence? Alas, email SVG support is very sad (e.g. gmail recently dropped all support, not even alt text), and the known javascript-free fallback techniques don't work on email. (I don't consider testing for screen resolution == iPhone|iPad an acceptable technique...)

The cleanest fallback techniques rely on clients ignoring tags they don't understand; alas quiet a few (web)mail clients only accept a whitelist of tags and completely drop things like $...<img .../>...$ instead of rendering the img...

As for doing these without fallback, so recipient can't read math at all without the right tool — it's a tough call (compared to PNG which is uglier but works) but maybe acceptable to you.
[Actually there is always the option to include text/plain fallback. Not all receiving clients expose it, and starting the mail with "Can't see math? Look for "Show original" in your email client" would be a lousy experience...