137

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?

4
  • 3
    See stackoverflow.com/questions/13149154/… for an actual example of why this is occasionally necessary for programming questions.
    – eh9
    Nov 20, 2012 at 15:47
  • 1
    I think this request was for SO only; otherwise the [status-declined] doesn't make sense. Nov 24, 2012 at 7:40
  • 2
    @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, 2012 at 12:38
  • 1
    So SO doesn't like math it seems.
    – Mitu Raj
    Jul 29, 2021 at 6:08

10 Answers 10

48

Found a site that does just this: c=sqrt(a^2+b^2) should work.

See also this site and particularly this page for more info.

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 https://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: StackOverflow

14
  • :( - doesn't work for some reason.
    – a_m0d
    Jul 10, 2009 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, 2009 at 3:05
  • 2
    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, 2009 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, 2009 at 3:11
  • Yeah, I just right clicked and "Copy Link Location"
    – a_m0d
    Jul 10, 2009 at 3:11
  • Important that you only paste in that last bit - otherwise it really stuffs it up!
    – a_m0d
    Jul 10, 2009 at 3:19
  • 2
    A follow-up: I found that texify.com has a much nicer interface, and it produces encoded URLs right away.
    – Stephan202
    Jul 12, 2009 at 11:47
  • I wonder what it would take to get a copy of that codecogs setup? Hardware, licencing etc.
    – BCS
    Jul 23, 2009 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, 2009 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, 2009 at 0:39
  • 8
    +1 For Stack "Over" Flow. Apr 16, 2011 at 4:35
  • 4
    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, 2013 at 16:05
  • Are we still doing it this way?
    – bobobobo
    Nov 5, 2019 at 2:15
  • This isn't really suitable; The math is not embedded in the questions/answers in a community-editable manner.
    – MRule
    Dec 2, 2021 at 17:41
28

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!)

2
  • 2
    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, 2012 at 15:34
  • 2
    As long as computational geometry and numeric computation are part of the project, LaTeX seems surely a required feature.
    – h22
    Feb 1, 2013 at 8:41
20

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.

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

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?

UPDATE: We have the ability to run code snippets now in posts now but not write math? Come on, it's 2015 - whatever performance issue hindered this from being implemented in 2009 surely isn't an issue anymore.

4
15

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.

Info here: TeX math markup is sorely needed

14
  • 1
    +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 ;) Aug 7, 2010 at 12:07
  • Check out this answer that refers to client-side latex. Jul 19, 2011 at 14:52
  • 19
    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, 2011 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/… Jul 27, 2011 at 2:35
  • 6
    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, 2011 at 7:26
  • 5
    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, 2012 at 14:44
  • 17
    “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, 2012 at 19:27
  • 16
    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, 2013 at 16:01
  • 7
    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, 2013 at 4:01
  • 8
    Still unanswered: what is the "extremely heavy dependency"?
    – orome
    Nov 4, 2013 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, 2014 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, 2014 at 15:06
  • This answer goes some way to explain the "extremely heavy dependency"
    – binaryfunt
    Aug 1, 2017 at 17:09
6

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.

2
  • 3
    Really? Even moms4mom.com? Nov 23, 2009 at 1:46
  • 13
    What moms can't do math?
    – beggs
    Nov 23, 2009 at 4:31
3

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.

1
  • 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, 2009 at 14:37
2

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.

2

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.

1

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.

1

Not the answer you're looking for? Browse other questions tagged .