# TeX math markup is sorely needed

This site is going to need TeX markup to express mathematical symbols and formulas well.

• Yep. They have it at Math Overflow, hence should be easy apply it here. – Royi Jul 20 '10 at 19:26
• For equations the site needs something besides image links. ∑∑∑∑ – Chris S Jul 20 '10 at 19:35
• @ShreevatsaR: I'm afraid this doesn't even get much attention at the main meta... But maybe if we all upvote there, we'd get more attention - I'll attach a bounty there, maybe that helps – Tobias Kienzler Jul 29 '10 at 7:30
• Whatever we are using now chart.apis.google is pretty horrible and I hope we can switch to jsmath or mathjax :S – anon Jul 29 '10 at 19:39
• We will continue to improve support for TeX - this is by no means the end. – Geoff Dalgas Jul 29 '10 at 19:39
• ~~~~~ yay! ~~~~~ – BlueRaja - Danny Pflughoeft Jul 29 '10 at 19:40
• @Geoff: I'm not clear on this...what exactly was done? I'm not seeing any change...I still see all kinds of $blah$ type stuff. – Beska Jul 29 '10 at 20:56
• ~-~-~-~- YAY! -~-~-~-~ – Mateen Ulhaq Apr 5 '11 at 0:34

I have already started using TeX in my markup.

The way that Math Overflow does it is to surround the TeX with dollar signs, using the jsMath library.

I suggest we stick with that convention, so that when we have support for it, our old posts will "light up".

EDIT:

I have created a quick-hack grease monkey script to get this done in the mean time:
http://userscripts.org/scripts/show/81977

EDIT2:

I have updated the script to work on Stats.stackexchange.com, and have added in transparency, and options to use other services, as well.

EDIT3:

• @John: Is it ok to copy your script for the stats.stackexchange.com? – Srikant Vadali Jul 21 '10 at 19:28
• @Srikant: I would rather have you just link people to my code, but the source is open. – John Gietzen Jul 22 '10 at 1:00
• @John: Will the script work as is for stats.stackexchange.com? If yes, I will be more than happy to point to your script to users over there. A second question: On what browsers does the script work (only firefox + greasemonkey installed?)? – Srikant Vadali Jul 22 '10 at 2:29
• @Srikant: I got it to work on chrome without other plugins. It should work for any site by changing the @include to the corresponding domain (idk if @namespace have to be changed) – Chao Xu Jul 22 '10 at 3:27
• @Mgcl: Thanks. @John: The image is not showing up in chrome but working in firefox. BTW, should we take discussions reg the script to userscripts.org? – Srikant Vadali Jul 22 '10 at 13:10
• @John: something in your update broke the script for me in Chrome--it was working last night and now produces broken images. – Isaac Jul 22 '10 at 14:15
• @John: Please see my modifications to your current (4th) version, posted at pastebin.com/uVB1rEdf and described below (meta.math.stackexchange.com/questions/2/183#183). – Isaac Jul 23 '10 at 4:34
• @Isaac: Thanks, I have incorporated your changes. – John Gietzen Jul 24 '10 at 14:24
• Does it work on Safari? – Vivi Jul 29 '10 at 0:35
• the script is fantastic :-) – mau Jul 29 '10 at 8:54
• Thanks for your contribution @John - we have incorporated it as a plugin on Math / Stats / Tex and all related meta sites for the good of the community. – Geoff Dalgas Jul 29 '10 at 19:37
• Great to have this on the math/stats/TeX sites. However, it is occasionally giving odd results. For example, see the answer of PaulHurleyuk at stats.stackexchange.com/questions/213/…. The problem is that the R code includes a dollar sign. Can the script by modified to fix this? – Rob Hyndman Jul 30 '10 at 13:03
• @Rob: Yes, easily. There is a list of tag names to ignore, and we can just add 'pre' and 'code' to the list. Also, we won't be able to entirely get away from weirdness, because the code is not an actual parser. – John Gietzen Jul 30 '10 at 15:02
• apologies for hijacking this thread, but I was wondering how we might get this enabled on the new CS theory SE site (cstheory.stackexchange.com) as well ? – Suresh Venkat Aug 17 '10 at 3:49

By the way, I'd recommend actually using MathJax, the brand new replacement for jsMath. It's still not quite as fast as jsMath, but it's the way of the future. MathOverflow will switch soon.

• MathJax is written by the same guy, only it's built with the future (HTML5) in mind and supports LaTeX and MathML. – Nick Jul 20 '10 at 20:10
• HTML5 is not the future. It's a kludgy hack made by lazy software manufacturers who don't want to bother complying with XHTML2. – 97832123 Jul 21 '10 at 19:45
• Future proof is important. I hope they'll use MathJax. Thanks. – Royi Jul 22 '10 at 7:45
• XHTML2 is dead, the group working on it was made redundant. – Hendrik Brummermann Jul 23 '10 at 21:14

# Temporary workarounds:

Images can be embedded in questions and answers with ![](http://www.example.com/image.png) like so:
![](http://mathurl.com/2azr28f.png) becomes
Combine this with:
http://mathurl.com/ - type in latex, get a minified image url to link to in your posts
http://www.codecogs.com/latex/eqneditor.php - as above, but no minification, and you have to rightclick to get the image url.

For simple formulas, where LaTeX is not needed:
You can use <sup></sup> to write superscripts and <sub></sub> for subscripts:
y<sub>1</sub>=x<sup>2</sup>+3becomes y1=x2+3

• +1 for mathurl.com I never know about it. – Lazer Jul 28 '10 at 13:56
• +1. IMO this is the preferable workaround. – Tomer Vromen Jul 29 '10 at 19:23

I've posted a walk-through of how we've implemented math rendering on MathOverflow on meta.SO. As Scott said, we'll be switching to MathJax in the near future, so it probably makes sense for new SE sites to just use MathJax from the get-go. Once we switch, I'll try to remember to update that answer to reflect the changes.

We have added MathJax to support TeX equations based on feedback. MathJax is on the cusp of a 1.0 release and we will update this library once it's final.

Three Four Five observations:

• If one escapes a latex fragment using backticks (this is frequently needed in order to arbitrate between Markdown and the latex rendered) the latex piece gets colored in gray due to the stylesheet in a rather unsightly way.

• Display math using $$ does not seem to work. • It would be immensely useful if the preview of answers rendered latex too. • Something's amiss with things like \mathbb{Z}/3\mathbb{Z}, which gets rendered as \mathbb{Z}/3\mathbb{Z}. (Hmm, here it looks fine, but in Group With an Endomorphism That is "Almost" Abelian is Abelian. it doesn't) • Editing a comment kills everything within dollar signs. • TeX markup is implemeted by making calls to chart.apis.google.com... I wonder why that is better than having the client render? – Mariano Suárez-Álvarez Jul 29 '10 at 21:17 • It's not. I hope they switch to mathjax. I do see your 2 and 4: math within$$ ... $$doesn't work (it keeps a dollar sign on each side and just displays inline), and on the question you linked to, even the / and 3 are in blackboard. – ShreevatsaR Jul 29 '10 at 21:21 • Okay, this question shows the behavior you describe for $$. But you can use $\displaystyle ...$ for now as Qiaochu did here. – Larry Wang Jul 29 '10 at 23:55

If the formula is not complicated, besides <sup> and <sub> I also use character entities in html. Some examples:

bold &prod; displays as
bold &sum; displays as

in general, Greek letters are displayed by writing &letter; other symbols are

ℵ &alefsym;
∀ &forall;
∃ &exist;
∈ &isin;
∩ &cap;
∪ &cup;

Look here for the complete list of allowed characters. I know that this is not enough to write decent mathematics, but it's a start.

• wow that works great. I've never thought that you can use html encoded symbols in stackexchange. I though only some tags like pre, sup, sub, br... work here – phuclv Feb 3 '15 at 5:18
• @mau: that link does not work anymore ... – kjetil b halvorsen Dec 31 '15 at 13:33
• I updated the link, this time using Wikipedia: en.wikipedia.org/wiki/…. I hope this helps! – mau Dec 31 '15 at 18:50

I do believe that this is of utmost urgency, and should be first priority for any developers working on this site.

• I doubt anything will happen during the beta, unless a lot of betas want the facility. – Charles Stewart Jul 21 '10 at 11:29
• MathOveflow already has this feature, and I suspect that it shouldn't be very hard to make it work here as well. – Anonymous Jul 21 '10 at 20:30

Is this thing on?
$$$\sum_{i=1}^{\infty}x_{i}$$$

...yep!

$\begin{tabular}{r|c|l} symbol & read as & example \ \hline$\to$& maps to" &$f:\mathbb{R} \to \mathbb{Z}$\$\forall$& "for all" &$\forall x \in E$\end{tabular}$

... what environments are going to work here? (clearly not tabular)

EDUT Oh, didnt read the comments. Thanks guys for working on this!

I vote for MathJax to be used instead of jsMath if a Javascript library is decided over a server-side LaTeX image generator.

Equation rendering is exceptional over jsMath, and all major browsers are supported. (Even IE6!! See Browser Compatibility.) Most operating systems and browsers anti-alias the LaTeX, and the equations seem to fit in to the native look, whatever browser that may be.

Is anyone else seeing the symbols as monstrously huge?

Agreed. I think everyone is begging for this feature. It's been requested numerous times on Meta StackOverflow, the latest one specifically for Area 51/StackExchange being here.

Personally I would like to see jsMath implemented on StackExchange sites. It's virtually trivial, a script reference simply needs to be added to the page.

In the meantime, there's Google Chart.

edit: except that it doesn't appear to show up. :P

• See my answer, I have added a script that uses the Google Chart API to some success. – John Gietzen Jul 21 '10 at 18:58

LaTeX rendering is needed, but I would like to see a server-side solution rather than a client-side solution such as jsMath. The biggest problem for me with jsMath is that it takes such a long time to completely load a web page on some popular MathOverflow questions. Often I have to simply disable jsMath or else the web browser consumes so much memory that my computer starts swapping pages of RAM to the disk.

What about adding a toolbar button to convert a LaTeX expression to an image using the mathURL service?

I am running John Gietzen's awesome Greasemonkey script in my browser and everyone's TeX is showing up great - but I am having a problem composing TeX. Specifically, I seem to be completely unable to include addition signs in my formulas. This makes zero sense to me, can somebody explain?

For example: "P of x equals a x squared plus bx plus c" looks like: $P(x)=ax^2 + bx + c$

I have typed $</code><code>P(x)=ax^2 + bx + c</code><code>$

EDIT: Isaac has fixed the script, it looks like it's working pretty good now.

• I was just experiencing the same problem. I haven't looked into the script yet, but I suspect that it's because a + in url-encoding is an encoded space (i.e. there's some missing encode/decode step). – Isaac Jul 23 '10 at 4:18
• Here's my modified version of the script: pastebin.com/uVB1rEdf --I think I've fixed the plus-sign issue and I've also excluded the script from running on the edit page (which, at least for me, was making all TeX markup vanish entirely in the edit box). – Isaac Jul 23 '10 at 4:32
• @Isaac, @John Gietzen: Thanks to you both for implementing this hugely important workaround. – Tom Stephens Jul 23 '10 at 4:48
• @Isaac: The line "name == 'textarea'" is supposed to prevent it from interfering with the edit window... – John Gietzen Jul 23 '10 at 14:38
• @John: I didn't read through it enough to catch that. For some reason, though, on Mac Chrome it was still eating the TeX in the textareas, which is why I added the exclude. The change from escape to encodeURIComponent was the more important change, though. – Isaac Jul 23 '10 at 14:41
• @Casebash: My answer at the top has a link to the Userscripts.org page. There should be a big green "Install" button. – John Gietzen Jul 25 '10 at 14:59

As mentioned before, one option that doesn't involve a third party rendering service is MathJax, the spiritual successor to jsMath. Here is a small userscript that inserts MathJax (currently hosted on my own web server, but presumably would be hosted by stack exchange on a permanent basis) into the head of math and meta.math.

You can use a number of math formats for display, like regular ol' TeX markup:

$P(x)=ax^2 + bx + c$

Or some more complex TeX formatting:

$\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)$

And eventually, if Stack Exchange allows MathML to be inserted into pages, code like this:

<math display='block'><mrow><mi>x</mi><mo>=</mo><mfrac><mrow><mo>&#x2212;</mo><mi>b</mi><mo>&#x00B1;</mo><msqrt><mrow><msup><mi>b</mi><mn>2</mn></msup><mo>&#x2212;</mo><mn>4</mn><mi>a</mi><mi>c</mi></mrow></msqrt></mrow><mrow><mn>2</mn><mi>a</mi></mrow></mfrac></mrow>[/itex]

(something seems a little slow when loading MathJax here - it may be a configuration problem on my end. I will look into it later today. Reference the official preview page if you want a better idea of the latency with translating lots of TeX on a page with javascript - it's quick)

• Installed in Chrome, worked for about 1 minute (rendered beautifully, if slow on the first load), then stopped working. Page loads generate the initial "Loading" message at the bottom, briefly, but no subsequent messages and none of the TeX is rendered. – Isaac Jul 24 '10 at 17:57
• It didn't even occur to me to check in Chrome, doing so now... – Nick Jul 24 '10 at 18:25
• Did you have any luck with it in Chrome? – Isaac Jul 28 '10 at 22:55
• It works for me. (Chrome 5 Mac) – Vortico Jul 30 '10 at 15:38

Another temporary workaround:

Use LaTeXiT with Dropbox or any other image hosting service. To match the size of the body text, set the font size to 16 pt.