TeXification is too aggressive, or “How to enter a dollar sign?”

The current TeXification function is too aggressive. The current behavior is that,

1. any text between two dollar signs in a single element will be formatted as a TeX formula.
2. this excludes any elements in <head>, <script>, <iframe>, <style>, <title>, <meta>, <textarea> and <object>.

However, this simplistic matching algorithm

1. causes TeXification in unsuitable places, e.g. inside code blocks

like $this$


while it's rare to write code here, it is still usable for ASCII art.

2. makes it impossible to use a raw dollar sign. Not even &#x24; works. In MathOverflow we can escape a dollar sign by prefixing a backslash (＼＄), but even this won't work here.

To see the mess it caused, see https://math.meta.stackexchange.com/questions/398#398.

Problem 1 can be fixed simply by also excluding the <pre> element in Behavior 2, just like MathOverflow. To solve problem 2, the whole goGoGadgetMath() function has to be rewritten, or just use jsMath/MathJax.

We just deployed MathJax 1.1 with escaping enabled, so this should be possible.

Let's see:

"if ten apples cost \$5.00 and six oranges are for \$3.50, how much is ..."

"if ten apples cost \$5.00 and six oranges are for \$3.50, how much is ..."

• Actually, the example you just typed looks broken to me. everything between 5.00 and "are for" are rendered as mathematical text. – Willie Wong Mar 29 '11 at 14:18
• @Willie Wong, it looks ok for me. Chrome 10 on Mac OS X 10.6.6 – mpiktas Mar 29 '11 at 14:20
• @Willie Wong, after submitting the comment the behaviour changed to the one you described. – mpiktas Mar 29 '11 at 14:21
• In Firefox 4, the behaviour is inconsistent. Hard-refreshing sometimes produces math text, sometimes dollar signs. It seems as though, as long as the text is in view when MathJax processes the page, the dollar signs appear as expected. – user856 Mar 29 '11 at 15:20
• I have asked a question in the MathJax forums: sourceforge.net/projects/mathjax/forums/forum/948701/topic/… - hopefully we will get a response soon. – Geoff Dalgas Mar 29 '11 at 17:47
• @Geoff: thanks! JFYI: they moved the discussion over to groups.google.com/group/mathjax-users/browse_thread/thread/… as the development forum is closed now. – Willie Wong Mar 29 '11 at 18:57

Algebra questions may periodically appear, that have multiple dollar signs. Compare:

"if ten apples cost $5.00 and six oranges are for$3.50, how much is ..." [using dollar symbol]

"if ten apples cost USD 5.00 and six oranges are USD 3.50, how much is ..." [avoid dollar signs]

"if ten apples cost \$5.00 and six oranges are for \$ 3.50, how much is ..." [using backslack-dollar]

"if ten apples cost $\$$5.00 and six oranges are for \$$3.50, how much is ..." [render each dollar sign in TeX as dollar-backslash-dollar-dollar] Same for postings of compound interest (loan amortization) calculations or anything with data in dollar currency. Such questions are likely to be posted by people who may not know what TeX is, so some dollar-sign FAQ may be in order. When [processEscapes is] set to true, you may use \$ to represent a literal dollar sign, rather than using it as a math delimiter. When false, \$ will not be altered, and the dollar sign may be considered part of a math delimiter. Typically this is set to true if you enable the $ ... $ in-line delimiters, so you can type \$ and tex2jax will convert it to a regular dollar sign in the rendered document.

Is there a reason this option is not enabled? T..'s other workaround of rendering a dollar symbol inside the TeX (using dollar-backslash-dollar-dollar) is quite non-obvious.

Now MathJax is deployed, problem 1 no longer exists, but it still TeXify in unnecessary places (see Editing a question containing formulae will remove the formulae).

The dollar sign can be escaped with \\$, but the leading \ should not present.