# How do I see LaTeX math on any web page and in email?

This is a follow up to this closed question.

I open a random page, such as something on arXiv at 8:05 p.m. EST, and I see all these dollar signs, and I sigh and I wish that I could see nicely formatted math formulas instead, just like on MO. Is it possible? Can one write a Greasemonkey script to apply jsMath after the fact even if the page authors did not think of it? A Mozilla Firefox addon?

Please share your solutions. Seeing like this is an active community of people with similar interests, I am sure that hundreds or thousands of mathematicians would benefit from a solution.

-
I'm pretty sure the answer to (the denotative meaning of) each of your questions is "yes". What you actually mean to ask, of course, is for someone here to actually write such a script. I recommend that you revise your question to make it ask what you clearly mean to ask. I don't care for indirect speech acts. – Theo Johnson-Freyd Apr 22 '10 at 5:26
I said this before, and I'll say it again: take a look at the actual TeX in those abstracts. More often than not, it won't TeX! It often says things like "let \$E\$ be an elliptic curve and let \$\E\$ be an integral model of E. By \cite{BSD} we know that the..." . TeX will choke on \E and \cite{BSD}, because they rely on definitions made in the body of the MS, which the web page doesn't have access to. See my next comment for something more positive though. – Kevin Buzzard Apr 22 '10 at 10:38
Complaining about the MO thought police is rude and unhelpful. Your previous question was closed, and the reasons for closing were explained clearly. It seems they still apply here! Especially given that your question is implicitly asking others to do work for you, it might be more productive to show some effort, perhaps by linking to a question on StackOverflow you've just asked about how to deal with loading external libraries in GreaseMonkey. – Scott Morrison Apr 22 '10 at 17:08
Scott Morrison: (1) Rude? Maybe. It was rude to close my question. (2) Unhelpful? I beg to differ: now people have a chance to answer, and the solution would be VERY helpful to MANY people. (3) Am I asking others to do work for me? Isn't that what every MO question is about? I helped many people by answering their questions, why can't I get some help with what is not my area of expertise? – VA. Apr 22 '10 at 17:50
This question was asked on Stackoverflow two days ago. It gathered 53 views and one very short answer which is a dupe of the answer here. I think this proves that MO is the right place for it to (1) get the question answered and (2) disseminate the answers to the mathematicians who would benefit from them - almost none of them read Stackoverflow. – VA. Apr 25 '10 at 4:20

The Greasemonkey MathML script written by Steve Cheng and linked to in Scott Morrison's answer worked only partially for me in Firefox on Windows 7: it did not display many \mathbb, \mathcal, and \mathfrak characters because the corresponding Unicode characters were missing in the fonts. Installing additional STIX and Asana Math fonts did not help, in fact it made the display looking worse.

So I rewrote the script (a long and tedious job finding the correct Unicode codes and putting them in the right places). I also added arxiv.org, front.math.ucdavis.edu, MathSciNet, and mail.google.com to the sites supported by default, and added miscellaneous characters and TeX commands missing in the original script.

Yes, it works with gmail (!) if you switch to the basic HTML view. So now you can read an email from your collaborator and see typeset math right there. Now tell me you haven't always wished and prayed for this? I know I have.

Here are the detailed instructions for the method that produces good results using Mozilla Firefox on Windows 7. I haven't tested on other systems, you are welcome to share your experiences in the comments.

3. From the Firefox menu bar, File > Open File, navigate to the downloaded script and open it. Greasemonkey will offer to install it. Do that.

That should be it. Check how it works by looking at some arXiv abstracts such as this, or this.

Even when the authors use custom notations, such as \red or \cE, removing the dollar signs, putting math in a different font, and using sub- and superscripts dramatically increases the readability in my experience.

Edit: I also fixed the displayed formulas with double dollars, which the original script did not handle correctly. So now you can also view this and this.

So in the end this was more of a community service than a question. Enjoy the results!

-
@VA: I believe this is the most useful (in the practical sense) contribution to MathOverflow so far. Thank you for your persistence! – François G. Dorais Apr 28 '10 at 0:58
I say this not having voted to close on either question and mostly taking your side on the discussions concerning these posts in meta: It's important to keep in mind that the people who voted to close the original question did not necessarily want the question closed permanently, but instead thought that it needed to be changed in order to be an appropriate MO question. The idea (which has not been communicated well to users and which some of us disagree with) is that closing and then reopening questions after they're edited should be a normal part of the life-cycle here. – Noah Snyder Apr 28 '10 at 1:35
Noah: I was most upset by the fact that one participant took the challenge and volunteered to write an addon in a few days. But with the question closed and the incentives, such as they are here (the "points") gone, and no way to communicate the results (one can not add answers to a closed question), he apparently abandoned it. So that's anti-progress. Mine was the only voice to reopen for a month. So I had to post a new question. – VA. Apr 28 '10 at 2:08
@VA: Thanks! That fixes the problem. Incidentally, another website that you can consider supporting by default is ams.org/mathscinet/* (of course, users can add it themselves). Wonderful work. – Willie Wong Apr 28 '10 at 13:01
This is amazing. I had been a bit skeptical that it would be very useful in practice, but I was completely wrong. This script has already totally changed my experience of browsing MathSciNet. I recommend it to everyone -- try it out! Thanks very much for your work, VA. – Tom Church Apr 29 '10 at 5:06

I wrote a little program called GmailTeX which adds $\TeX$ capability to Gmail. You can get it here.

GmailTeX now includes the "live" fully automatic mode, just like when you type a question / answer on MO. (Actually, faster than the current MO math preview.)

Added 9/1/2010: Thanks to Kristi Tsukida, it is now available as a Firefox greasemonkey script and as a Google Chrome extension, for easy installation.

-

By now, I am aware of three ways to accomplish this:

1. MathJax.
2. display-latex2 described in the other answer (written by Steve Cheng, to which I made some modifications).
3. ASCIIMathML, written by Peter Jipsen.

I think the best choice by far is to use MathJax, an active project with a very professional development team. It is free, open source, and it is backed by the American Mathematical Society, the American Physical Society, and SIAM, among others. That is the way to go, if you are able to install it on your server.

(In the previous version of this answer, I mentioned several problems. They were very promptly resolved by the developers, who are truly impressive, and whom I can not praise enough.)

I wrote a very simple Greasemonkey script which allows you to use your local installation of MathJax on any web page, and in Gmail (in "basic HTML" and "print" views).

The same web page also contains a Greasemonkey script allowing you to pick and choose between the three locally installed math engines.

In the long run, the best way would be for arXiv, MathSciNet, and Gmail to use MathJax on their servers. I made a Gmail Lab request for this. If more people support it, maybe they will do it, that would be great.

Here are detailed instructions. I am hesitant to bump this question too often. So for minor edits I will update this web site instead.

## Installation instructions

This solution assumes that you have access to a web server and can install Javascript programs on it.

First, download and install MathJax and MathJax web fonts. Install MathJax on your web server. Install the MathJax fonts from the MathJax-webfonts(-beta2)/fonts/HTML-CSS/TeX/otf directory.

The customization is done by editing the file MathJax/config/MathJax.js. You need to set

webFont: null,


so that MathJax uses your locally installed MathJax TeX fonts. Next, download mathjaxthispage.user.js and save it to your Desktop. The script assumes that your MathJax installation resides in http://localhost/MathJax. If it is different, edit the script accordingly. From the Firefox menu bar, File > Open File, navigate to the downloaded script and open it. Greasemonkey will offer to install; do that. Start surfing.

### Muting the TeX errors (optional)

The following settings make for a more pleasant viewing experience when browsing the pages with non-standard TeX macros, for example arXiv.org.

extensions: ["tex2jax.js", "TeX/noErrors.js", "TeX/noUndefined.js"],

and inside the TeX block, the following code

TeX: {

       noErrors: {
inlineDelimiters: ["",""],
multiLine: false,
style: {
"font-family": "serif",
"font-size":   "120%",
"color":       "gray",
"border":      ""
}
},

noUndefined: {
attributes: {
mathcolor: "red",
mathbackground: "#FFEEEE",
mathsize: "100%"
}
},


// The rest follows...

If you don't have the extensions noErrors.js and noUndefined.js in your MathJax/extensions directory, you can get them from a more recent build available at https://sourceforge.net/projects/mathjax/develop

### Using the native MathMML output (optional)

With Mozilla Firefox, you have an option of using the native MathMML instead of HTML-CSS output, which is faster. For this, you will need to set the following in MathJax/config/MathJax.js :

jax: ["input/TeX","output/NativeMML"],

math { font-size: 112% } [mathvariant="double-struck"] {font-family: MathJax_AMS; } [mathvariant="script"] {font-family: MathJax_Script; } [mathvariant="fraktur"] {font-family: MathJax_Fraktur;} [mathvariant="-tex-caligraphic"] {font-family: MathJax_Caligraphic; } [mathvariant="bold-script"] {font-family: MathJax_Script; font-weight: bold;} [mathvariant="bold-fraktur"] {font-family: MathJax_Fraktur; font-weight: bold;} [mathvariant="monospace"]{font-family: monospace}

The first line controls the magnification of math output, and you can change it to your liking. The other lines are needed to fix a bug with Mozilla's display (otherwise, Mozilla does not display MathML correctly).

For font consistency, you could also type 'about:config' (without the quotes) in the location bar, and change the variable font.mathfont-family to

MathJax_Main, MathJax_Math, MathJax_Size1, MathJax_Size2, MathJax_Size3, MathJax_Typewritter, MathJax_AMS, MathJax_Caligraphic, MathJax_Fraktur, MathJax_SansSerif

-

In fact, this question has previously been answered on MathOverflow. There's a Greasemonkey script here, which does not in fact use jsMath, but rather produces MathML directly, and leaves it to the browser to render. I haven't tried using it, so I don't know the extent of its LaTeX support.

-
That actually works. No cut and paste, and not even a button to press, all automatic. – VA. Apr 22 '10 at 21:22
The output is not as nice as jsMath, though. – VA. Apr 22 '10 at 22:48

Yes, it is clearly possible to write a GreaseMonkey script that loads the jsMath library, then calls the appropriate code.

In fact, you can easily look up the appropriate function call to re-render a page using jsMath, by inspecting the "(Re)process math" element on this page. For your convenience:

<a onclick="jsMath.ConvertTeX();jsMath.Process(document);">(Re)process math</a>


You might also look at this description of building a GreaseMonkey script that loads an external library. It seems sufficiently complicated (waiting to ensure the library has loaded before calling it) that I'm not interested in the details.

-
I tried to fiddle around with simpler versions of this: Greasemonkey inserting appropriate <SCRIPT> tags. Unfortunately this will probably not work with jsMath, as the author himself on the webpage states that jsMath will not work if it is called from a different domain than the one it is installed on. Also, Firefox doesn't allow inserting of local scripts. I really hope Mathscinet will install jsMath soon. (yes I am too lazy to click on "PDF" :)) – Lars Apr 23 '10 at 11:03

Here's a solution that is easy and doesn't require you to install Greasemonkey (in particular, you can use it with Chrome), but is quite crufty. Visit a page with math on it (like this arXiv abstract), paste the following into the location bar of your browser and hit enter:

javascript:var e=document.createElement("script");e.type="text/javascript";e.src="http://www.mathjax.org/MathJax/MathJax.js";document.getElementsByTagName('head')[0].appendChild(e);setTimeout(function(){MathJax.Hub.Config({config:["MMLorHTML.js"],extensions:["tex2jax.js","TeX/noErrors.js"],tex2jax:{inlineMath:[["$","$"],["$","$"]]},jax: ["input/TeX"],MMLorHTML:{prefer:"MML"}});MathJax.Extension.tex2jax.PreProcess(document);MathJax.Hub.Process(document);},300);void(0);


If that worked, create a new bookmark in your browser with the above line as the "location". When you come to a page where you want to process the math, just click on the bookmark.

Edit(VA): Please consider installing MathJax locally. You don't want to cost the MathJax organization bandwidth. And with a local installation, you are fully in control, and can configure MathJax in a local configuration file. In that case, you can use a shorter bookmarklet (replace 'localhost' by your server):

  javascript:
var e=document.createElement("script");
e.type="text/javascript";
e.src="http://localhost/MathJax/MathJax.js";
setTimeout(function(){
MathJax.Extension.tex2jax.PreProcess(document);
MathJax.Hub.Process(document);
},200);
void(0);


## How it works

The basic idea is to load MathJax from mathjax.org like this:

var e  = document.createElement("script");
e.type = "text/javascript";
e.src  = "http://www.mathjax.org/MathJax/MathJax.js";


Then you set up MathJax and process the page like this:

MathJax.Hub.Config({
config:["MMLorHTML.js"],
extensions:["tex2jax.js","TeX/noErrors.js"],
tex2jax:{inlineMath:[["$","$"],["$","$"]]},
jax: ["input/TeX"],
MMLorHTML:{prefer:"MML"}
});
MathJax.Extension.tex2jax.PreProcess(document);
MathJax.Hub.Process(document);


This solution simply runs all this together on one line and tells the browser to execute it. MathJax loads asynchronously, so javascript will try to execute the second step before MathJax finishes loading. To avoid this, I've inserted a small (0.1 sec) pause after the first step to give MathJax a chance to load. This works well for me, but you may have to tweak this number ... it's at the very end of the line (in milliseconds).

## Issues

• As with VA's solution, this doesn't seem to work with the standard view in Gmail.
• Mathjax.org may not be happy with people loading the script from them to view random web pages.
• For me, this works in Chrome, but leaves the page in Firefox (javascript must be overwriting the contents of the page). Does anybody know how to fix that? If yes, please edit this answer (it's CW). Edit (VA): I increased the timeout to 0.3 sec and added 'void();' at the end. In my tests, it now works in Chrome, Firefox, Internet Explorer, and Opera.

## MathML

If your browser supports MathML, this solution should produce MathML output, but I haven't tested this yet (because it doesn't work in Firefox for me). If you can get MathML output, please leave a comment saying so. If you had to do something special, please edit this answer (it's CW).

Edit(VA): I believe the only browsers supporting MathML now are Firefox and IE with MathPlayer installed. Using the default output (HTML-CSS) should work very well if you have installed MathJax fonts on your machine. Or you can wait until the official STIX fonts come out (it has been 13 years of delays but maybe they are really coming out on May 17?) and install those.

Also, noErrors.js and noUndefined.js are not currently part of the standard MathJax distribution. But they can be obtained from the recent builds as explained in the other answer.

-
Anton, thank you for your solution. But please edit it to encourage people to use their local MathJax installation. First, you get more control over the display this way, and can easily set lots of things. Secondly, if everybody in the world uses MathJax's server, they will go broke, and the community will suffer. – VA. May 15 '10 at 20:17
Greasemonkey is built into chrome. So installing/not installing it is not an issue. – Regenbogen May 15 '10 at 20:24
+1 for the right idea. Something like this SHOULD be the best solution, as it SHOULD work in every browser: Mozilla, Chrome, Safari, IE, Opera, etc, provided you have MathJax fonts installed locally and are using HTML-CSS output, not MathMML. This particular applet works for me in Chrome. But it breaks in Firefox (where it gives me a blank window with '2' on it). Could the javascript gurus please fix it? – VA. May 15 '10 at 22:31
OK, I think I figured this out. This bookmarklet works for me in Firefox, Chrome, IE, and Opera, once I increase the timeout to say 300, and add 'void(0);' at the end. It works even better once I replace 'www.mathjax.org' by my own server where I installed MathJax. Note: (1) Only Firefox and IE+MathPlayer support MathMML, (2) So you better use the default HTML-CSS, and then you better install MathJax fonts locally, (3) noErrors is not part of MathJax for now, and should be installed locally (see my answer), and it has to be called in MathJax.Hub.Config() or in the local config file. Good job! – VA. May 15 '10 at 23:34
Anton, I am sorry, of course I meant 'void(0);', thanks for fixing that. The answer to your question is NO (as I learned from Davide, the lead developer of MathJax, I had exactly the same question): Firefox, Chrome, and IE all do not allow execution of javascript from a local file. Only Opera does. – VA. May 16 '10 at 17:25