-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Options to choose different LaTeX rendering services (p.e. with svg output) and offline conversion with MathJax #144
Comments
+1 for MathJax rendering support. |
I think it is possible only by using svg, the "usual way" is certainly not supported by Gmail and family. |
So there is no way of using Mathjax in GMail with web fonts or utf characters (like here) instead of images. Is that true? |
Well, actually I am not sure, but when I see HTML-with-CSS to lay out the mathematics I ever think that probably there will be some problems with the email providers. I said svg because it should be the easy way. |
I've been fooling around with this a bit, but I haven't found a solution I'm very happy with. I'll note what I've found below. Note that I've only tested with Gmail-in-Chrome and Thunderbird. Also note that I'm not a math guy and I don't really know much about LaTeX/TeX, SVG, Mathjax, etc. SVG images loaded remotely seem to work fineThat means you can have SVG math by setting this in Markdown Here's math option:
There are at least a few shortcomings with this, mostly privacy related:
And to repeat: I haven't tested anywhere else. Inline SVG does not workGmail-web strips it out before sending and won't render it if it receives it. With Tbird you can't actually see it in the compose window after rendering, but it does send and you can see it after receiving it. For the record, here's the SVG I used (just a
Here's a pretty comprehensive test of SVG in various email clients: http://conference.createsend.com/screens/r/06A83737A07C505E. Mixed results, but not good enough. SVG as
|
Forgot to add... Non-email considerationsMarkdown Here is used (with varying degrees of success) in more places than just email. What about SVG support in Google Groups, Evernote, Blogger, TinyMCE, etc.? If the target supports it, we could think about rendering directly to |
Pretty comprehensive explanation. Thank you, |
If Codecogs is fine, then does |
For what regards me, it is enough. Alex |
Very good summary of the current state of the different options, Adam. |
I added info about this to the Hints and Tips wiki page. Leaving this open as there's more in the original issue to think about and discuss. |
[The following is long and includes ideas that might be too much work for Markdown Here; I'm just doing a brain dump on how pretty math could be sent in emails at all...] SVG is bad defaultAlas, when Gmail switched to proxying and transcoding all images (which is good for privacy), Oh, and there is no reliable way to fall back from SVG to something else if it's unsupported. Must leave Google chart APIBut a bigger problem with the google chart TeX api is that it's been deprecated since 2012 and is expected to stop working around April 2015, retroactively breaking all math using it for external images! So I think it's better to switch to something else like CodeCogs (with PNG) right now. I can't probe they're not evil but CodeCogs have been serving math around the web for ages, and GmailTeX uses them. In the long term, the healthiest option would be embedding the image with data: URI so the result doesn't depend on any external service (also loading should be faster). MathMLNot here yet — only works on most of Apple's stuff and Thunderbird. A reliable fallback to something else should be possible, so an ideal solution would employ it. Unicode/CSS "native" rendering of mathMathJax's current HTML+CSS output is highly non-portable but both KaTeX and MathJax's upcoming CommonHTML output a stable HTML.
That said, while we can't have perfect-looking HTML+CSS math in email, it's not hard to produce something more readable than plain text! Some would say even than PNGs. Bottom lineKudos to Mozilla and Apple for supporting practically everything above but that's not enough. AFAICT the only safe way to send math that everybody can view (up to image blocking) is still PNG :-( Unicode + HTML + CSS might be workable but there is no immediately usable implemetations. Improving PNGsIf we're stuck with PNG, could we make them suck less?
|
Great research and analysis, @cben . Thanks for that. Some notes...
I don't suppose Gmail's proxying of images will save the Chart API images after that API is dropped, eh? (Not that either answer helps us...)
Yeah. I'll do that now-ish.
I really wish we could figure this out... The Gmail web client uses I have tried and failed in the past to get Chrome pasting-from-clipboard working. Maybe if we reversed engineered the (minified, horrible) Gmail JS? Maybe there's a point where we could just stick in image bytes and they would end up in a Another possibility is using the Gmail API. Like... wait until the user clicks "Send", intercept it, and create a raw email and send it via the API? Sounds like a crap user experience (no more Undo Send, etc.). And a lot of work. Seriously: How do we trick Gmail into treating our images as if they were pasted?
I can't quite tell if you're saying it's sufficiently win-tastic or not. Is this a thing for us to look at more?
That reminded me of the crazy awesomeness that is Zalgo -- which is rendered well by Gmail. Someone (who isn't me) should use that for math stuff. But yeah, I hope the magical "Unicode + HTML + CSS" future comes soon. To quote myself, a year ago:
Maybe... not totally ridiculous? It allows you to be the master of the availability of your images. Instead of S3, use GDrive. Lots of work. I am pretty convinced by your "suck less" list. And your argument for CodeCogs over Google Chart API. |
It might be a fun excercise to write a browser extension "resurrecting"
Switching Mathjax to some "average" metrics for platform fonts shouldn't be But making CSS layout work across email readers will be a nightmare. I'm |
Also, I did some tests to confirm Gmail doesn't like data URI png images. Results: Still broken. The image shows fine during compose (I inserted via DOM inspector) and are not stripped on send, but are not shown when reading via gmail. ALT text does show in gmail. Connecting to gmail via thunderbird shows all data uri images fine. Raw mails: https://gist.github.com/cben/664583043a2af239fa9d |
On the CodeCogs front: I have exchanged a couple of emails with them, and it looks like they'll be fine with MDH using their API. (Just trying to nail down when it's okay to start.) |
I created a new issue for switching to CodeCogs: #261. I intend to do it in the next release. I also had a bad idea: Instead of creating image links to Google Charts or to CodeCogs, etc., create them to an intermediate service (that I run or the user themselves could run). That service would look at the requesting user agent (Gmail in Chrome? Thunderbird? Postbox? Evernote in Firefox?) and decide which rendering to provide (indicating format with mimetype). That way we wouldn't be restricted to the least common denominator -- instead we could return the optimal choice for each platform. (Would have to be an image, though. Not fancy MathJax JS stuff.) There are a bunch of really good reasons to not do this. 1) It adds another privacy compromise. 2) Running a server, bleh. 3) Figuring out and maintaining "optimal" choices. Can we even tell what is requesting? Thunderbird receiving: Accept-Language: en-US,en;q=0.5
Connect-Time: 1
Accept-Encoding: gzip, deflate
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Connection: close
X-Request-Id: e2462045-b85c-4373-bd89-b862dba58a81
Via: 1.1 vegur
Total-Route-Time: 0
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0
Host: requestb.in Gmail+Chrome composing: Accept-Language: en-US,en;q=0.8,ja;q=0.6,ko;q=0.4
Connect-Time: 3
Accept-Encoding: gzip, deflate, sdch
Accept: image/webp,*/*;q=0.8
Host: requestb.in
Dnt: 1
X-Request-Id: 45accc18-7244-406d-8905-9700f8914f3a
Via: 1.1 vegur
Total-Route-Time: 0
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36
Connection: close Gmail+Chrome receiving: Connect-Time: 3
Accept-Encoding: gzip,deflate
Host: requestb.in
X-Request-Id: c4259f01-10be-4686-87da-3078cc96ed1a
Via: 1.1 vegur
Total-Route-Time: 2
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko Firefox/11.0 (via ggpht.com GoogleImageProxy)
Connection: close Firefox+Yahoo receiving: Accept-Language: en-US,en;q=0.5
Total-Route-Time: 0
Accept-Encoding: gzip, deflate
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Connection: close
Dnt: 1
X-Request-Id: c393f6b0-5668-464b-997c-3a23ae16c175
Via: 1.1 vegur
Connect-Time: 0
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
Cookie: session=eyJyZWNlbnQiOlsiMWkxb3BkdzEiXX0.B-cuwQ.CQ511AR4VinZPLawrbKAJR_ig24
Host: requestb.in Chrome+Outlook.com receiving: Total-Route-Time: 0
Accept-Language: en-ca,en,en
Host: requestb.in
X-Request-Id: f8c9a26b-b823-4dd3-92da-8ebaf85a2287
Via: 1.1 vegur
Connect-Time: 2
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36
Connection: close Chrome+Evernote composing: Accept: image/webp,*/*;q=0.8
Total-Route-Time: 0
User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36
X-Request-Id: 3a95184f-68f6-47bf-9dcc-533a0bd2e446
Accept-Encoding: gzip, deflate, sdch
Connection: close
Via: 1.1 vegur
Dnt: 1
Host: requestb.in
Accept-Language: en-US,en;q=0.8,ja;q=0.6,ko;q=0.4
Connect-Time: 3 Well, that's not hopeful. Thunderbird is obvious from the user agent, Gmail-receiving (but not browser) is obvious from the Maybe there's some kind of overall fingerprint for each combination? Like, maybe Yahoo+Firefox has a set of headers and header values that can consistently distinguish it from the other services? Seems like a big, fragile hassle. I think I can safely put this idea out of my head. |
Yeah, sounds pretty painful.
What would be useful to vary in the response?
-
Format? Replacing PNG with SVG would be nice, and could be done sanely
if only clients mentioned SVG in the Accept: header.
Alas, they don’t, except for — I’m embarassed to say — IE:
https://bugzilla.mozilla.org/show_bug.cgi?id=824623#c9
-
Better resolution for high DPI (“retina”) clients? Nice but math is
relatively small and grey&white, sending the big image to everyone is
probably way simpler. IIUC the imgset / picture efforts, header negotiation
was never considered an option.
User-agent sniffing is I think insane unless you’re full-time maintainer of
a service dedicated to images, e.g.
http://blog.imgix.com/post/90838796454/webp-jpeg-xr-progressive-jpg-support-w-auto
…
|
Mostly for SVG vs. PNG. Yeah, not much gain for quite a bit of pain. Regarding retina clients: When replacing with CodeCogs, I plan on getting a higher DPI image and then explicitly setting the size on it. |
I revoke that statement. I can't figure out a way to satisfactorily size the higher DPI image (in a way that works everywhere). At least until/unless we have both inline and block math -- then the inline can be |
Let's have inline&block then :-) Anything I can help? Does |
Ah, perhaps I see what you mean: math should have different size depending on formula, e.g. How about interrogating the returned image size and scaling the em/ex height appropriately? |
Also, re-reading this thread notice MathML works not only in ThunderBird but also on iOS and Apple Mail! Perhaps MathML with PNG fallback is doable and sufficient. |
Configuring this actually works (only tested in Gmail in Chrome though): (testing .height instead of .naturalHeight because it’s more portable and It turns: header
|
Sorry, I hoped gmail rich text could survive into github, but it seems github took the text/plain version |
Epic investigation. I love when someone else goes down the rabbit hole. Your inline JS resize idea is great. A couple things, though:
The size variation is utterly bizarre. Any chance you want to post to the CodeCogs forum, suggesting that it's broken? In exchange for that effort, I'll offer you this data point and possible solution to our woes: If you render to GIF instead of PNG (so, But if you don't use Note that I have a plain letter Here it is without the Here's some more numeric evidence of wackiness (and a cool CodeCogs trick):
'a' is 20 vs. 22. 'c' is 20 vs. 47. What the hell. (I learned about the Recap: Inline GIF ftw. You should totally post to the CodeCogs forum, @cben. |
More I modified the test alphabet by adding the plain letter beside each math letter. With no (I fooled around with some other Tall letters -- like 't' and 'k' -- get worse, but the letters with "descenders" -- like 'j' and 'y' -- look a lot better. I think it's a net gain...? But barely. |
Regarding what I meant by "inline" and "block": I mean the former in the sense of "inline with normal text" and the latter to mean "standing by itself". (Say we had say I would be pretty comfortable forcing the inline math to (In theory, I suppose, the code could detect math that is by itself in a paragraph versus math that's in a paragraph with other text. Hmm. Seems like a lot of work, though.) (For the record, I never use the math feature, so it's all hypothetical to me. People who actually use it have more valuable opinions.) P.S. This is really the wrong issue for these discussions. But too late now... |
Oops. Will continue on #261. Will report on CodeCogs forum. |
1. Update `marked.js` to the latest release 2. After the update of `marked.js`, the customization made by @adam-p for math treatment is lost. Instead of adapting those, I decided to use Katex instead for math rendering. Note that this is not a generic solution and doesn't align perfectly with the goal of Markdown Here. See discussions such as adam-p#144 (comment)
So are we any closer these days to the HTML + CSS promised land? |
I'm going to close this issue. There's great info here that I'm sure we'll refer to in the future, but it's too sprawling. The landscape of TeX rendering (and what is supported in email) hasn't really changed much since we started this conversation, unfortunately. On the other hand, there's a glimmer of hope for client-side rendering. Follow #874 for that. |
Hi,
I would like to suggest some enhancements to the LaTeX section.
It works pretty well and the output is in svg format.
$ ... $
and$$ ... $$
for the centred environmentand pure LaTeX delimiters as
\( ... )\
and\[ ... \]
for the centred environmentI have seen something interesting on MathJax's Website especially with the configuration
TeX-AMS-MML_SVG.js
Thank You,
Alex
The text was updated successfully, but these errors were encountered: