how to process only the non-tex parts of mathml with mathjax?

94 views
Skip to first unread message

Joe Corneli

unread,
Jul 16, 2012, 8:37:00 AM7/16/12
to MathJax Users
We have math in HTML produced by LaTeXML, looking like this:

<math alttext="\widehat{}\;\;:\mathcal{A}\longrightarrow
C(\bigtriangleup)" display="inline">
<semantics>
<mrow><mover accent="true"><none/><mo>^</mo></mover><mo>:</
mo><mrow><mi mathvariant="script">A</mi><mo>⟶</mo><mrow><mi>C</
mi><mo>⁢</mo><mfenced open="(" close=")"><mo>△</mo></mfenced></mrow></
mrow></mrow>
<annotation-xml encoding="MathML-Content"><apply xmlns="http://
www.w3.org/1998/Math/MathML"><ci>:</ci><apply><ci>^</ci><csymbol
cd="latexml">absent</csymbol></apply><apply><ci>⟶</ci><ci>A</
ci><apply><times/><ci>C</ci><ci>△</ci></apply></apply></apply></
annotation-xml>
<annotation encoding="application/x-tex">\widehat{}\;\;:\mathcal{A}
\longrightarrow C(\bigtriangleup)</annotation>
</semantics>
</math>

Our question is: how to get MathJaX to just process the MathML
representations, rather than the LaTeX representation embedded within
the MathML?

An example page is here: http://metameso.org/q/chapter3part1thecalculusbydavisandbrenke

If you load that in Chrome, you see al the LaTeX formulas in grey
before the page is finished rendering.

Right now, we're including

http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=MML_HTMLorMML

along with the following JavaScript:

if (!jQuery.browser.mozilla) {
MathJax.Hub.Register.StartupHook("MathML Jax Ready", function() {
var PARSE = MathJax.InputJax.MathML.Parse;
var oldMakeMML = PARSE.prototype.MakeMML;
PARSE.Augment({
MakeMML : function(node) {
if (node.hasAttribute("type")) {
node.removeAttribute("type")
}
return oldMakeMML.apply(this, arguments);
}
});
});
}

This all seemed to work well until we added the TeX annotations. Any
advice would be appreciated!

Davide P. Cervone

unread,
Jul 16, 2012, 9:34:46 AM7/16/12
to mathja...@googlegroups.com
MathJax IS only processing the MathML. Your configuration file does
not include the LaTeX input jax or preprocessor, and if you check the
MathJax contextual menu on any of the typeset equations, you will note
that the "show math as" option includes MathML and Original MathML,
not TeX, which indicates that the input format used by MathJax was
MathML, not TeX.

The reason you are seeing the TeX code is because the mml2jax
preprocessor's default is to use the alttext attribute as the initial
preview. Since the alttext has the TeX code, you are seeing the TeX
code as the preview (in grey). But it is still the MathML that is
being processed.

You can change the preview using the preview setting in the mml2jax
section of your configuration. For example, adding

MathJax.Hub.Config({
mml2jax: {preview: "none"}
});

would prevent any preview from being inserted. You can also add an
HTML snippet, for example a pointer to an image or the word "MathML"
or something else. See

http://www.mathjax.org/docs/2.0/options/mml2jax.html?highlight=preview:

for details.

Davide

Joe Corneli

unread,
Jul 16, 2012, 9:45:47 AM7/16/12
to mathja...@googlegroups.com
Cool, thanks!

Joe Corneli

unread,
Jul 17, 2012, 6:18:29 AM7/17/12
to mathja...@googlegroups.com
Hi Davide and all:

I adjusted the "preview" setting so the TeX doesn't show up and
instead we see [MathJaX rendering MathML] -- but I also still briefly
see what looks to be slightly garbled MathML code briefly - when
loading my example page,
http://metameso.org/q/chapter3part1thecalculusbydavisandbrenke

(I've also attached a screenshot of that.)

Is there a good way to make this not appear?

Joe
what-you-see.jpg

Davide P. Cervone

unread,
Jul 17, 2012, 6:55:52 AM7/17/12
to mathja...@googlegroups.com
Yes, the browser will try to interpret the MathML when it initially
downloads the content, and will display that before MathJax runs. For
browsers that understand MathML, it will show the math briefly before
MathJax processes it. For those that don't understand MathML, it will
display the text content of the various elements, which will produce
something like the math, but without the formatting of fractions,
roots, etc.

If you want to prevent that, you can use CSS to hide <math> tags:

<style>
math {display:none}
</style>

However, if someone uses the MathJax contextual menu to switch to
NativeMML output, that will also be hidden. To get around that, you
can ask MathJax to disable this stylesheet if the NativeMML output jax
gets used:

<style id="hide-math">
math {display:none}
</style>
<script type="text/x-mathjax-config">
MathJax.Hub.Register.StartupHook("NativeMML Jax Ready",function () {
document.getElementById("hide-math").disabled = true;
});
</script>

This must go BEFORE the script that loads MathJax.js itself.

Davide
> <what-you-see.jpg>

Reply all
Reply to author
Forward
0 new messages