# Allow TeXification in <code> tags.

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). • Can't we regard this as a workaround and not a permanent solution? – 97832123 Aug 10 '10 at 19:44 • @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. – kennytm Aug 11 '10 at 18:06 • 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). – 97832123 Aug 11 '10 at 22:38 • @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. – kennytm Aug 12 '10 at 15:57
• Why wouldn't we want to stop formatting between $ everywhere? It doesn't seem to matter much... – 97832123 Aug 12 '10 at 20:05 • @978: By "everywhere" I mean the whole SE network. – kennytm Aug 12 '10 at 20:37 • @KennyTM: I still don't see how it could possibly be harmful if it's implemented on the whole SE network. – 97832123 Aug 12 '10 at 21:47 • @978: You have not used the $ sign as its intended purpose (indicating money), have you? – kennytm Aug 13 '10 at 6:17
• I can't see any possible situation where someone is going to be using it for its intended purpose on any SE2.0 site... – 97832123 Aug 13 '10 at 12:44
• @978: Seriously? – kennytm Aug 13 '10 at 13:17
• 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. – 97832123 Aug 13 '10 at 15:08
• @Kenny: Can't any such quoting be done automagically so that the user never needs to waste thought on it? – Bill Dubuque Nov 2 '10 at 17:51
• @Bill: Too late. If the quoting is done automagically now then all previous LaTeX code worked around by adding a "\ " will be broken. – kennytm Nov 2 '10 at 17:56
• @Kenny: But surely there are ways to handle that case too. – 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}

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


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

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

• What won't work in an align? – Mariano Suárez-Álvarez Nov 11 '10 at 20:03
• @Mariano: Inhibiting the Markdown parsing on server side. – kennytm Nov 11 '10 at 20:06
• 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... – Mariano Suárez-Álvarez Nov 11 '10 at 20:20 • @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. – kennytm Nov 11 '10 at 20:26 • @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. – Bill Dubuque Nov 11 '10 at 22:07 • @Bill: The preview pane doesn't treat $...\$ as special yet. Please see Kevin's post I've linked to for detail. – kennytm Nov 11 '10 at 22:25
• @Kenny: Why is the preview different? – Bill Dubuque Nov 11 '10 at 23:25
• @Bill: They do not share the same code base. Why don't you comment on Kevin's post? I do not write the code. – kennytm Nov 12 '10 at 8:30