Some special characters, e.g. *, _ and \ have special meaning in Markdown syntax, but these are also commonly used in TeX equations too. This caused some equations, e.g. \alpha^{-1}_{-1} + \beta_{-1} fails to render properly (see my answer to Math markup, diagrams, etc. — pointers please).

In Math Overflow it is resolved by allowing TeXification in inline code. Since those characters won't be considered special inside backquotes, and we seldom need to write inline code in math, it is perfect for holding TeX equations without changing the backend.

To allow TeXification inside code tag, we just need to edit the config, and remove "code" from the skipTags: config.

Of course, this will make the equation have an ugly gray background. I disagree that all <code> should be made to have a white background, because this makes all code blocks to have a white background on gray background. Instead, I prefer the whiten the <code> only if it contains TeX equation.

In summary, I propose the following change to math-tex.js:

Find the var b=...; line, replace with:

var b='MathJax.Hub.Config({imageFont:null,extensions:["tex2jax.js","TeX/AMSmath.js","TeX/noUndefined.js"],jax:["input/TeX","output/HTML-CSS"],TeX:{noUndefined:{attributes:{mathcolor:"red",mathbackground:"#FFEEEE",mathsize:"90%"}}},tex2jax:{skipTags:["script","noscript","style","textarea","pre"],ignoreClass:"tex2jax_ignore|dno"},});MathJax.Hub.Register.StartupHook("End",function(){$("code > .MathJax").parent().css({"background-color":"transparent"})});MathJax.Hub.Startup.onload();';

This will allow TeXification in <code> tag (at the same time, solve the editing comment problem).

  • $\begingroup$ Can't we regard this as a workaround and not a permanent solution? $\endgroup$ – 97832123 Aug 10 '10 at 19:44
  • $\begingroup$ @978: Since a permanent solution requires changing the backend on a site-specific way, it's harder to do so. Think about the cost-benefit ratio of the all SE sites. $\endgroup$ – kennytm Aug 11 '10 at 18:06
  • 1
    $\begingroup$ This site, the LaTeX site, the stats site, the physics site, the theoretical computer science site, stackoverflow itself would all benefit from proper LaTeX support. It's not all that hard to program it (just modify the markdown module). The nForum (the forum attached to the nLab) has proper support for this, and the person who programmed the hack to the markdown renderer isn't even a programmer (Andrew Stacey over at MO). $\endgroup$ – 97832123 Aug 11 '10 at 22:38
  • $\begingroup$ @978: (1) The workaround I described behaves exactly the same as MO. (2) SO doesn't support LaTeX. (3) How it works on another PHP site is irrelevant. (4) The problem isn't how easy it can be implemented (yes I know it's easy if applied everywhere), but this change invokes site-specific behavior on the server-side in a non-generalizable way. Remember there are sites besides the ones you mentioned. Cooking, webmasters, ubuntu etc. won't need LaTeX support, and surely cannot stop formatting between $ signs. $\endgroup$ – kennytm Aug 12 '10 at 15:57
  • $\begingroup$ Why wouldn't we want to stop formatting between $ everywhere? It doesn't seem to matter much... $\endgroup$ – 97832123 Aug 12 '10 at 20:05
  • $\begingroup$ @978: By "everywhere" I mean the whole SE network. $\endgroup$ – kennytm Aug 12 '10 at 20:37
  • $\begingroup$ @KennyTM: I still don't see how it could possibly be harmful if it's implemented on the whole SE network. $\endgroup$ – 97832123 Aug 12 '10 at 21:47
  • $\begingroup$ @978: You have not used the $ sign as its intended purpose (indicating money), have you? $\endgroup$ – kennytm Aug 13 '10 at 6:17
  • $\begingroup$ I can't see any possible situation where someone is going to be using it for its intended purpose on any SE2.0 site... $\endgroup$ – 97832123 Aug 13 '10 at 12:44
  • 11
    $\begingroup$ @978: Seriously? $\endgroup$ – kennytm Aug 13 '10 at 13:17
  • $\begingroup$ Fine, but I still can't see why it would be so hard to enable it as an option in the control panel for all SE2.0 sites. $\endgroup$ – 97832123 Aug 13 '10 at 15:08
  • $\begingroup$ @Kenny: Can't any such quoting be done automagically so that the user never needs to waste thought on it? $\endgroup$ – Bill Dubuque Nov 2 '10 at 17:51
  • $\begingroup$ @Bill: Too late. If the quoting is done automagically now then all previous LaTeX code worked around by adding a "\ " will be broken. $\endgroup$ – kennytm Nov 2 '10 at 17:56
  • $\begingroup$ @Kenny: But surely there are ways to handle that case too. $\endgroup$ – Bill Dubuque Nov 2 '10 at 19:23

I am marking this , although the this doesn't actually corresponds to the initial request.

Now everything between $...$ and $$...$$ will not be parsed by the Markdown parser on the server side. This only applies for new/edited posts.

$\alpha^{-1}_{-1} + \beta_{-1}$

$\alpha^{-1}_{-1} + \beta_{-1}$

$$\alpha^{-1}_{-1} + \beta_{-1}$$

$$\alpha^{-1}_{-1} + \beta_{-1}$$

Note that preview doesn't reflect the change yet (done). This also won't work in AMS environment such as align (yet?).

\begin{align} \alpha^{-1}{-1} &= \beta{-1} \ \gamma^{-1}{-1} &= \delta{-1} \ \end{align}

\alpha^{-1}_{-1} &= \beta_{-1} \\
\gamma^{-1}_{-1} &= \delta_{-1} \\

\begin{align} \alpha^{-1}_{-1} &= \beta_{-1} \\ \gamma^{-1}_{-1} &= \delta_{-1} \\ \end{align}

\alpha^{-1}\_{-1} &= \beta_{-1} \\\\
\gamma^{-1}\_{-1} &= \delta_{-1} \\\\
  • $\begingroup$ What won't work in an align? $\endgroup$ – Mariano Suárez-Álvarez Nov 11 '10 at 20:03
  • $\begingroup$ @Mariano: Inhibiting the Markdown parsing on server side. $\endgroup$ – kennytm Nov 11 '10 at 20:06
  • $\begingroup$ You are saying text inside $s is not processed by Markdown, except for the parts in align environments? I honestly do not understand what you mean... $\endgroup$ – Mariano Suárez-Álvarez Nov 11 '10 at 20:20
  • $\begingroup$ @Mariano: Originally, $...$ and $$...$$ and \begin{align}...\end{align} and so on are not special, so the Markdown parser will parse text inside them, causing some LaTeX code like $\alpha^{-1}_{-1}+\beta_{-1}$ to fail. Today's change make $...$ and $$...$$ special, so those LaTeX code works from now on. But the other environments are not yet specialized, so those special LaTeX code continues to fail. $\endgroup$ – kennytm Nov 11 '10 at 20:26
  • $\begingroup$ @KennyTM: What do you mean by the "preview doesn't reflect the change yet"? If this breaks the WYSIWYG property of the preview then IMO it introduces a serious problem. It is essential that the preview be precisely faithful to the final rendered text. $\endgroup$ – Bill Dubuque Nov 11 '10 at 22:07
  • $\begingroup$ @Bill: The preview pane doesn't treat $...$ as special yet. Please see Kevin's post I've linked to for detail. $\endgroup$ – kennytm Nov 11 '10 at 22:25
  • 1
    $\begingroup$ @Kenny: Why is the preview different? $\endgroup$ – Bill Dubuque Nov 11 '10 at 23:25
  • $\begingroup$ @Bill: They do not share the same code base. Why don't you comment on Kevin's post? I do not write the code. $\endgroup$ – kennytm Nov 12 '10 at 8:30

You must log in to answer this question.

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