329

MathOverflow has an awesome engine where you can embed LaTeX in questions, answers, and comments. Can we get something like this going on Stack Overflow?

I think it’d be appropriate as I at least pretty often want to write something like n^2 and would benefit greatly from prettier markup.

19
  • 8
    +1. Though in a "programming", instead of math, environment, it seems this issue comes up less often and programmers are used to dealing with it when it does. Plus complex formulas aren't needed nearly as often. (How often do you think you'd be misunderstood on SO writing n^2 and n**2?)
    – Gnome
    Commented Nov 22, 2009 at 2:20
  • 67
    That's true, but just because we're used to something bad doesn't mean we shouldn't attempt to improve it =).
    – Claudiu
    Commented Nov 22, 2009 at 2:41
  • I like the idea in principal. However, it should be as intuitive as possible. I've looked at LaTeX for typesetting and decided to stick with QuarkXPress as I found it more intuitive. (shudder)
    – Jason D
    Commented Nov 29, 2009 at 23:59
  • 11
    I think this is a good idea. It would be very helpful for the more computer sciency sort of questions. I think LaTeX makes the most sense; it's standard in academia.
    – user138665
    Commented Dec 17, 2009 at 1:42
  • svgkit.sourceforge.net/tests/latex_tests.html or similar might help. Think "preview bit" below answer.
    – Aiden Bell
    Commented Jan 14, 2010 at 16:11
  • Maybe this is just my personal problem, but I cannot read set theory notation or Sigma notation, even though I easily understand the related concepts they embody. Those would probably be the first things commonly used on the site. As much as I want arithmetic to have the proper symbols, I would not want the rest that comes with it. Commented Nov 19, 2011 at 1:09
  • 11
    I would argue that programmers see a lot of complex math, it just depends on what you are programming. I do research in intelligent controls, for instance, and most of my programs are heavy on both the programming stuff and the math. LaTeX in SO would be extremely helpful.
    – Engineero
    Commented Jun 9, 2013 at 17:12
  • @minitech Do you have an example for when you would use this on SO?
    – Undo
    Commented Sep 10, 2013 at 17:28
  • @Undo: Not on hand. Anything regarding algorithms. This advice is an important part, by the way.
    – Ry- Mod
    Commented Sep 10, 2013 at 17:29
  • 4
    @minitech If you need math formatting, there's a good chance that your question is off-topic and you should ask it on Computer Science instead. There are plenty of exceptions, of course, but I've found it to be a good rule of thumb for deciding between Stack Overflow and Computer Science. (You could even add a third wheel: code → Stack Overflow, math → Computer Science, neither → Software Engineering, but I don't know how accurate that one is.) Commented Sep 10, 2013 at 17:50
  • 7
    @Gilles: Sure. If it’s not, however… I just don’t see the harm in adding something that already works elsewhere for the specific exceptional cases.
    – Ry- Mod
    Commented Sep 10, 2013 at 17:51
  • The FAQ link for latex now redirects to the tour page.
    – Stevoisiak
    Commented Jul 18, 2017 at 13:24
  • 3
    A good suggestion that should never have been closed, and if you could just edit it to say "SO and selected other SE network sites", then it should be reopened ASAP.
    – smci
    Commented Dec 10, 2018 at 3:15
  • Can somebody show me an easy way to write a square root in StackOverflow, as $\sqrt$ is not an option? :-) Oh, I can't install StackApps due to security concerns of my employer.
    – Dominique
    Commented Feb 13, 2023 at 10:59
  • @Dominique .
    – zeit
    Commented Feb 14, 2023 at 1:49

7 Answers 7

45

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. (See also Nick's investigations about impact in November 2013.)

Info here: TeX math markup is sorely needed

13
  • 17
    Well, you could conditionally enable it accross stackexchange, enabling consistent markup (question migration). By that I mean that you check the question and all answers if there is LaTeX block and if so, you load this "extremely heavy dependency". There are questions that would hugely benefit from that.
    – Rok Kralj
    Commented Jun 26, 2012 at 17:07
  • 78
    As it works just fine on math.stackexchange.com how is it too heavy?
    – donroby
    Commented Aug 12, 2012 at 16:54
  • 18
    Also on physics SE.
    – Calmarius
    Commented Aug 16, 2013 at 14:52
  • 1
    (@donroby, I know more than a year passed, but if you still wonder about impact and missed it: see Nick's investigations. Just the messenger!)
    – Arjan
    Commented Dec 12, 2013 at 20:22
  • 19
    -1 it should be enabled on any site that might use math. See stackoverflow.com/a/15966238/125507 for example
    – endolith
    Commented Feb 25, 2014 at 19:44
  • 28
    If Wikipedia guys (#5th website on Internet and non-commercial) had same point of view, I suppose we would never had math in Wikipedia as well. "It would never be on StackOverflow" is too strong a statement. Sure it can be enabled purely on client side and limit to only those posts. This is 2014 and StackOverflow was supposed to be THE website. Programming is mathematics. Knuth would have been disgusted not seeing expression O(n) rendered via LaTeX. Commented Dec 27, 2014 at 7:11
  • 1
    How about moving the making of the decision to render LaTeX to the client side, so that it's the browser that will trigger the rendering? Would this negatively affect page load times for pages that don't use LaTeX? Commented Mar 9, 2015 at 12:13
  • 3
    Any change in this for the likes of jqMath or KaTeX? Both of which seem to be much faster than MathJax
    – Toby
    Commented Mar 23, 2017 at 13:16
  • 3
    Funny that Puzzling, Physics, Chemistry, Crypto, and TONS of other network sites have LATEX, but it will "never be on Stack Overflow". Is is because they have less traffic? Or do they just have terrible load times and noone cares because they are less important?
    – NH.
    Commented Oct 19, 2017 at 23:13
  • 1
    How do you do with SymPy? But perhaps Sympy is not programming.
    – mins
    Commented Nov 16, 2020 at 16:40
  • 1
    I see the main argument was that it takes a fraction of a second longer without any latex content, and a suggestion that it might take even a full second when processing content. Is 1 second really too long to wait? can it not be lazy loaded so it is only loaded on demand? Commented Dec 12, 2020 at 18:43
  • 1
    I there a reason not to render the expressions on the server side? I think half-modern browsers allow the necessary fonts to only be loaded when used and do so after rendering the page initially. Commented Apr 8, 2021 at 18:51
  • 1
    I'm not too familiar with how heavy latex is but a tonne of other sites implement it so I doubt it's crippling, additionally a lot of stuff is moving to client side rendering which would make the cost approximately nill. Finally compute power is still increasing rapidly; while we're going to start running into physical limits as we hit the atom there's still a fair chunk left there, and a lot of room in terms of efficiency so there's no reason to think what is "too expensive" today won't be negligible in 5-10 years time. So saying it'll "never" be possible is just daft
    – Pioneer_11
    Commented Jan 10, 2023 at 0:50
120

enter image description here

As a workaround, you can easily embed LaTeX by generating an image of the equation using the following WYSIWYG editor: https://codecogs.com/latex/eqneditor.php.

enter image description here

11
  • 46
    Holy crap, this is useful.
    – Makoto
    Commented Jan 20, 2013 at 5:06
  • I know it's too late to ask, but is there an alternate to codecogs? This website has been giving a 503 - Service Not Available since past few days.
    – Ranveer
    Commented Feb 15, 2014 at 21:40
  • 4
    @Ranveer Daum Equation Editor
    – Anant
    Commented Feb 20, 2014 at 17:17
  • 9
    Images are discouraged across all SE, because they are impossible to search.
    – vonbrand
    Commented Apr 26, 2014 at 15:16
  • 4
    This is the only solution other than adding Math.SE style LaTeX support that's adequate to the problem, which is spelled out in @datenwolf's answer. Most of the comments and answers don't realize what sort of mathematics can be needed. With this solution, however, not having LaTeX support in SO is acceptable. Otherwise the lack of LaTeX support would limit SO to problems that don't require comparison of code with halfway complex mathematical specifications. Such problems are not common on SO, but if they couldn't be adequately be handled in SO, that would be sad.
    – Mars
    Commented Oct 28, 2014 at 5:00
  • 1
    instead of pasting image, you can just use the api url as the image, see my answer on stackoverflow Commented Sep 24, 2015 at 18:25
  • 2
    Could we get something like LaTeX Equation Editor hosted by StackExchange itself? I don't like to link content of another site. [It would even give them a (strongly limited) ability to track users on this site.]
    – JojOatXGME
    Commented Mar 6, 2016 at 4:24
  • 4
    Not only they are impossible to search but they’re also not accessible to e.g. screen reader users.
    – bfontaine
    Commented Nov 16, 2016 at 15:01
  • 2
    Images are not selectable by parts, so not a good workaround
    – HackerBoss
    Commented Oct 14, 2018 at 22:44
  • 1
    This application is a good interface for LaTeX but it is buggy application. Sometimes it puts the code in the wrong place of the equation. Undo doesn’t remove the last action. The case clause allows you to select more than two columns but it is not valid.
    – David Leal
    Commented Nov 24, 2022 at 22:41
  • Codecogs doesn't copy and paste correctly between vim and on mac. Plus there are many functions not supported, like all the whitespace I tried Commented Jul 31 at 21:57
66
+550

Having LaTeX support on Stack Overflow would be great. After all SO is about programming, which covers algorithms. And some algorithms are easier explained if one can typeset math. For example whenever it comes to complicated transformation issues regarding 3D graphics, being able to typeset those matrices would be a huge benefit.

14
  • For 3D stuff, you should be at GameDev.SE anyways. LaTeX will take up CPU (on your computer and on SO's servers), and I believe it'll be only needed in 1/1000 questions or answers. And most of those questions could probably go over to Math.SE, or GameDev.SE. Commented Apr 16, 2011 at 4:31
  • If you're really desperate, you can render the image, and then simply include the image in your question/answer. Commented Apr 16, 2011 at 4:33
  • 5
    @muntoo: 3D isn't limited to gaming – I admit, that my 3D experience mostly results from developing a 3D engine. However it's as important in programming engineering tools (CAD/CAM), scientific visualization, modern user interfaces, etc.
    – datenwolf
    Commented Apr 17, 2011 at 8:50
  • @datenwolf I think physics simulation fits in to GameDev.SE, even if it's for a NASA rocket, and not just a game with a NASA rocket. GameDev.SE probably has a higher ratio of knowing "3D stuff" to number of [active] users than any other SE site. You don't have to tell them that you're going to be using it for a "game" or not. Commented Apr 17, 2011 at 18:14
  • For stuff that doesn't fit into GameDev.SE, you could go to CSTheory.SE or Math.SE. (Or any of the other LaTeX enabled sites.) Commented Apr 17, 2011 at 18:16
  • 5
    @muntoo, we don't get to choose where the questions go, and often the subject matter belongs on SO.
    – Adam
    Commented Jun 14, 2011 at 7:14
  • 2
    @muntoo if it is used in 1/1000 of the questions, it will affect SO's servers only in 1/1000 of the time...
    – vonbrand
    Commented Apr 26, 2014 at 15:19
  • I think you're wrong about SO being for algorithms. SO is for calls to library functions which implement algorithms. Questions and answers about algorithms themselves are normally downvoted or answered with library function calls.
    – sh1
    Commented Jul 31, 2016 at 18:28
  • 1
    @sh1: To properly use a library one must understand the underlying principles that are to be achieved with doing these calls. Take computer graphics programming for example. A recurring question is, why normal vectors muse be transformed using a different set of operations (i.e. library calls) than regular vertex positions. Another recurring question is, why a separate tangent space transformation is required for normal map bump mapping. Just giving the recipe is only half the answer. It's also essential to understand "why". And the most concise way to explain the "why" is through math.
    – datenwolf
    Commented Aug 2, 2016 at 14:28
  • 1
    @sh1: Some of the mathematical notation, for the most part linear algebra can be typeset using unicode symbols. But already something as mundane as superscripts or subscripts is impossible with just markdown and unicode. Sometimes you want to typeset a partial differential equation, that can be found in a book or a paper about a particular graphics rendering technique and want to explain how to translate that into library calls.
    – datenwolf
    Commented Aug 2, 2016 at 14:31
  • 2
    @sh1: And then there's of course the broader issue that, thanks to the Curry–Howard correspondence writing a program is technically the same thing as writing a mathematical proof. So stating that programming and asking questions on StackOverflow is about how to call library functions is highly ignorant. And given that some languages (like Coq which allows you to write mathematical proofs and translate it into programming language source code), yes math typesetting is absolutely required.
    – datenwolf
    Commented Aug 2, 2016 at 14:35
  • Well in my experience, when I'm idle and take the time to look at new questions as they're asked; if anything interesting and algorithmic does come up or if it requires any thought at all then it's downvoted and eventually closed or deleted. SO only accepts questions that help game the system for reputation, and that's a matter of familiarity with libraries where you can spit out an answer quickly for the reputation avalanche of being first responder.
    – sh1
    Commented Aug 2, 2016 at 15:34
  • 3
    @sh1: Two of my most highly voted answers are quite heavy on the math: stackoverflow.com/a/6661242/524368 and stackoverflow.com/a/5257471/524368 – both of them are lacking in the quality of the mathematical typesetting. In case of the "how to calculate normals" answer I was able to make use of Unicode to somehow typeset it. The answer on how to derive a tangent space mapping tries to use ASCII art to typeset matrices and fractions, but it looks ugly (in fact it's that later answer, which lack of proper math typesetting which made me ask about adding support for TeX/LaTeX at SO).
    – datenwolf
    Commented Aug 2, 2016 at 16:24
  • @sh1 Easy counter-example to your claim: there is a bug on Spark MLlib implementation of an algorithm that results in an error. I want to show the algorithm it were intending to implement: without any details about the why of it. That is squarely an SO question - but at the present time the algorithm / equation itself would have to be an unsearchable image. Commented Jan 6, 2017 at 17:11
44

Although I'm a big LaTeX fan, I don't think the work would be justified for Stack Overflow.

Since Stack Overflow is one of the sites on the web that gets Unicode right, you can do standard things like

K ⊆ A

or

O(n²)

anyway. And <sub> and <sup> are whitelisted, so you can even do more complicated things like

k1,…,n

or

eɣ2n-1

14
  • 27
    that seems way more complicated doing O(n<sup>2</sup>) than O(n^2) for the same thing...
    – tzenes
    Commented Feb 23, 2010 at 5:09
  • 2
    @tzenes: Pick your examples right. O(n^2) is still more than O(n²). But again, I love Latex, and I wouldn't have a problem with it being implemented on SO. I just feel that the work necessary to do that isn't justified by the few times this is actually needed.
    – balpha StaffMod
    Commented Feb 23, 2010 at 8:04
  • 2
    Well I came onto this subject when writing this answer: stackoverflow.com/questions/2315987/… It took me a long time to get all the tags right, especially considering how much easier latex would have been...
    – tzenes
    Commented Mar 11, 2010 at 4:20
  • 1
    Expressions featuring summation, integrals, products, roots ... would be nice examples. E.g. ∑<sub>i=0</sub><sup>n</sup> just doesn't look right. I don't know wether it justifies the work for the few questions that need it though. Commented Aug 4, 2010 at 18:52
  • 5
    About justifying "the work" that'd need to be done - since mathoverflow has it working perfectly, it seems like it would be a simple matter
    – Claudiu
    Commented Mar 6, 2011 at 17:52
  • 1
    @Claudiu: Yes, it's done client-side via JavaScript. This requires every single user visiting the site to download gigabytes of JavaScript (okay, slightly exaggerating) for something that's interesting for at most a tiny amount of posts.
    – balpha StaffMod
    Commented Mar 6, 2011 at 17:57
  • 4
    While this is a fair suggestion, I'd certainly rather have people download excess code than suggest that people learn to use Unicode for formatting. Wasting a few bytes for some users isn't quite the same as wasting brain cells. Nonetheless, mentioning Unicode points to gradual evolution in browsers, and perhaps a future version of HTML or browsers will make this question irrelevant.
    – Iterator
    Commented Nov 18, 2011 at 21:53
  • @balpha can you provide a link on how to use <sub> etc and also how do you generate the unicode characters?Through a char-map and then copy and paste or is there some nice shortcut?
    – Dan
    Commented Jan 14, 2014 at 10:51
  • @Iterator, yep. It's called MathJax ;-)
    – vonbrand
    Commented Apr 26, 2014 at 15:17
  • 1
    There isn't any "work" involved. They already have it working on every other stack exchange site
    – endolith
    Commented Sep 11, 2018 at 15:31
  • @endolith Note that this answer is from 2010.
    – balpha StaffMod
    Commented Sep 11, 2018 at 15:47
  • 2
    This is a nice answer, although math typography is a bit more than just having the right symbols. It's also about choosing the right font and laying it out correctly. While the results as shown here may be acceptable, they look like crap :( Commented Jan 28, 2021 at 20:52
  • @balpha I understand your point, but this logic: “I just feel that the work necessary to do that isn't justified by the few times this is actually needed”, can be used to remove bold or italic from current editor, because they are way less used than source code. Sometimes is not about statistics but just to provide a complete or better solution to a problem or existing limitation. Since LaTeX creation it hasn’t being a better solution for typing math. I don’t need it every day, but it sucks not having it when you need it.
    – David Leal
    Commented Nov 25, 2022 at 14:46
  • It's really not fair to make an argument about how something, which is impossible to do without first being implemented, isn't used so shouldn't be implemented. It's circular logic. Obviously it would be used if it were implemented, seeing as though the lack of LaTeX is still being complained about 13 years later.
    – aiootp
    Commented Aug 12, 2023 at 2:21
26

It would be fantastic to have this. There are times when a statistical programming question arises where either Stack Overflow or Cross Validated would be an appropriate site (maybe Stack Overflow will have the edge), but I would rather see it on Cross Validated simply, because one can have LaTeX formatting.

The use case is pretty simple: Joe comes along with a question about how to do X in R (or MATLAB, Python, whatever), and there's an issue with his math and his implementation. For example: the two don't match. Another scenario is that of this question, where we could Q&A on the mathematical inverse, and a good way to code the transformation. It is irritating to address the mathematics within an environment where the formatting support is weak. Both sites (Stack Overflow and Cross Validated) have adequate support for presenting code, so the winner is the site that supports the formatting of mathematics. The same is true for $\textrm{computational math} \setminus \textrm{statistics}$ and the Stack Exchange site Mathematics. ;-)

To that end, I hope that moderators will accept some flags that suggest that a question is better for Mathematics or Cross Validated based on topic, audience, etc. and the ease of answering the question with the available formatting tools.

2
  • works on Cross Validated -- try $\frac{a}{b}$ as well as some others... + see for more examples of MathJax... from editor here can printscreen img of func
    – JeeyCi
    Commented Nov 26, 2023 at 13:57
  • quick examples
    – JeeyCi
    Commented Nov 26, 2023 at 14:25
8

For simple math, you may use this user script. It adds a math bar to the editor for some commonly used symbols:

enter image description here

2

While I think that most questions asked on SO where it would be useful to use math formatting are probably off-topic and more appropriate for CS Stack Exchange, it would still be much easier in many cases just to answer the question on SO than to try and migrate it. I don't see how having the math formatting on SO would conflict with anything else. Some people simply don't know about CS Stack Exchange, and so it is easier to ask a question on SO.

I know I have answered questions on SO where the math notation would have been useful. There are instances where you want to talk about algorithm complexity while working with code in a particular language.

As another note, why the heck can't I get code coloring on CS Stack Exchange? Since CS Stack Exchange is smallish and there is a decent amount of overlap between CS Stack Exchange and SO, I really think we ought to just merge them and support math typesetting in SO.

Basically, BOO to the people that declined to implement this. It shouldn't be hard, since it is already in place on other sites, and it wouldn't really conflict with anything. If I knew more about how the sites worked, I would do it myself.

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