MathML Blogs: How to render MathML in blogs hosted by Blogger

Friday, November 14, 2008

How to render MathML in blogs hosted by Blogger

Many years ago when I came to know about blogs hosted by Blogger, I took great interests to find out if it was possible to post MathML in blog posts. And I tried. But I did not succeed. Not because it was not possible, but because I did not try enough.

I am very convinced now that it would have been possible if I had tried harder. I think I was discouraged after reading many articles and blog posts that it was not possible. I believe that it was probably because most were trying it with the newer templates as opposed to the classic templates. In the newer templates, even though the blog pages are served as HTML, the templates are scanned as strict XML pages and a lot of errors are thrown for use of certain characters or for not closing certain tags.

Also for some reason in the newer templates, some of what one wants to include in the header section are automaticaly scraped and not saved in the templates. I found this out after experimenting with the old classic templates and became successful in displaying MathML. Its so much easier to implement MathML in classics templates. All one has to do include the following in the header section of the template.

<OBJECT ID="MathPlayer" CLASSID="clsid:32F66A20-7614-11D4-BD11-00104BD3F987"> </OBJECT>

<?IMPORT NAMESPACE="m" IMPLEMENTATION="#MathPlayer" ?>

The above code allows Mathplayer to kick in when the blog pages are viewed.

This works great in Internet Explorer with Mathplayer installed.

However, this does not work in Firefox. I have noticed that Firefox is very strict in adhering to rules and standards. But thats too bad. Because a vast majority of web sites fail to meet any html or XML standards.

In order for Firefox to display MathML, the pages must be delivered as XML/XHTML pages and must have specified XSL stylesheets to display any XML content. MathML is an XML application and it must come with XSL stylesheets to display it in some browsers including Firefox.

And unfortunately, the blogs hosted at Blogger are served as HTML pages only and that can not be changed even when the content type in the header is changed to XML. Aparently, the page has already been preprocessed as HTML. I suppose some web servers do not care about the content type mentioned in the headers. They probably associate the content type with file name extension.

But, hey, atleast we can have Internet Explorer display MathML with the help of Mathplayer.

Now, coming to the newer blogger templates where it is so much easy to design the layout, it becomes frustrating to see that the template is not saved with the 'import' directive for the Mathplayer. So, what do you do???

Well I found a little trick by coming across a blog by David Carlisle. He was using a different technique to publish math content in his blogger blog. The technique involves translating plain simple ASCII to MathML by creating the XML doc (math node) the most painful way creating each node, adding each attribute and style and appending to parent node and all that by making calls like createelement, setattributes and all that.

What piqued my interest in David's blog was whether it was using the classical blogger template or the newer 'beta' blogger template. They both look the same till you look at the source code of the page. When I did look at the source code of the page, I found out that it was using the newer beta blogger template and there was no sign of the above mathplayer needed code in the header in a discernable way. So I digged further into the source code and found that the javascript employed by David Carlisle was putting that mathplayer needed code in a 'document.write' statement.

So I tried the document.write technique to insert the 'import' directive which was not getting saved in the new beta blogger template. And, lo and behold, the new beta blogger template comes live with MathML with the aid of Mathplayer.

The javascript that David Carlisle had used is authored by Peter Jipsen. This ASCII to MathML script comes with its own stylesheet to render the MathML. So, it is no surprise that it works with Firefox and probably other browsers too.

It is a nice achievement for Peter Jipsen. However, I find some drawbacks. First of all, the stylesheet is limited compared to David Carlisle's XSL stylesheets. The stylesheet is used by any browser where Mathplayer support is not there like in Firefox. No wonder, it works with Firefox. Secondly and perhaps more importantly, the ASCII to MathML must translate and convert each ASCII mathcode and then it must recreate the XML mathnode for each such instances. For a page with tons of mathcodes, it can significantly slowdown the rendering.

Thus we have two solutions to render MathML in blogs hosted by Blogger.

One is using Peter Jipsen's ASCII to MathML script and posting ascii math code. And, this method works for Internet Explorer and Firefox and probably other browsers too.

And the other is simply posting MathML directly and let Mathplayer take care of the rendering. And Mathplayer does a super job of that. Unfortunately, it works only Internet Explorer only and not with Firefox or Gecko based browsers.

I had been running a BBS (Bulletin Board System) since 1985 and it was called "Mathematics Online" using PCBoard running on original IBM PC with a 4.77MHz Intel 8086 processor with a giant 10MB hard drive. I believe it was in the early 1990's when I switched over to a Windows based BBS software called Excalibur BBS software that had graphical windows interface. The makers of the software never upgraded their Windows 3.1 based software to the 32 bit Windows 95 system and it basically died after folks stopped using BBSes in favor of Internet starting in 1995. There was a nice API for Excalibur BBS software to create addons and I created a ton of it for use in my "Mathematics Online" BBS and also for other BBSes and I made a ton of money selling those addons. Now they are all free to all those who are still using Excalibur BBS software and there are quite a few of them.

I have ported some of my Excalibur math plugins to ActiveX plugins in the past.

A few years ago, I created some server side math plugins to generate MathML documents on the fly. You can check them out at JDS Math Plugins. It works in both Internet Explorer and Firefox. If using Internet Explorer, you must have installed Mathplayer.

No comments:

Post a Comment