Blog 1

Random Talk on Random Thoughts

Escaping '$' in MathJax

| Comments |

Anyone who are used to $\rm \LaTeX$’s $ character$ for switching to inline math mode would like to use the same command for the same thing on MathJax, which suggests the use of backslashed parentheses to enclose an inline math equation. As a result, in the very first part of MathJax’s official documentation, it contains several lines code for that.

After pasting the code inside the <head> tag, the above problem is solved, but this method creates another problem.

Imagine that you want to compare the price of a product of different companies. You then typed two prices on the same line.

1
2
3
4
5
6
<p>...</p>
<br />
<p>Nowadays, it costs nearly $500.  In the past, it only costs around
$300.  It's too expensive!</p>
<br />
<p>...</p>

Then the web browser will interpret the contents in this way:

wrong contents

In order to get the problem fixed, I searched “mathjax escape dollar sign” and found a Stack Overflow question very useful. Following the first answer for the question, I managed to get it right. That is, to change the it like this:

1
2
3
4
5
6
7
<p>...</p>
<br />
<p>Nowadays, it costs nearly <span class="tex2jax_ignore">$</span>500.
In the past, it only costs around
<span class="tex2jax_ignore">$</span>300.  It's too expensive!</p>
<br />
<p>...</p>

correct contents

Comments