processEscapes not working

50 views
Skip to first unread message

Davide P. Cervone

unread,
Mar 29, 2011, 2:27:10 PM3/29/11
to mathja...@googlegroups.com
This was originally posted to the old SourceForge user forums at


but those are not closed, so I've copied it here. Hope the formatting comes through to the google group OK. If not, I'll repost.

Davide

_________________________________________________________________


We are attempting to get processEscapes working in order for our users to be able to use $ in a post by escaping \$. We are using the following configuration loaded via JQuery: (function () { var script = document.createElement("script"); script.type = "text/javascript"; script.src = "/Content/Js/third-party/mathjax/MathJax.js?config=TeX-AMS_HTML"; var config = 'MathJax.Hub.Config({' + '"HTML-CSS": { preferredFont: "TeX", availableFonts: ["STIX","TeX"], imageFont: null, preferredFont: "TeX" },' + 'extensions: ["tex2jax.js"],' + 'tex2jax: { inlineMath: [ ["$","$"], ["\\\\(","\\\\)"] ], displayMath: [ ["$$","$$"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno" },' + 'TeX: { noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } } }' + '});' + 'MathJax.Hub.Startup.onload();'; if (window.opera) { script.innerHTML = config } else { script.text = config } document.getElementsByTagName("head")[0].appendChild(script); })(); Even when escaped \$ appears to be rendered via MathJax. Our control phrase is: "if ten apples cost \$5.00 and six oranges are for \$3.50, how much is ..."You can find this test here: http://meta.math.stackexchange.com/questions/403/texification-is-too-aggressive-or-how-to-enter-a-dollar-sign/1863#1863


Davide P. Cervone

unread,
Mar 29, 2011, 2:42:15 PM3/29/11
to mathja...@googlegroups.com
I'm wondering if there is a timing problem with the dynamically inserted MathJax.  One thing that might be it is that you don't need the extensions array since tex2jax is already included in the configuration that you have specified.  I really shouldn't be a problem, but I wonder if the preferences sometimes get reset this way.  (You also have preferredFont: "TeX" twice, but that is not a problem.)

I have been able to reproduce the problem described with Firefox (reloading produces inconsistent results) and will see what I can do about tracking it down.

Davide

Geoff Dalgas

unread,
Mar 29, 2011, 9:58:27 PM3/29/11
to MathJax Users
These are good changes - I have removed the extensions array and the
duplicate preferredFont which will go out in a build tonight. I'm
glad to hear you can reproduce this issue and let me know if there's
anything you'd like me to try to help narrow this issue down.

On Mar 29, 11:42 am, "Davide P. Cervone" <d...@union.edu> wrote:
> I'm wondering if there is a timing problem with the dynamically  
> inserted MathJax.  One thing that might be it is that you don't need  
> the extensions array since tex2jax is already included in the  
> configuration that you have specified.  I really shouldn't be a  
> problem, but I wonder if the preferences sometimes get reset this  
> way.  (You also have preferredFont: "TeX" twice, but that is not a  
> problem.)
>
> I have been able to reproduce the problem described with Firefox  
> (reloading produces inconsistent results) and will see what I can do  
> about tracking it down.
>
> Davide
>
> On Mar 29, 2011, at 2:27 PM, Davide P. Cervone wrote:
>
>
>
>
>
>
>
> > This was originally posted to the old SourceForge user forums at
>
> >    https://sourceforge.net/projects/mathjax/forums/forum/948701/topic/44...
> > You can find this test here:  http://meta.math.stackexchange.com/questions/403/texification-is-too-...

Geoff Dalgas

unread,
Mar 31, 2011, 12:54:36 AM3/31/11
to MathJax Users
Another note - we have switched to using more of an inline include:

<script type="text/x-mathjax-config">

MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX",
availableFonts: ["STIX","TeX"] },

tex2jax: { inlineMath: [ ["$","$"], ["\\\\
(","\\\\)"] ], displayMath: [ ["$$","$$"] ], processEscapes: true,
ignoreClass: "tex2jax_ignore|dno" },

TeX: { noUndefined: { attributes:
{ mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } } },

messageStyle: "none"

});

</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/
latest/MathJax.js?config=TeX-AMS_HTML"></script>

We are still experiencing random results w/r/t using: /$

Davide P. Cervone

unread,
Apr 9, 2011, 4:10:17 PM4/9/11
to mathja...@googlegroups.com
Geoff:

I finally figured out what is going on, here. It turns out that your
startup code not only loads MathJax, but also queues a call to
MathJax.Hub.Typeset. That means the page is typeset twice. Normally,
that is not a problem, as the second pass will not find any new math.
But the Typeset method calls both the preprocessors and the output
processor, and that means tex2jax runs over the page a second time.
That may not sound like a problem, but in the case of escaped dollars,
it is. Why? Because the first pass unescapes them (to turn them into
normal dollar signs) and the second then FINDS those dollars and uses
them as delimiters. Whew!

Anyway, the solution is to have tex2jax arrange things so that the
previously escaped dollars are not treated as delimiters on the second
pass. That can be done by having tex2jax enclose the dollars in a
<span> for example, which will prevent the next pass from matching it
with another dollar sign (since tex2jax requires the two delimiters to
be in the same parent element).

I haven't fixed tex2jax yet, but thought I would let you know what the
problem is. It was a challenge to isolate this one (especially since
I was taken down several blind alleys), but it should not be hard to
fix.

Davide

Geoff Dalgas

unread,
May 26, 2011, 12:50:56 AM5/26/11
to MathJax Users
Davide,

Has there been any forward motion on this as far as a fix? In order
to render MathJax on our site I am following the documentation listed
here: http://www.mathjax.org/docs/1.1/typeset.html

which does require MathJax.Hub.Queue(["Typeset", MathJax.Hub]);

We are now using MathJax from the CDN so any fix deployed there should
fix our network of sites immediately.

Thanks for any info!

Davide P. Cervone

unread,
May 26, 2011, 8:33:03 AM5/26/11
to mathja...@googlegroups.com
I have a fix for this, and it should be in the 1.1a update, which is
in final testing, and that we will be putting out shortly. It will
become part of the mathjax/1.1-latest and mathjax/latest versions on
the CDN, so as you say, it should take care of your network as soon as
it is deployed.

Davide

Reply all
Reply to author
Forward
0 new messages