# Adding support for math notation [duplicate]

Every once in a while I miss having the option to write some LaTeX math on SO. E.g. when talking about automata. I'm certainly not the only one. And I think the person answering this question would have appreciated it as well. I'm sure there are more examples.

It can be done, look e.g. at the Physics forums. Multiple solutions exits, either by converting the LaTeX code to an image or MathML.

Since the fields of theoretical computer science and computer programming overlap (formal languages, data structures, ...), and because plenty of users are acquainted with LaTeX, I think it makes sense to provide support for mathematical notation on SO. What do you think?

-

## marked as duplicate by BЈовић, hims056, Martijn Pieters, psubsee2003, ЯegDwightMar 26 '13 at 12:49

See stackoverflow.com/questions/13149154/… for an actual example of why this is occasionally necessary for programming questions. –  eh9 Nov 20 '12 at 15:47
I think this request was for SO only; otherwise the [status-declined] doesn't make sense. –  Mechanical snail Nov 24 '12 at 7:40
@Mechanicalsnail: correct. In fact, when I filed this request the *.stackexchange.com sites didn't exist yet. There was only SO, SU and SF (and Meta, of course :)). –  Stephan202 Nov 25 '12 at 12:38

Found a site that does just this: $c=\sqrt{a^2+b^2}$ should work.

I can't seem to get the image working, I got the image working, thanks to Kip; for those who are curious, the url I am using is http://latex.codecogs.com/png.latex?c=%5csqrt%7ba%5e2%2bb%5e2%7d (which doesn't work properly as a link either - wonder if it has something to do with the \ in the url?)

Here's a cool one: $\frac{Stack}{Flow}$

-
:( - doesn't work for some reason. –  a_m0d Jul 10 '09 at 2:59
Strange indeed. Because loading the given example directly in the browser does work. I changed the backslash to %5C, but that didn't help either. –  Stephan202 Jul 10 '09 at 3:05
you can generate the encoded url string here: string-functions.com/urlencode.aspx just paste in the part that goes after "c=" –  Kip Jul 10 '09 at 3:09
note: for my first comment there, you can't copy the link from the comment, because SO is shortening part of it to an ellipsis. click on it or copy the location to get a proper link. –  Kip Jul 10 '09 at 3:11
Yeah, I just right clicked and "Copy Link Location" –  a_m0d Jul 10 '09 at 3:11
Important that you only paste in that last bit - otherwise it really stuffs it up! –  a_m0d Jul 10 '09 at 3:19
A follow-up: I found that texify.com has a much nicer interface, and it produces encoded URLs right away. –  Stephan202 Jul 12 '09 at 11:47
I wonder what it would take to get a copy of that codecogs setup? Hardware, licencing etc. –  BCS Jul 23 '09 at 17:47
On the same site, you can go here: latex.codecogs.com/editor.php That lets you enter the equation, get a preview, then it gives you a link to the actual image –  Kip Jul 23 '09 at 17:55
@stephan: I find the codecogs setup nicer because it helps you to build your equation; however, it is more work. –  a_m0d Jul 24 '09 at 0:39
+1 For Stack "Over" Flow. –  Mateen Ulhaq Apr 16 '11 at 4:35
Great answer, although it is still a pain in the butt and interrupts the train of thought by having to gather all these random equations while trying to write an answer. If only they would just add the MathJaX support directly... –  Andrew Mao Mar 21 '13 at 16:05

Is there any service out there that lets you generate latex images using query strings? I'm thinking something like:

<img src="http://example.com/latex.png?formula=2%2B2%3D4" />


It's hardly ideal because the URL encoding makes it difficult to read (the above example is just "2+2=4"), but it would at least be a workable solution. But I don't see it being implemented here because it's not necessary often enough for the team to focus their efforts on it.

Actually, if this service doesn't exist, someone should create it and they'd probably be able to make money. Since the URL encoding is so difficult, users would have to come to your site and enter the formula there, and let it generate the image url for you. You could sell ads there directed at math and science professors (which might be pretty effective, since you'd have a fairly narrow audience). And the generated LaTeX could have some kind of non-obtrusive watermark that would lead users back to your site.

-
Very interesting idea! –  Stephan202 Jul 10 '09 at 2:19
I like it! So who's gonna step up? –  Tom Ritter Jul 10 '09 at 2:22
Already been done - see my answer below! –  a_m0d Jul 10 '09 at 3:10
i see... oh well :( –  Kip Jul 10 '09 at 3:15
@a_m0d your answer below is now the answer above –  Andrew Mao Mar 21 '13 at 16:03

This is implemented on http://math.stackexchange.com -- you can check it out there. It will never be on Stack Overflow, though, as it is an extremely heavy dependency.

-
+1 - thanks for implementing this where needed the most! The first URL is kind of a mashup though, it should be math.stackexchange.com. (I'm afraid that might happen regularly with the three involved and related entities ;) –  Steffen Opel Aug 7 '10 at 12:07
Check out this answer that refers to client-side latex. –  Lance Roberts Jul 19 '11 at 14:52
I'm struggling to comprehend how it could be an "extremely heavy dependency". It's apparently not too heavy for math.stackexchange! Some questions and answers are better expressed in better notation. Can you please put some evidence to your claim? –  spraff Jul 26 '11 at 15:08
@spraff math notation is not that useful to practicing programmers, whereas it is rather essential to practicing mathematicians. You can see the full list of sites that support math notation here: blog.stackoverflow.com/2011/04/… –  Jeff Atwood Jul 27 '11 at 2:35
As a practicing programmer I dispute that, but it's a subjective point. What's objective is the heaviness of the dependency. That, I don't see. The software involved isn't especially big, and the images don't have to be computed very often. Or am I missing something? –  spraff Jul 27 '11 at 7:26
The support is also there on electronics.stackexchange.com and even the recently created dsp.stackexchange.com - I'd really like to see it on stackoverflow.com too. –  Paul R Jan 1 '12 at 14:44
“Never” is quite a long time! And seeing as all the rendering is done client-side, so all the servers have to do is embed a single line referencing some JavaScript (which already exists for those other MathJax-enabled SE sites), I cannot really follow the rationale either. With a CDN you'd not have any bandwith concerns either. Are you worried about page-load times? In any case, is this answer still up to date after two years? –  MvG Aug 6 '12 at 19:27
Blah, this is such a lame answer. Not everyone is programming in C/assembly anymore. Math is integral to machine learning, computer graphics, optimization, and lots of other very programming-fundamental disciplines. I resent having to write answers containing math in fixed-width font! Examples in my answer below. –  Andrew Mao Mar 21 '13 at 16:01
It will never be on Stack Overflow, though, as it is an extremely heavy dependency. Never? ಠ_ఠ Not even if you get some fancy Star Trek-like computers that can handle it? –  Synetech Sep 8 '13 at 4:01
Still unanswered: what is the "extremely heavy dependency"? –  raxacoricofallapatorius Nov 4 '13 at 13:59
@JeffAtwood: Have a look on this page: datascience.stackexchange.com/questions/1059/… would not be possible for the other sections to simply parse the math part to an image and cache it? Or load the Matjax only if used in the page.. –  Revious Oct 2 '14 at 14:59
@JeffAtwood: at least please include those 2 links in the formatting help: mathurl.com , codecogs.com/latex/eqneditor.php (for the lovers of perfectionism) –  Revious Oct 2 '14 at 15:06

We use mathematical notation all the time in the algorithm and math questions - LaTeX would be incredibly helpful (especially if it wouldn't be too much work to implement - mathoverflow.com already has it!)

-
As a practicing mathematician and a practicing programmer, I use LaTeX whenever I need to write up an algorithm analysis. You just can't analyze a loop right without subscripts, to pick on the most universal point. –  eh9 Nov 20 '12 at 15:34
As long as computational geometry and numeric computation are part of the project, LaTeX seems surely a required feature. –  h22 Feb 1 '13 at 8:41

I agree that there is a strong need for equations on StackOverflow.

I'd like to point out another major need for TeX support on StackOverflow: answering quantitative programming, vector computation, and machine learning questions. I understand there are some programmers on this site that believe everything can be expressed with code, but it's pretty much impossible to explain that the code is correct without math. Since machine learning questions are becoming much more common now, as well computer graphics questions, both of which require linear algebra and probability, I don't see why we should unnecessarily restrict ourselves. Another big use case: optimization problems such as linear programming and numerical approaches to solving equations.

I would say questions that marry the arts of mathematics and programming are ones that I especially enjoy answering, and I have quite a few answers that would have been much improved by being able to write math, instead of the ugly fixed-width hack. Here are some examples:

I have even more answers that haven't been accepted yet that also use math; I also have tons of answers where I decided to just not even try to explain with math. It sucks that every time I want to post a proper answer to a machine learning question, I end up waving my hands instead of writing something that will be useful for the OP and many others. Wouldn't things be so much better if I could actually contribute my knowledge?

Before posting this answer, I considered re-requesting this feature in a new question. I guessed that it would be immediately closed as duplicate, so I ended up posting this answer, which will probably never be read. :(

-
Yeah, it's a shame this question doesn't get enough attention. I mean, math is a basic principle of any programming language! –  Gottlieb Notschnabel Feb 25 '14 at 19:15

We should look into how mathoverflow did it. They have a very neat integrated solution which I think should be added to all the SO-like sites.

-
Really? Even moms4mom.com? –  Andrew Nov 23 '09 at 1:46
What moms can't do math? –  beggs Nov 23 '09 at 4:31

mimetex would be a great solution. It's rather lightweight and does math pretty well as dynamically generated images. It's also incredibly easy to set up. However, the administrators would need to add it.

See mimetex's website.

-
That page refers to forkosh.com/mathtex.html for servers with LaTeX installed. The output looks better, so I guess that is to be preferred. –  Stephan202 Jul 21 '09 at 14:37

http://mathbin.heroku.com works kind of like a code paste bin for math equations. It has an embed option, but it doesn't work with SO because it uses a script tag. It's a quick work around as you don't have to URL encode the LaTeX string. You also have to include the LaTeX string as part of your post in case someone decides to edit it and hit save.

-

I use this bookmarklet for rendering MathJax on sites that don't support it, for example all social networking sites.

In fact I have the bookmarklet converted as a Chromium extension so that I can render MathJax at the click of a button, on any site.

-

As long as computational geometry and numeric computation are part of the project, LaTeX seems surely a required feature. It is stupid to ask people to generate and upload formula images.

You could place the supporting renderer into separate server that would receive the equation URL-encoded, returning image in response. This probably would allow to use one of existing engines. It took about two days to integrate JLaTeXMath into my own project that way.

-
I'd expect questions on computational geometry and numeric computation to be asked on Computational Science, not on Stack Overflow (which is only about the programming aspects, which usually requires code, not equations). MathJax is available on Computational Science, as well as Mathematics, Physics, Computer Science, etc. –  Gilles Feb 1 '13 at 15:01