Swablr found this which I'm posting here:
Display LaTeX math on web pages and in email
(Last updated: May 16, 2010)
For background, see this and this questions on MathOverflow. Feedback can be sent to me (va.at.mathoverflow) at gmail.com.
This
page provides some tools to display LaTeX math on web pages where the
web designer did not provide a server-side way of doing this.
Currently, such pages include arXiv.org, front.math.ucdavis.edu, MathSciNet.
The programs also work in Gmail (the first four solutions work in
"basic HTML" and "print" views, the last one works in the standard
Gmail view).
Several ways are provided. The first three assume that you use Mozilla Firefox with the Greasemonkey addon.
The scripts work on the above-mentioned web sites by default. You can
always add and remove sites by using the Greasemonkey console (click on
the monkey face).
The last two solutions are bookmarklets which should work in any browser.
Solution 1: A standalone Greasemonkey script
Download display-latex2.user.js and save it to your Desktop. 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.
Solution 2: Use MathJax installed on a local server
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.
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.
[FONT='courier new', monospace]extensions: ["tex2jax.js", "TeX/noErrors.js", "TeX/noUndefined.js"],
and inside the TeX block, the following code
//
// These parameters control the TeX input jax.
//
TeX: {
noErrors: {
inlineDelimiters: ["",""], // or ["$","$"] or ["\\(","\\)"]
multiLine: false, // false for TeX on all one line
style: {
"font-family": "serif",
"font-size": "120%",
"color": "gray",
"border": ""
// add any additional CSS styles that you want
// (be sure there is no extra comma at the end of the last item)
}
},
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
[/font]
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 :
[FONT='courier new', monospace]jax: ["input/TeX","output/NativeMML"],
Next, add the following to your userContent.css file (see Customizing Mozilla):
[FONT='courier new', monospace][FONT='Trebuchet MS', arial, sans-serif][FONT='courier new', monospace]math { font-size: 112% }
[FONT='courier new', monospace]
[FONT='courier new', monospace][mathvariant="double-struck"] {font-family: MathJax_AMS; }
[FONT='courier new', monospace][mathvariant="script"] {font-family: MathJax_Script; }
[FONT='courier new', monospace][mathvariant="fraktur"] {font-family: MathJax_Fraktur;}[/font]
[FONT='courier new', monospace][mathvariant="-tex-caligraphic"] {font-family: MathJax_Caligraphic; }[/font]
[FONT='courier new', monospace][mathvariant="bold-script"] {font-family: MathJax_Script; font-weight: bold;}[/font]
[FONT='courier new', monospace][mathvariant="bold-fraktur"] {font-family: MathJax_Fraktur; font-weight: bold;}[/font]
[FONT='courier new', monospace][mathvariant="monospace"]{font-family: monospace} [/font]
[FONT='courier new', monospace]
[/font]
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.
[FONT='courier new', monospace]
[/font]
For font consistency, you could also type 'about:config' (without the quotes) in the location bar, and change the variable font.mathfont-family to
[FONT='courier new', monospace]MathJax_Main, MathJax_Math, MathJax_Size1, MathJax_Size2, MathJax_Size3, MathJax_Typewritter, MathJax_AMS, MathJax_Caligraphic, MathJax_Fraktur, MathJax_SansSerif
[/font]
[/font][/font][/font]
Solution 3: choose and pick between three locally installed scripts
In addition to MathJax, you can install display-latex2.js and ASCIIMathML.js on your server, and use the Greasemonkey script displaymathonpage.user.js. Edit it and replace the variables mathjaxServer, displaymathServer, asciimathmlServer
at the top of the file by pointing them to the right places. By
default, they are assumed to reside in the top directory of
'http://localhost'. If that's where your scripts are, you don't need to
change anything
[/font][/font]
[/font]
[/font]About the engines
- For the MathJax project, including the installation instructions etc., go here.
- ASCIIMathML was written by Peter Jipsen, go here.
- display-latex.user.js was written in 2006-7 by Steve Cheng. The original is here. In April-May 2010 I, VA@MathOverflow, updated it as follows:
- Fixed \mathbb, \mathcal, \mathfrak: many of these characters were pointing to Unicode values missing in the math fonts.
- Fixed displayed formulas with $$...$$ and \[...\].
- Added some extra TeX commands and arrows that are used on MathSciNet, for example.
- Made
it work with Gmail (in "basic HTML" and "print" views). The original
script hanged since Gmail uses $ in its code. Also, the script did not
work with formulas spread over two or more lines, as frequently happens
in an email. - Added common abbreviations, such as \A and \bA for \mathbb A, and \cA for \mathcal, etc.
Brief comparison of the engines
MathJax is by far the most professional solution. It is an open source project, 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
dispay-latex2 provided a consistent solution for me, with occasional problems (such as displaying $\overline{\mathbb F}_2$).
ASCIIMathML has problems with displaying \mathbb, \mathcal, and \mathfrak, at least with the fonts I tried, and sometimes chokes on long formulas.
Note on the math fonts
Before the official STIX fonts arrive, the best could be to use Math_Jax fonts.
Windows 7, Vista, and MS Word 2007 all include “Cambria Math”. These fonts are actually very nice, but using them with MathJax and
Native MathMML output leads to the incorrect (but readable) rendering
of \mathbb, \mathcal, \mathfrak characters, because of a Mozilla bug.
Solution 4: bookmarklet for any browser
This bookmarklet was contributed by Anton Geraschenko in this Mathoverflow answer. Create a bookmark with the following text as "location"
javascript:
var e=document.createElement("script");
e.type="text/javascript";
e.src="http://localhost/MathJax/MathJax.js";
document.getElementsByTagName('head')[0].appendChild(e);
setTimeout(function({
MathJax.Extension.tex2jax.PreProcess(document);
MathJax.Hub.Process(document);
},200);
void(0);
Again,
'localhost' should be replaced by the server where you have installed
and configured MathJax. Then, once you encounter a web page with LaTeX
math, simply click on that bookmark (in Firefox, you can also set up a
keyboard shortcut). The page will redisplay with math correctly
rendered (the same instructions for installing fonts as in Solution 2
apply). This works in Gmail's "basic HTML" and "print" views but not in
the standard view.
Solution 5: bookmarklet for Gmail's standard view
This bookmarklet works in the standard view. It works nicely for me if my MathJax server is configured with
jax: ["input/TeX","output/NativeMML"].
It hangs if jax: ["input/TeX","output/HTML-CSS"] is used.
javascript:
(function(){
var e=document.createElement("script");
e.type="text/javascript";
e.src="http://myserver.org/MathJax/MathJax.js";
document.getElementsByTagName('head')[0].appendChild(e);
function mathjaxThis(doc){
setTimeout(function(){
MathJax.Extension.tex2jax.PreProcess(doc);
},300);
setTimeout(function(){MathJax.Hub.Process(doc);
},300);}
var iframe=document.getElementById('canvas_frame');
var body=iframe.contentDocument.body;
var emails=body.getElementsByClassName('ii gt');
var length=emails.length;
var i,j;
for(i=0;i<length;i++){ mathjaxThis(emails[i]);
}
})()
If there are several messages open in a conversation, I have to click on the bookmark repeatedly, as they get transformed in a sequence, one by one. This must be a timing issue. The following version avoids this problem at the price of several alert boxes popping up.
javascript:
(function(){
var e=document.createElement("script");
e.type="text/javascript";
e.src="http://myserver.org/MathJax/MathJax.js";
document.getElementsByTagName('head')[0].appendChild(e);
function mathjaxThis(doc){
setTimeout(function(){
MathJax.Extension.tex2jax.PreProcess(doc);
},300);
setTimeout(function(){MathJax.Hub.Process(doc);
},300);}
var iframe=document.getElementById('canvas_frame');
var body=iframe.contentDocument.body;
var emails=body.getElementsByClassName('ii gt');
var length=emails.length;
var i,j;
for(i=0;i<length;i++){ j=i+1; alert('MathJax is working on opened message '+j);
mathjaxThis(emails[i]);
}
})()
For more info, check the chat room.