ASCIIMathML packages, fallback and SVG

ASCIIMathML packages, fallback and SVG

by Nicola Vitacolonna -
Number of replies: 27
Dear all,
sorry if my problem is trivial, but I am new to the topic and I am a bit confused about the several packages that can be found here and there.

I want to be able to type equations with (La)TeX syntax and have them rendered as MathML when supported by the browser, as images otherwise. I am using Moodle 1.9.5.

Now, I've found two main references: the Moodle Docs page (http://docs.moodle.org/en/ASCIIMathML) and the ASCIIMathML page (http://www1.chapman.edu/~jipsen/mathml/asciimath.html). They point to different versions of the same (?) packages. The first question is: which should I use? Either

http://sourceforge.net/project/showfiles.php?group_id=106148
plus
http://moodle.org/file.php/5/moddata/forum/130/483519/ASCIIMathML2wMnGFallback.zip

from Moodle Docs, or

http://www1.chapman.edu/~jipsen/mathml/asciimath.tar.gz
plus
http://www.pierce.ctc.edu/dlippman/asciimathtex/ASCIIMathMLwFallback2.js

from prof. Jipsen's page? Do I need to download something else (I don't need plugins for graphical editors)?

So far, I've stuck to the Moodle Docs page. As a first step, I've downloaded ASCIIMathML 2.0.2 from Sourceforge, installed and configured as explained (put inside lib, edited theme/standard/meta.php, etc… ). Everything (math and graphs) is working as expected.

Then, I have replaced ASCIIMathML.js by the fallback script linked from the Moodle Docs page (the file MathML2wMnGFallback.zip). Within the script, I have changed var AMTcgiloc to point to http://latex.codecogs.com/gif.latex and I have left AScgiloc unchanged. Should I change AScgiloc, and if so, how?

I ask, because math is still displayed fine with the fallback script (MathML rendering is even better than the original script – try $\int_0^\infty x$ for example), but graphs (e.g., agraph plot(sin(x)) endagraph) are not rendered any longer. Why is it so?

There's one more piece to the puzzle: ASCIsvg. Is it needed? Is it embedded into ASCIIMathML or has to be installed separately?

As a beginner, I would really appreciate if someone could help me compose my puzzle into a coherent (svg) picture smile

Sincerely,
Nicola
Average of ratings: -
In reply to Nicola Vitacolonna

Re: ASCIIMathML packages, fallback and SVG

by Mauno Korpelainen -

I wish I could but it's a really long story to explain all the points. A short answer is that we have too many versions...

Original scripts by Peter Jipsen do not use image fallback - they render asciimathml as MathML only for such browsers that are capable to show MathML - read: Firefox (or with Math Player plugin other browsers) - and use "old style asciisvg" that IE can't show without (Adobe) SVG plugins.

David Lippman wrote the original fallback scripts and you can in theory use any fallback you want but in practise different distributions of Latex use a little different syntax -  http://latex.codecogs.com/gif.latex is a good option and you could use there png instead of gif as well. If you use that site for fallback  permanently it would be good to inform them...

Asciisvg and "asciisvg fallback" is the more confusing part of scripts. David Lippman is using in http://www.imathas.com/editordemo/demo.html a php script that translates part of asciisvg to gd images for IE and I have demo plugin files using similar script in http://korpelainen.net/plugindemo and http://korpelainen.net/mediawiki

For example Paoplo Soares has nice demos about non fallback asciisvg that require svg cabable browser (Firefox, Opera or Safari or Adobe SVG plugin) in http://www.math.ist.utl.pt/~psoares/MathSVG.html

I was planning to start changing asciisvg code to VML to IE (SVG/VML dual code) because these are both vector graphics and VML would be better than GD graphs for IE but there are many other possible graph renderers too...

In reply to Mauno Korpelainen

Re: ASCIIMathML packages, fallback and SVG

by Marc Grober -
MK,

I had mentioned, backi think when Andy and I were playing with mathtran as fallback, that there might be some utility in providing and array with fallbacks and a timeout. With the availability of google chart API I could see setting this as primary and then falling back to other locations. Maybe separate js called by main if switch set?

Btw, are you using FF build with smil?
In reply to Marc Grober

Re: ASCIIMathML packages, fallback and SVG

by Mauno Korpelainen -

Yes - I have been testing that option to select fallback with config settings that can be set to database with filter or with config.php files. It's actually very simple thing to use filtersettings.php - I will explain it after couple of days...

I'm not sure which is better - to use several fallbacks (with dollars and other characters around notations) for different cases (for example google chart code for roots to avoid Firefox 2 font issues) or to select and set from administration primary fallback, secondary fallback...

Paolo has used jQuery in his asciimathml version and it lead me to use jQuery in my current test plugins too - at first in color picker and then in image drop down list that really can show mathematics and is cross browser compatible even if IE otherwise has no way of showing images in normal selection lists.

And no - I haven't tried smil yet (just checked some examples and have "normal Firefox" ) - but it will be soon available in FF too... and works in Opera and Safari...

In reply to Mauno Korpelainen

Re: ASCIIMathML packages, fallback and SVG

by Nicola Vitacolonna -
Thanks all for replying so fast! That's a lively community! I'm starting to get the picture (not only metaphorically).

After my post, I've tried the pair of scripts from prof. Jipsen's page (with and without fallback). Here are my conclusions from comparing the two versions (let me call "Moodle Docs scripts" the ASCIIMathML version linked from Moodle Docs and "Jipsen's scripts" the ones from prof. Jipsen's page):

1) MathML in rendered identically, and slightly better with the fallback script (whatever version).

2) Jipsen's script with fallback renders 'agraph plot(sin(x)) endagraph' with a white background. Moreover, the graph can be resized with shift-click or alt-click. Moodle Docs script with fallback renders the graph with a transparent background, but the graph cannot be resized. Jipsen's script (without fallback) does the same as Moodle Docs script (without fallback): a non-resizable graph with transparent background.

3) Fallback works the same for math. For graphs, the Moodle Docs script generates a white rectangle, while prof. Jipsen's script produces the error message: "The requested URL /mod/resource/d.svg was not found on this server.".

4) (Minor difference) The fallback script (whatever version) renders math in blue by default, while the original script (whatever version) renders math in black by default. This may tell you whether you're using the fallback script or not smile

Of course, this is not an exhaustive testing, but it suggests that the scripts from prof. Jipsen's page may be a better choice.

I am a bit surprised about the difference in MathML rendering between the script without fallback and the script with fallback…

Nicola

In reply to Nicola Vitacolonna

Re: ASCIIMathML packages, fallback and SVG

by Marc Grober -
WOW! Quite a lot of work!

At the time I posted the Fallback script you are wokring with it was as I recall the script which included fallback with the least bugs and the most functionality.... that may no longer be the case ;=} (I know that the scripts Mauno has been working on far surpass the ones I posted, and I have scripts changes I worked on as wlel that may be seen by some to be incremental to those I posted.....

BUT

it can be tough to try and make everyopne happy at all times in a dynamic world - LOL

AND

for those who are not faint of heart there is SA's website http://asciimathml.com/ as well as the asciimath google group set up by Peter at http://groups.google.com/group/asciimath

One of the issues discussed in the asciimath group was the possible need to "manage" asciimathml vis-a-vis heads, trunks, builds etc because there was so mucgh that so many had done, but no apparent mechanism for reconciliation... that is one reason SA has tried to collect everything at his site, but we still don;t have a real SVN or CVS system to manage asciimathml, nor any real sense of a distro system for it.

Bottom line is knock yourself out! ;=} I am hopeful that my friend Mauno will soon have a production version of SEE to roll out, and I think this will reflect a GIANT step towards client side usage of svg and math notation for teacher and student, but the great thing about asciimathml AND dragmath are that they are easily configurable and extensible (I still think there must be a word extendable as extensible to me has other connotations, oh well....)

The greatest challenge is making use of math graphing and notation transparent and universal (ahhhh, I knew sooner or later I would get back on my soap box) so that from elementary school to college one and all and communicate in math and science. As you will see if you check out the google group, there is quite a bit of opinion about how and were math notation should be parsed, displayed, etc. Things are moving, but as with much of anything human, things can take time, especially when there are such deep felt convictions about such matters. I look at things non-evangelically.... if you use math notations and two or three others see you do that and decide to try it, then eventually we will have "prevailed".

In reply to Nicola Vitacolonna

Re: ASCIIMathML packages, fallback and SVG

by Mauno Korpelainen -

There are quite many settings at the beginning of AsciiMathML script - for example the font color is controlled by var mathcolor...

"I am a bit surprised about the difference in MathML rendering between the script without fallback and the script with fallback…"

In fact you are comparing MathML (depends on selected font) to Latex (gif or png images) and vector graphics (SVG) to pixel graphs (rendered by php and GD as png images). Fallback scripts just try to create something similar for IE that can't use SVG or MathML itself - if we had VML fallback for IE you would not notice a difference between static graphs created with SVG or VML.

The original reason for creating fallback scripts was the need to get rid of Math Player and Adobe SVG plugins that do not produce quality output anyway - but the best way to improve quality is to use Firefox that supports most web standards unlike IE...wink

In reply to Mauno Korpelainen

Re: ASCIIMathML packages, fallback and SVG

by Nicola Vitacolonna -
Sorry, I wasn't clear enough. What I meant is, I would expect that both the script without fallback and the variant with fallback would render *MathML* code (and svg images) the same way in Firefox. This is not the case: look at the attached picture (the results obtained by the scripts from Moodle Docs using Firefox with the same fonts).

Clearly, the script with fallback does not just *add* a feature to the original script (the fallback), but it introduces some modifications to existing features.

Nicola

Attachment test.png
In reply to Nicola Vitacolonna

Re: ASCIIMathML packages, fallback and SVG

by Marc Grober -
Nicola,

quite a few variables here.
A) could you provide the text expression you are using (there are quite a few ways to express something along the lines of what you present)
B) as noted elsewhere, there are diffs between and Tex and latex and among apps that seek to parse and display same. While mimetex is a great fallback in many cases, it has it's own limitations, as does mathtex and mathtran.
C) if you go to EdTech site you will find peters demo table I believe (I should check to make sure ;} ) that will provide extensive display of asciimath with fallback. Mauno's test site had a similar table

on another note, I am still waiting on
my WA apiid..... And between WA and google there are many a new horizon opening...

Re voting, go to tracker.moodle.org and do a search on asciimathml ..... And drop MD a personal note ;)
In reply to Marc Grober

Re: ASCIIMathML packages, fallback and SVG

by Nicola Vitacolonna -
This is what I've typed:


An integral: $\int_0^\infty x^2=1$

A graph: agraph plot(sin(x)) endagraph


I'll take a look at EdTech for sure ;)

Nicola
In reply to Nicola Vitacolonna

Re: ASCIIMathML packages, fallback and SVG

by Mauno Korpelainen -

The problem is most likely in \displaystyle setting.

Using for example mathtran (just testing)

\int_0^\infty x^2  \int\limits_0^\infty x^2 \displaystyle\int_0^\infty x^2 \int\limits_0^\infty x^2

renders 4 different integrals

mathtran?D=1;tex=%5Cint_0%5E%5Cinfty%20x%5E2%20%20%5Cint%5Climits_0%5E%5Cinfty%20x%5E2%20%5Cdisplaystyle%5Cint_0%5E%5Cinfty%20x%5E2%20%5Cint%5Climits_0%5E%5Cinfty%20x%5E2

In reply to Nicola Vitacolonna

Re: ASCIIMathML packages, fallback and SVG

by Marc Grober -
Nicola,

First I want to thank you for taking the time to post a great question. You have not only worked the docs but have detailed the steps you have taken already with clarity and precision. Bravo!

Unfortunately I wish I could be as forthcoming ;)

the version os asciimathml you now have installed is the version in production on my moodles at present. If you look at the file you will see that asciisvg is integrated. It should render most of the asciisvg primitives, though there are some complexities. If you go to edtech.alaskapolicy.net you will find some examples of rendering svg with the same asciimath file.

However, fallback for svg continues to be a challenge. I have posted elsewhere about svg plugins. There are a few available. An old PC on my wife's desk continues to be able to do svg fallback, but employs a dated version of IE and the adobe plugin ;)

Assuming that svg is rendered correctly in FF, then pending Mauno's release of a production version of SEE I would recommend two options: a) get your users off IE, and/or b) search this forum for my post with the urls for the svg plugins still supported (I really do need to put those in the docs, but would need someone to test, so, if you are interested.......)

Marc
In reply to Marc Grober

Re: ASCIIMathML packages, fallback and SVG

by Nicola Vitacolonna -
I see… I think that the situation for SVG is still a bit messy. For now, I'll be happy with the math smile

Btw, it was a pleasant surprise to discover that Moodle comes with a TeX notation filter, which leverages the full power of an underlying LaTeX distribution (a very good solution for complex math with unusual symbols, though the picture quality is not the best).

I wish that Moodle 2.0 will bring in support for MathML without external plugins, in addition to the TeX notation filter!

Nicola
In reply to Nicola Vitacolonna

Re: ASCIIMathML packages, fallback and SVG

by Marc Grober -
Please check as the graininess in your Tex may be from fallback to mimetex ;=}

There is a tracker item to allow you to vote to include asciimathml in Moodle 2

I think there si some resistance to supplanting or providing options to existing Tex filter, though I think it is consistently a major hassle for so many users. I have promoted implementing asciimathml via a theme for moodle docs and moodle.org, and I think that may yet happen, but as you note, when there is such breadth when it comes to responding to, 'what is asciimath and what does it do' that may also result in some hesitancy.....

But, I think the more people exposed the mote people interested. WHile many argue that MathML is still poorly supported, that by itself is not going to increase pressure for MathML. So I invite you to scream your bloddy head off for using MathML in moodle forums and docs ;=}

Of course, there are other solutions as far as implementing MathML (one I like to mentin is LatexML, intially developed by the US NIST) and if there is enough pressure we can gen up another big push............ but I want to use the tools at hand to increase familiarity....

BTW, double clicking on the version I posted provides access to the SVG primitives and I have noticed that this is not always the case as well.


In reply to Marc Grober

Re: ASCIIMathML packages, fallback and SVG

by Nicola Vitacolonna -
I don't want the TeX filter to be replaced or modified. Absolutely. I have tried it and I find it does a perfectly good job, provided that an underlying TeX distribution is used. Please, let Moodle 2.0 will have it unchanged (or, well, improved)!

What I would like to see is a MathML filter in addition to, and possibly with some integration (e.g., for fallback) with, the TeX filter.

The rationale for this is that installing a full TeX distribution on the server sometimes is not an option and MimeTeX, for some purposes, is too weak. That's why I'm hungry for alternatives smile

I will vote for including asciimathml as soon as I find how to do it smile
In reply to Nicola Vitacolonna

Re: ASCIIMathML packages, fallback and SVG

by Mauno Korpelainen -

I like TeX filter too... It's a core filter and will probably remain as core filter for a very long time but it is possible to create also a "modified TeX filter" with another name (let's call it Math filter...) that renders MathML for MathML capable browsers (with AsciimathML script) and works otherwise like normal TeX filter with different characters around notations - it's actually easy, we just need to use browser detection to skip normal TeX filter functions for FF. Another option is to use several fallbacks and some fallbacks can render different problematic cases where others fail.

My own totally unofficial ToDo list has also a new Math filter that could be available next month - "alpha version" is already tested. Before that I will finish Google Chart Api Latex editor plugins (99% ready - check maths forum on Monday if you want to be the first tester before Marc...), then we should add support for other renderers to these plugins (Mathtran, Mimetex, TeX filter, AsciimathML - next week), then might be a graph week (code for Google Charts, filters and AsciiSVG) and after a month we should have a full set of tools for maths in one downloadable package that can be used with all current versions of moodle (1.7-2.x).

In reply to Mauno Korpelainen

Re: ASCIIMathML packages, fallback and SVG

by Bob Mathews -
Is MathJax something that could be of use here? http://www.mathjax.org/ (open source, Ajax-based math display)
In reply to Bob Mathews

Re: ASCIIMathML packages, fallback and SVG

by Marc Grober -
Maybe, but....

My experience is that jsMath can be VERY slow; can a larger app be faster?

The URL talks about mathml in, not mathml out, and the two are very different

mathjax promises to be complex, while I think we need to move in the other direction, but it is hard to talk about an app that is yet to be made available

the website talks about open software but I did not find anything that pointed to beta code to play with

Davide argues that mathml is something to hope for but not to the state where it is a viable technology, yet Davides name is the only name prominently displayed

Here is an early discussion of mathjax in response to promotion of asciimath:
http://groups.google.com/group/google-wave-api/msg/e9a9b8cbb8c27d09

this and other discussion leads me to be wary of commercial involvement, especially by design science who I believe having nothing to gain from open source solutions that render moot their commercial products. I am not doubting Davides bona fides and I am sure any app he is involved with will be top drawer, but this smells a little like current us health care debate and I will be happy to explore what is made available when it is made available.....
In reply to Nicola Vitacolonna

Re: ASCIIMathML packages, fallback and SVG

by Mauno Korpelainen -

It's just waiting in TODO list... and you can improve the quality of Latex with some tiny settings (but not make it faster...):

\alpha

In reply to Mauno Korpelainen

Re: ASCIIMathML packages, fallback and SVG

by Nicola Vitacolonna -
A question for developers: how is fallback to images implemented? That is, given a script like the original ASCIIMathML.js, how do I detect whether the browser supports MathML and how do I dispatch the code to ASCIIMathML.js, or to some other method that generates images, accordingly? You may point me at the relevant parts in your scripts, then I may try to work the rest out by myself :)
In reply to Nicola Vitacolonna

Re: ASCIIMathML packages, fallback and SVG

by Mauno Korpelainen -

Browser detection is rather simple if you know what browser and which versions are supported - different scripts use different ways and it is possible both with javascript and php.

Those scripts basicly test just if browser is Gecko or if it has Math Player installed and if not they use fallback... with tags like

function checkMathML(){
 noMathML = true;
 return null;
 if (navigator.product && navigator.product=='Gecko') {
    var rv = navigator.userAgent.toLowerCase().match(/rv:\s*([\d\.]+)/);
    if (rv!=null) {
  rv = rv[1].split('.');
    }
    if (rv!=null && 10000*rv[0]+100*rv[1]+1*rv[2]>=10100) {
     noMathML = null;
    } else {
     noMathML = true;
    }
    }
  else if (navigator.appName.slice(0,9)=="Microsoft")
    try {
        var ActiveX = new ActiveXObject("MathPlayer.Factory.1");
        noMathML = null;
    } catch (e) {
        noMathML = true;
    }
  else noMathML = true;
 
//noMathML = true; //uncomment to check
  if (noMathML && notifyIfNoMathML) {
    var msg = "To view the ASCIIMathML notation use Internet Explorer + MathPlayer or Mozilla Firefox 2.0 or later.";
    if (alertIfNoMathML)
       alert(msg);
    else return msg;
  }
}

The bad thing in this kind of scripts is that they don't know if some other plugin gives support for MathML or if some other browser suddendy starts to support MathML (you never know when this is going to happen... wink )

In reply to Mauno Korpelainen

Re: ASCIIMathML packages, fallback and SVG

by Mauno Korpelainen -

Another way is to make just browser detection and let Firefox do what it can...and let IE do what you like (use filter or other scripts while Firefox can use AsciiMathML without fallbacks)

Opera and Safari can use (Ascii)SVG like Firefox (or even better)  but they can't use mathML any better than IE at the moment.

In reply to Mauno Korpelainen

Re: ASCIIMathML packages, fallback and SVG

by Marc Grober -
Because the script checks for browser/version, not capability, which is an issue all browser folk should address
In reply to Marc Grober

Re: ASCIIMathML packages, fallback and SVG

by Nicola Vitacolonna -
(Talking only about math, not graphics) Why not factoring out the code that detects the browser and let it decide whether to call a (user defined) MathML renderer or a (user defined) fallback image renderer? All the solutions I've found tightly couple such a “dispatcher” with the renderer. This component should be written once and for all. Separating it from the renderer would allow a user to choose which script to use and a developer to avoid mangling other people's code. And if a better detection method came out, all scripts would benefit from that.
In reply to Nicola Vitacolonna

Re: ASCIIMathML packages, fallback and SVG

by Mauno Korpelainen -

That's exactly what I was planning to do in my coming code (next month?) - if you use FF choose script A for asciimath and script B (or TeX Filter for latexmathml) for other browsers (no matter if they have mathplayer or not...). Choose script C for FF,Opera,Chrome and Safari in AsciiSVG and script D for IE (that could render VML instead of php/GD graphs).

Separation of code is easy for plain symbols - for more complex structures and functions having several arguments or brackets it may be more difficult. Basicly the old code of Peter Jipsen is all what FF needs and fallback parts of David Lippman's code together with missing and new features can be used for IE without loading both code - or without checking of MathPlayer or Adobe SVG player plugins. 

I will add those features to my editor code in http://moodle.org/mod/forum/discuss.php?d=133132

In reply to Mauno Korpelainen

Re: ASCIIMathML packages, fallback and SVG

by Nicola Vitacolonna -
Great! That's really good news!
If I am allowed one more request, I wish that the code for the several scripts will be unified. On reading the release notes of each and every script, you realize that they are derived/merged/extended/included from each other (ASCIIMathML from LaTeXMathML and vice versa, for example), but in an uncontrolled way (it is hard even to determine which code is more recent than another). Although this may have been inevitable in the past – and certainly a sign of active interest in the topic – it seems to me that that the different lines of development are mature enough to be better organized into a single coherent project.

This discussion has been very useful: now, it's time to start preparing some lesson smile

Keep up with your good job!

PS: I would like to see all LaTeXMathML features integrated as well (e.g., support for tabular and figure environments, etc…) smile
In reply to Nicola Vitacolonna

Re: ASCIIMathML packages, fallback and SVG

by Marc Grober -
LoL, yes, there has been quite a bit of discussion in the asciimath group re current and future formats. You can see where asciisvg and latexmathml were pulled into current js but things do bounce around a bit ;). One argument is that each lib get backed out and then gets called as necessary, so instead of one lib approaching 300k you might have 4or 5 smaller libs called as needed. One of the problems is that asciimath community has not really agreed to an asciimath cvs (or perhaps has agreed but has yet to accomplish same) which means that any changes made will continue to be the responsibility of the changer.... Don't know if asciimath will make it over that hump. Biggest innovators at present are SA and MK.

You can also play with latexmathml yourself (I've posted URL for that in a few places here) and you can also explore latexml and blahtex (which don't provide some of the amenities of asciimathml but will render mathml from Tex text expressions (gilles, the fellow responsible for blahtex v0.7 is very helpful)
In reply to Mauno Korpelainen

Re: ASCIIMathML packages, fallback and SVG

by Marc Grober -
What I meant was browser variables that could be queried by js so one could check whether browser does mathml, whether a mathml plugin is set, whether math fonts have been set, whether svg plugin set... Then we can just do a case statement (well the js equiv) and bobs your uncle you are good to go.... Now we don't need to know what browser or version you are using. But that is not going to happen......