MathJax as TeX->MathML converter?

615 views
Skip to first unread message

Max

unread,
Mar 4, 2011, 11:22:15 PM3/4/11
to mathja...@googlegroups.com
Is there a simple process (like a shell script) that takes as input an HTML5 file containing <script type="math/tex"> blocks and outputs an HTML5 file containing MathML?

This would be an intermediate step in document preparation, followed by steps that require the MathML structure (e.g., adding events).

starbuc2

unread,
Mar 5, 2011, 9:23:42 AM3/5/11
to MathJax Users
Max,

Glad to see someone else thinking about this. I'm having good success
with some fairly complex math going from TeX to MathML in MathJax. I
have a test file (with TeX) that I made a copy of and did a "view
source as MathML" on each eq and copied and pasted the MathML to
replace each TeX instance (this took a while with about 400 eqs) into
the 2nd file. I wanted to see the difference in rendering speed if
MathJax didn't have to do the conversion as part of the loading. It is
somewhat faster if you just have MathML. What I'd like to see is some
way of pre-processing the files with MathJax to do the conversion and
place the MathML in with the TeX, thus saving both and allowing the
end-user to have the MathML for faster rendering and also the TeX
source but have the TeX source wrapped with a tag to hide it and not
be processed the next time it is opened. Having both versions might
help "future proof" the data somewhat and give some more flexibility
in later reuse situations.

-David

Davide P. Cervone

unread,
Mar 12, 2011, 12:19:08 PM3/12/11
to mathja...@googlegroups.com
> Is there a simple process (like a shell script) that takes as input
> an HTML5 file containing <script type="math/tex"> blocks and outputs
> an HTML5 file containing MathML?

Not that uses MathJax (that I know of). If you are using something
like Safari, you could use AppleScript to automate it to some degree,
but a browser would still be needed, and that wouldn't work out too
well with your shell script requirement, I would expect. Similarly,
you might be able to use javscript itself to automate the process in
other browsers, though saving the results might be an issue. (I know
that things like TiddlyWiki let you save local files to disk, but I
don't know the mechanism they use.)

There are other TeX to MathML processors that might do more what you
want. Google "TeX to MathML" for links.

MathJax is not really designed to be used as a batch processor for
files in this way. The TeX input processor is all in one place,
however (the MathJax/unpacked/jax/input/TeX/jax.js file) so it might
be possible to pull that out (together with the core libraries from
MathJax.js itself) and either run it in a javascript interpreter
(e.g., rhino) or perhaps convert it to another language like perl or
python. That is not something we are likely to do, however, but we
could answer questions if you wanted to undertake that yourself,
especially if you would contribute the result to the MathJax open
source project in the end.

Davide

Davide P. Cervone

unread,
Mar 12, 2011, 12:31:48 PM3/12/11
to mathja...@googlegroups.com
> I wanted to see the difference in rendering speed if
> MathJax didn't have to do the conversion as part of the loading. It is
> somewhat faster if you just have MathML.

Can you quantify this at all? My experience is that the TeX to MathML
conversion is pretty fast (hardly the bottleneck for MathJax), but I
haven't actually separated it out to see exactly what it costs. Also,
the code for the MathML input processor is smaller than that of the
TeX input processor, so you might be counting the download time for
that as part of your conversion time. While that may be reasonable in
the sense that the user does have to wait for that, it is not really
the conversion that is the cause in that case.

> What I'd like to see is some
> way of pre-processing the files with MathJax to do the conversion and
> place the MathML in with the TeX, thus saving both and allowing the
> end-user to have the MathML for faster rendering and also the TeX
> source but have the TeX source wrapped with a tag to hide it and not
> be processed the next time it is opened.

There is no current mechanism for that now, but it is something to
consider for the future.

As you probably know, even with the TeX source, the user can have
MathML output for fast rendering (by selecting the MathML renderer in
the settings item of the MathJax contextual menu). You can also
configure your page to select that automatically when the browser
supports MathML. So the only real advantage to this is the slight
speed gain by not having to do the TeX conversion in the browser. I'm
not sure it's worth it (note also that your HTML pages will become
much longer with the additional MathML, so will take longer to
download, which somewhat offsets your savings).

> Having both versions might
> help "future proof" the data somewhat and give some more flexibility
> in later reuse situations.

OK, I can see that.

Davide

Scott Morrison

unread,
May 11, 2011, 12:28:52 AM5/11/11
to MathJax Users
I have MathJax running in phantomjs (this is a headless build of
WebKit). I'd like to use this to do server-side LaTeX to MathML
translation (we're already committed to using MathJax client side, so
it's a huge help if we can avoid using another library on the server
side; hence wanting to use MathJax without a browser).

I've run into a very simple problem --- how do I detect when MathJax
has finished processing a page? Is there some variable I can poll? If
not, could someone post a code snippet showing how to register a
callback function?

best,
Scott Morrison

Davide P. Cervone

unread,
May 11, 2011, 11:41:45 AM5/11/11
to mathja...@googlegroups.com
> how do I detect when MathJax
> has finished processing a page? Is there some variable I can poll? If
> not, could someone post a code snippet showing how to register a
> callback function?

You use the MathJax.Hub.Queue method to run a command that signals you
in whatever way you need. It will not be run until after MathJax has
finished all the other queued functions (which includes the initial
typesetting run). For example

MathJax.Hub.Queue(function () {
... (Your code here -- it won't run until after MathJax has
finished typesetting) ...
});

See

http://www.mathjax.org/docs/1.1/queues.html#the-mathjax-processing-queue

for more details, and

http://www.mathjax.org/docs/1.1/synchronize.html

for more about synchronizing with MathJax in general.

Davide

Reply all
Reply to author
Forward
0 new messages