11

This post is to help people who absolutely need mathematical notation on their questions / answers, to point out my method of doing so, given Stack Overflow's reluctance / inability to support MathJax (heavily discussed elsewhere on meta) (and for the consideration of the Stack Overflow developers as an alternative to MathJax). This method is by no means 'at the click of a button', but it looks as good as MathJax 'on-paper', and is fast enough once you get the hang of it.

I use it as a workaround whenever I need LaTeX math on Stack Overflow (which is a lot more often than people seem to think, and finding out how many other users feel the same is difficult).

The downside of this method is that it relies on an image to an external link, but presumably if one uses Stack Overflow's own image generating facilities, then this is a safe enough way to do it that doesn't risk having the image deleted.

An example that uses this method.

Would this method bypass the MathJax debacle enough, while being a decent workaround to interest an SO developer enough to create a bespoke editor button for the specific creation of LaTeX equation images in this manner?


Step 1 : Generate an image of a LaTeX equation

Arguably this is the most difficult step if one does not have such facilities.

One way to do this is using online facilities like Codecogs' online LaTeX equation editor to generate an image. You could then link to this, or preferably save the image and upload to Stack Overflow, using the "Insert image" facility in the editing window.

However, best is to quickly render the equation in Anki, then to click on "Insert Picture" here, and drag and drop the generated LaTeX image directly from the Anki screen to the drag-and-drop-enabled box here. To do this in Anki, create a temporary deck, and create a temporary card in it and save it; this will act as your LaTeX sandbox for whenever you need to generate a LaTeX image.

Now find that card from Anki's "Browse" mode and click on "Preview". You can preview LaTeX equations live as you type them. To create a LaTeX image, wrap your LaTeX code in [latex] ... [/latex] tags. So, to generate the following image:

[latex] $$ \int _ a ^ b x ^ 2 \, \mathrm {d} x $$ [/latex]

you would type the following code in Anki:

[latex] $$ \int _ a ^ b x ^ 2 \, \mathrm {d} x $$ [/latex] 

You can then click on the "Insert image" button here, and drag and drop the generated image straight from the Anki preview box into the "Upload image" box here.

Step 2 : Upload and edit

Once you've uploaded the image, Stack Overflow will include a markdown image link, and a reference below. Unfortunately, for our purposes this is the wrong format, and we will need to use a standard <img> tag instead. Copy the image URL that was generated by Stack Overflow, remove all the image-related markdown, and create your own image tag. This enables you to also add your preferred height (which is usually critical to control the size, especially when you want to use this image inline), and also to add alt and title tags to hold your LaTeX code, since it may be important for users to see / obtain the LaTeX code that generated this.

Using the integral example from above, your code should go from:

[![enter image description here][1]][1] [1]: https://i.sstatic.net/rIIMt.png 

to something like:

<img src="https://i.sstatic.net/rIIMt.png" height="50" alt="[latex] $$ \int _ a ^ b x ^ 2 \, \mathrm {d} x $$ [/latex]" title="\int _ a ^ b x ^ 2 \, \mathrm {d} x"> 

I have used the full Anki LaTeX tags for the alt text, and just the LaTeX code for the title text. Hover on the image above to see the tooltip in action! Or, to view and copy the full Anki LaTeX code held in the alt tag, right-click on the image and click on "View image info" (or whatever it's called on your browser).

Step 3 : Using for inline math

Sometimes you need to use inline math in the text, e.g. to talk about [latex] $$ O ( 2 ^ n ) $$ [/latex] algorithms. If you create just the image tag, even with the right height (here I chose height="18"), the image isn't centered properly, and appears above the text baseline: [latex] $$ O ( 2 ^ n ) $$ [/latex]. Therefore, for inline use you need to wrap your <img> tag further with <sub> and </sub> tags. You can have your <sub> tag appear on its own line, making the page somewhat easier to read during editing. For example, the above inline sentence will look like this:

Sometimes you need to use inline math in the text, e.g. to talk about <sub> <img src="https://i.sstatic.net/Q87NV.png" height="18" alt="[latex] $$ O ( 2 ^ n ) $$ [/latex]" title="O ( 2 ^ n )"> </sub> algorithms. 
14
  • 6
    Shouldn't you ask a question here, for example: "How can I include LaTeX math in posts without MathJax?" and then put your complete "question" into an answer? IMHO, that would better fit out Q&A style... Commented May 29, 2017 at 11:59
  • @honk perhaps, but I intended this post to be a discussion post. I'm proposing my method for the benefit of future users who have the exact same problem, and I'm hoping for comments / answers below to contribute to the discussion on whether this is useful or not, whether it could be improved, whether the external dependency is a no-deal even if it is internal to SO's imgur facility, whether a bespoke tool implementing such a solution is a more acceptable solution by the SO devs than the MathJax debacle, etc. Commented May 29, 2017 at 12:10
  • However, if "Question is not in the form of a question" is a cause for some inane close-reflex here, then I'm happy to rephrase, although I feel this completely destroys the point of such a meta post. I'm under the impression that meta is a suitable place for discussion. (it even has a bespoke tag for it). Commented May 29, 2017 at 12:12
  • 2
    Discussions still need to ask a question. That's how we know what we're supposed to be discussing. It isn't simply an inane close-vote reflex. I honestly have (had?) no idea what this "question" was asking of the community. Commented May 29, 2017 at 12:16
  • @CodyGray very well. I will edit to emphasize the feature request aspect of the question if you wish, so that it requests a specific answer. This converts the question into a "does this interest anyone enough to add it as a feature" (presumably the answer is "no"), while still hopefully remaining on the site as useful information to future users with the same issue. I would find it incredibly sad if a detailed solution to a common problem here was close-voted into obscurity because it failed to be written in a "technically" appropriate, but effectively less useful format. Commented May 29, 2017 at 12:21
  • 3
    @TasosPapastylianou: Sorry for my misunderstanding. I found your title starting with "A method for users..." a bit misleading. Only after your edit it became clear to me that a developer of SO is required to realize your suggestion. Maybe you could clarify this in the intro. Currently your question reads to me like: "Hey user, forget about MathJax, I have a workaround on SO for you!" Commented May 29, 2017 at 12:50
  • 2
    @TasosPapastylianou: I wouldn't say 'enhance'. I'd say 'clarify' ;) Commented May 29, 2017 at 12:59
  • I'm aware people don't need to explain their downvotes, but I'm honestly surprised my question is deemed to be "lacking research effort, be unclear, or not useful". Would someone downvoting mind explaining what kind of further research effort, clarity, or usefulness they would like to see so I can improve the wording? Commented May 29, 2017 at 14:32
  • @TasosPapastylianou As Eric indicated, Meta votes have different meanings than votes on the normal site. If you're making some kind of proposal (e.g. a feature request), voting indicates agreement or disagreement, not necessarily question quality. For example, I upvoted because I agree with this and want to see it implemented. Commented May 29, 2017 at 18:17
  • @EJoshuaS thank you. Alas, this is why I was initially against phrasing this as an outright feature request but as a discussion instead. Now instead of voting whether the topic is useful or not, we're voting on whether we'd like to see yet another "button" implemented or not, which was not necessarily the focus I was hoping for. But unfortunately the original format of the question triggered all sorts of knee-jerk reflexes. I hope people who'd search meta hoping to find a method like this one won't be pushed away from all the downvotes from people who just "didn't want yet another button" :( Commented May 29, 2017 at 23:33
  • 1
    The inline behaviour without extra <sub> and </sub> tags doesn't act like you say (now). Commented Aug 24 at 14:04
  • 1
    Either present a workaround discussion (is this a good workarond, or, self-answered how can I do X) or request a feature (should devs add a certain button). This post is an unclear mix of both. The feature request is (a special case of) a (declined) duplicate. Commented Aug 24 at 14:32
  • Also, those LaTeX PNGs don't look good in the dark theme. OTOH, SVG can work in both light and dark themes, (depending on the browser). I have an example here: meta.stackoverflow.com/a/412802/4014959 Commented Aug 25 at 3:37
  • 2
    @philipxy "This post is an unclear mix of both". I agree; this is partly due to how the post evolved (i.e. based on requests for changes to make it 'sound' like a question, or direct changes applied from others not in the spirit of the original post). The original post was probably more like what you suggest. In any case, this is a 7 year old post, I was surprised to see a comment here again! (and also surprised to see how riled up I got back then over this discussion and the other one linked in the post! 😱) Commented Aug 25 at 9:21

1 Answer 1

-1

Modern browsers all now support MathML. Can it now be enabled in stack exchange sites?

1
  • 5
    This is different from what the question is talking about, it would be better for this to be a separate feature request (posted as a separate question). In fact there already is a request for it here Commented Aug 22 at 13:10

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.