MathML + HTML in Moodle

MathML + HTML in Moodle

by Zbigniew Fiedorowicz -
Number of replies: 20
The Mozilla documentation seems to indicate that MathML is incompatible with ordinary HTML, that rigid adherence to XML+XHTML standards is required in a web page for Mozilla to consent to render imbedded MathML content. Fortunately this is not the case. Thanks to some nifty Javascripts sent to me by Peter Jipsen of Chapman University, it is possible to have Mozilla render MathML in ordinary HTML pages, such as those currently produced by Moodle. Moreover the exact same pages will also have the MathML rendered by Internet Explorer with the MathPlayer plugin. I also note that the installation of MathPlayer and the requisite math. fonts has been greatly simplified in recent releases.

While I have not tried yet to incorporate this in Moodle, I can demonstrate MathML rendering from within the WeBWorK electronic homework system for which I provide an interface in Moodle. To see this go to the following url:
https://webwork2.math.ohio-state.edu/moodle1_2/mod/webwork/view.php?id=2866&username=guest
and check the MathML radio button. Try it with Mozilla or with IE+MathPlayer, and look at the HTML source.
Average of ratings: -
In reply to Zbigniew Fiedorowicz

Re: MathML + HTML in Moodle

by Don Quixote -

Hi Zig,

looks great. I think that MathML will finally be the best solution (for the presentation in the browser), since this is the way of the W3C. Concerning the authoring part it's good to see that Peter Jipsen's javascripts optionally support TeX commands.

The question arises now if you plan to replace soon the mimeTeX filter by these scripts?

Andreas

In reply to Zbigniew Fiedorowicz

Re: MathML + HTML in Moodle

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Hmm ... yes, interesting and tricky hack!

I wish all maths could be implemented in standard browsers using standard MathML, but unfortunately even this nifty javascript solution will only work for the original web page in a Mozilla browser (and not in email etc). Pity.

Still, we have the MathML and TeX plugins for now. big grin
In reply to Martin Dougiamas

Re: MathML + HTML in Moodle

by Zbigniew Fiedorowicz -
No Martin, that's incorrect. This javascript solution works with IE+MathPlayer also, as well as Mozilla.

I think it would not be hard to integrate Peter Jipsen's javascripts into Moodle in such a way that it would work for browsers with or without MathML capability, replacing the current algebra and TeX filters.

Here's a sketch of how it would work. The javascripts would detect if the browser is MathML capable. If it is MathML capable, then some other javascripts of Peter's would convert the imbedded TeX/algebra into MathML. If not, then the javascript would generate an IMG tag calling a Moodle server script, which would generate a gif using mimeTeX, similar to the current filter. Briefly the current filter.php scripts would be replaced by client-side javascripts, calling a server-side pix.php script for non-MathML capable browsers.

In reply to Zbigniew Fiedorowicz

Re: MathML + HTML in Moodle

by Zbigniew Fiedorowicz -
Here's a further thought.  Alternatively the javascripts could work in cooperation with the current algebra/TeX filters. Briefly for MathML capable browsers, the javascripts would convert the filter-generated IMG tags into MathML using the imbedded TeX in the ALT text.  For nonMathML capable browsers, the IMG tags would be left alone.  This has the advantage of working with email too.
In reply to Zbigniew Fiedorowicz

Re: MathML + HTML in Moodle

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Yes, it's areas like email or Opera or Safari that I'm worrying about (IE always had the plugin).  The process mentioned above sounds convoluted though ... if TeX is still required at the source level then what's the advantage converting into MathML?  I suppose it does allow resizing at the client end, but I can't see much else.  For example, it would prevent cut and pasting of MathML code around Moodle ...

And is there in fact a javascript test for MathML capability?  For some reason I think we previously found there wasn't (could easily be wrong on this one).
In reply to Martin Dougiamas

Re: MathML + HTML in Moodle

by Zbigniew Fiedorowicz -
Well Opera and Safari don't support HTML Editor either. They would just rely on the current filters.

The main advantage of MathML would in fact be superior, resizable display of math expressions in MathML capable browsers. While I am hardly knowledgable about Javascript, I think it ought to be possible to copy/paste MathML display, using something like overlib.js.

Also there is the public relations advantage of being able to brag that Moodle supports MathML.

As for MathML detection, Peter has a javascript which he thinks is pretty reliable. An alternative would be some kind of user preference based on which Moodle would decide whether or not to include the TeX-->MathML javascripts in the header.
In reply to Zbigniew Fiedorowicz

Re: MathML + HTML in Moodle

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
What I meant by the cutting and pasting was only with the idea you described above, where the source format was TeX, converted to MathML on the fly by Javascript.

With that scheme as I understood it, you couldn't copy MathML from anywhere, then paste it into a Moodle forum post, because the source code would actually need to be TeX.  This means students would still have to learn TeX.

I'm not dissing the scripts, I'm just trying to point out small problems to help us think about solutions for this tricky client/server situation ... they are most likely surmountable. User preferences are a good idea that will help.

The nice thing about the scheme we hammered out for the TeX filter is that it "just works" in all browsers and HTML-email programs.  I'm of course as keen as you to see MathML support in Moodle but it has to have the same sort of solidity for all sorts of viewer situations.  I'd love to see a MathML->gif filter written 100% in PHP, for example.  wink

In reply to Martin Dougiamas

Re: MathML + HTML in Moodle

by Zbigniew Fiedorowicz -
Well, yes under all the schemes I discussed so far, the original source has to be TeX or algebra (simplified TeX). However the javascripts would convert them to MathML on the fly, and the results could be copied/pasted into some MathML application.

It does not preclude later developing some other method of inputting MathML directly using, e.g. some equation editor addon to HTML Editor.
In reply to Zbigniew Fiedorowicz

Re: MathML + HTML in Moodle

by Peter Jipsen -
As far as Opera is concerned, there is an interesting CSS approach that seems to produce quite good math notation: see http://rmi.acnet.ge/~gch/css/legacy/

As far as I can tell there are at least three areas for formulas on webpages that can benefit from development.

1. Output:

Converting formulas to gifs is certainly the most portable, and has been used on the web for many years. The correct baseline positioning and sizing of the formulas is often difficult, and the printed output is less than perfect, but it ensures that the largest number of users can see the formulas. So it is desirable to keep such a solution as a default, and perhaps allow the user to switch to several other formats that her/his browser might support. MathML would be the recommended format, and the more it is used, the more likely it will be included in future releases of browsers or provided by plugins.

2. Input:

Wysiwyg seems to be what most beginning users prefer (i.e. formulas are constructed by clickinig on templates and symbols). But there are several drawbacks.

There are not many good freely available editors that work uniformly on different operating systems, and the resulting files are often nonportable. Many users prefer the editor they learn to use first, making it difficult to communicate with users of a different editor. It is unlikely that there will be a standard solution anytime soon.

If copied and pasted into email the formulas are seldom readable or familar to the user.

Text with many (small) formulas (e.g. most mathematical text where each variable is a formula) is cumbersome to type since it requires frequent switching between keyboard and pointer device.

So, ascii based formula languages are often a convenient alternative. Variants are part of most computer algebra systems and advanced calculators, but certainly (La)TeX is the most widely used.

Any such ascii language has to translate the 2D formula notation into a one-dimensional character stream, and come up with ways to code many different symbols. Currently Moodle provides an algebra and TeX filter, and there is discussion here to include another recent variant (ASCIIMathML) that partially overlaps both these languages. It would be a good idea to compare and contrast all three and see if there is some concensus that could result in a combined "standard". This would lead to less confusion on the users' side, but perhaps also to less flexibility.

3. Translating from input to output:

3a. Server-side.

Advantages: complete control over server setup.

The user is sent a webpage that (hopefully) works correctly on the client.

3b. Client-side.

Advantages: Less overhead for server.

Can also work offline.

Allows instant dynamic preview (possibly even as the formula is being typed).

I'm currently a complete novice to Moodle, but it looks like a fantastic system. The hard work that has been done to integrate formulas nicely in Moodle is very impressive. If ASCIIMathML (the language) or ASCIIMathML.js (the javascript) can contribute in some small way to this effort, that is great, and I'll be glad to make some required modifications to help in this way. The current version (1.3) has been moved to http://asciimathml.sourceforge.net, and it can be used quite easily on standalone webpages, as well as within wikiservers (there is also a PHP version, see the link on the homepage).

I'm looking forward to reading about other users views on these issues.

-- Peter
In reply to Martin Dougiamas

Re: MathML + HTML in Moodle

by Don Quixote -

Hi Martin,

...if TeX is still required at the source level then what's the advantage converting into MathML?

I believe that many would still prefer entring math. expressions in TeX because (1) they know this syntax (2) it's imo a more comfortable syntax for authoring larger texts than MathML

Maybe a good alternative would be a php wysiwyg math editor (like mathtype) as I mentioned earlier today (see below).

And MathML as the way to deliver math expressions to the browser could have the advantage that it's the preferred standard by W3C. I think that regarding the bandwidth there's only a slight advantage, but the formulas seem to be a bit nicer with MathML (heavily subjective for sure). Also, if the approach is to transfer a javascript along with TeX in ASCII and convert it in the browser it will probably even turn into a disadvantage concerning the bandwidth aspect.

For the php wysiwyg math editor I could maybe help although I am just starting with php (but I have some knowledge in other programming languages like Java, LabView/G, Pascal, js and (rudimentary) in C). But I like constructionism... wink Depends on your plans with this issue.

Andreas

In reply to Don Quixote

Re: MathML + HTML in Moodle

by Zbigniew Fiedorowicz -
Also, if the approach is to transfer a javascript along with TeX in ASCII and convert it in the browser it will probably even turn into a disadvantage concerning the bandwidth aspect.

The javascript would be cached by the client browser.
In reply to Don Quixote

Re: MathML + HTML in Moodle

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
The editor is not really the issue here, though, Andreas ... this is about how Maths should be stored and displayed in HTML pages.

In my ideal world the raw, base format (to be actually stored in the database) would be normal MathML format. There could be various input methods (including TeX) that would convert to MathML, and various filters to transform the MathML into images or whatever is required to get them to work for each user.

There are already plenty of WYSIWYG MathML editors around (and they don't need to be built-in to the editor) that will produce MathML which can be pasted into Moodle, so this is not that urgent.

Now with all that said, I just took a look at Peter's AsciiMath page and I must say the shorthand format there looks pretty impressive as an input method, especially since the scripts also support TeX. However, the TeX support seems rather rudimentary.

It's difficult to see the best way forward - I've confused myself again. smile I'll go work on something else for a while.
In reply to Martin Dougiamas

Re: MathML + HTML in Moodle

by Rudy Scott -

It looks to me like this could be a good candidate the replace the algebra filter (especially if the database format became MathML).  The algebra filter is very neat and I have students who use it a lot, but it does have limitations that come from its history as a Perl function evaluation translator, not an input layer filter.  Did you notice AsciiMath has now been ported to PHP? http://www.jcphysics.com/ASCIIMath/index.php

Also, I think it could be a mistake to underestimate the value of better equation rendering that might come through MathML--especially as a PR tool.

--Rudy

In reply to Martin Dougiamas

Re: MathML + HTML in Moodle

by Tom Murdock -
Can I ask an ignorant question?

Is there a way to create a pop-up screen like the "Use emoticons", that can be filled with teacher/admin selected material? My thought was that the screen could serve as kind of a palette/quickeys tool, where the graphic parts of maths could be listed and selected into non-html windows.

If this were possible, I would be interested in creating other kinds of palettes for the screens my teachers see (items that teachers might frequently use to respond to a student's assignment)...


-Tom
In reply to Martin Dougiamas

Re: MathML + HTML in Moodle

by Pierre Pichet -

Hi Martin,

Porting WebCT UQAM site to Moodle, I am asking: 

"What happen to MathML since your 2004 comment?
Tex is always in Moodle but MathMl seems to have disappeared."

There is nothing in Moodle docs on  MathML and nothing easy to find in forums.

Thanks

Pierre

In reply to Zbigniew Fiedorowicz

Re: MathML + HTML in Moodle

by Yew Hong Ng -
I'm wondering whether there's been any development in this direction? I notice that this thread is more than a year old, has there been no development in this one year? It would really be nice to see Moodle going into MathML, I find that in general it looks better than the gif images currently rendered by the filters. Also, a wysiwyg editor would be nice too.