2
\$\begingroup\$

I would like to add some math to a question and the easiest way to do this in math.stackexchange.com is to use LaTeX. However it seems codegolf doesn't support this and I understand it is a pain to add MathJax support.

Given that, what is the best workaround? It would be great if there were "best practice" document which gave explicit instructions for how to insert LaTeX. It seems you have to make images and include them but it's not even obvious to me how to make the images in the right size/shape, how to include them inline and so on.

\$\endgroup\$
4
\$\begingroup\$

The two easiest methods are by using the unicode characters, or by taking screenshots of rendered LaTeX. Here's how the second can be done:

  1. Go to math.stackexchange or some other LaTeX rendering site.
  2. Type out your LaTeX
  3. Take a screenshot. If you use Windows, Snipping Tool is very useful. Here's an example: enter image description here Make sure your screenshot is localized on the rendered LaTeX.
  4. Now you can upload it to your Question / Answer by Ctrl+G

Unfortunately, if you just paste it inline, this is what happens: $$\int_0^\infty x^\frac12dx$$.

Not very nice. But this does work well for non-inlined LaTeX. We can make it slightly nicer by surrounding the image in 3 <sub>; <sub><sub><sub>![$$\int_0^\infty x^\frac12dx$$][3]</sub></sub></sub> produces: $$\int_0^\infty x^\frac12dx$$. Any additional <sub> tags do not make the image lower.


Also note: when you use Ctrl+G, you get ![enter image description here][2]. It would be helpful for you to change the description to the LaTeX used to produce the image, so that if the image ever goes bad, the equation can be recreated.

\$\endgroup\$
2
\$\begingroup\$

An alternative to taking screenshots of rendered TeX, is to abuse the Google Charts web interface. To use the same example as Quincunx:

http://chart.googleapis.com/chart?cht=tx&chl=\int_0^\infty x^{\frac12}dx

The cht=tx parameter specifies to render as TeX, the chl parameter is the input. The dialect is slightly different; note, for example, the enclosing braces around {\frac12}. Although the above URL works fine, SE won't recognize it as a valid link unless it is URL encoded. You can either make a script for this, or use an online tool.

Then insert:

![][1]

[1]: http://chart.googleapis.com/chart?cht=tx&chl=%5Cint_0%5E%5Cinfty+x%5E%7B%5Cfrac12%7Ddx

Which produces:

Admittedly, fairly ugly. This can be prettied up by subscripting the intervals:

\int_{_0}^{_\infty}x^{\frac12}dx

Or repositioning them with \limit:

\int\limit_{_0}^{_\infty}x^{\frac12}dx

You get the idea. It's not an ideal solution, but I find it preferable to pre-rendering, taking a screenshot, cropping, exporting, and then uploading. The output also inlines reasonably.

\$\endgroup\$
  • \$\begingroup\$ The problem is that something like \left\{x^4-x^2-x-1,x^4-x^3-x-1,x^4+x^3-x-1,x^4+x^2-x-1,x^4-x^3-x^2-1,x^4+x^3- x^2-1,x^4-1,x^4-x^3+x^2-1,x^4+x^3+x^2-1,x^4-x^2+x-1,x^4-x^3+x-1,x^4+x^3+x-1, x^4+x^2+x-1,x^4+x^3-x^2-x,x^4-x,x^4-x^3+x^2-x,x^4-x^2,x^4-x^3,x^4+x^3,x^4-x^ 3+x^2,x^4+x^2,x^4+x^3+x^2,x^4-x^3-x^2+x,x^4+x,x^4+x^3+x^2+x,x^4-x^2-x+1,x^4- x^3-x+1,x^4-x^3+x^2-x+1,x^4-x^3-x^2+1,x^4+x^3-x^2+1,x^4+1,x^4+x^2+1,x^4-x^2+ x+1,x^4+x^3+x+1,x^4+x^3+x^2+x+1\right\} fails. \$\endgroup\$ – user9206 Jun 2 '14 at 16:46
  • \$\begingroup\$ @Lembik Yes, the maximum input length is 200. I'm not sure whether the other links listed in the comments below the original post have similar limitations or not. \$\endgroup\$ – primo Jun 2 '14 at 17:07

You must log in to answer this question.