Moodle 2.X math plugins

Re: Moodle 2.X math plugins

by Mauno Korpelainen -
Number of replies: 17

For MathJax plugin I decided to hide the whole option to add latex images or tex filter tags if no mathjax fallback is selected in settings of tinymath editor or if convert binary of tex filter is not executable - and in that case users see only 3 options: to add inline maths, display maths or plain notations without delimiters. If fallback url is given they will see also option to add latex images or tex filter tags. If no fallback url is given (default empty) but convert binary is executable plugin will use texviewer script and tex filter files for latex images.

I added delimiters for inline maths and display maths to settings of math filter and both mathjax plugin and scripts in mathstandard theme and stylist theme take those delimiters from settings. This is not yet a perfect solution - for example some email addresses may have @i or @d inside and if that address is given twice on the same page something strange may happen. For more complex delimiter settings it is better to edit script tags directly - now people can for example disable tex filter and change inline math delimiters to double dollars in settings to make mathjax render tex filter tags...

Mathjax

I will check next (tomorrow) the most unfinished part of this package - asciimathml script and plugin. You can update your current files if you want - I updated both packages on my test server some minutes ago and will create that public test site at the end of this week (once asciimathml plugin has some more content inside... wink

Average of ratings: Useful (1)
In reply to Mauno Korpelainen

Re: Moodle 2.X math plugins

by Marc Grober -
Mauno, It is unclear on face of package which one to use if you want to do mathjax cdn but local hubconfig. Also, I suggested to Alfred using cdn for jsxgraph casual users so that might be other option - so, I am thinking reference lib directory for script source and fallback to CDN... That way it works no matter whether you havefiles installed or not.
In reply to Marc Grober

Re: Moodle 2.X math plugins

by Mauno Korpelainen -

I think I'll add the option to use either local MathJax or http://cdn.mathjax.org/mathjax/latest/MathJax.js available in the next update (may take a day or two) - like settings of current geogebra filter is giving 3 options to use http://www.geogebra.org/webstart/geogebra.jar (latest version), http://www.geogebra.org/webstart/3.2/geogebra.jar (version 3.2) or local applet with $CFG->wwwroot.'/filter/geogebra/32/geogebra.jar'

Geonext applet is in version 1.7.3 but I have not seen new development there during the last years so that must be the latest version of applet in lib/geonext. Sadly it's not a complete package, at least some help files are missing (for example lang_fi.jar) and when I looked at the apache error log some missing java utility file might explain this IE behaviour. I have not asket from Alfred yet.

JSXGraph files are in the latest version with one modification (commented out that debugging to enable graphs for IE9 in IE9standards mode) - if you set scripts to use the latest files for example with

<script type='text/javascript' src='http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js'></script>
<script type='text/javascript' src='http://jsxgraph.uni-bayreuth.de/distrib/GeonextReader.js'></script>

 some examples fail in IE9.

If sites need to use moodle offline local files are always better, if they need the latest versions external files can be all the time up-to-date but that can cause also problems for sites like http://cdn.mathjax.org/ - imagine that all moodle sites, WP sites, Drupal sites, Joomla sites... might start to use cdn mathtex some day - no server can handle such amount of http requests, it would make cdn mathjax down like sitmo latex is down now and forkosh site seems to be the only functional public mathtex site now... smile

For moodle sites that are not allowed to install any non-core things or change any settings or permissions (keytoschool etc) the only option to use maths might be some link to an external palette that can be attached to any forum, labels etc

For asciimathml I will most likely set those traditional 3 types of fallback scripts (in AMMathtex.php for texlive type syntax, AMMimetex.php for Mimetex/Google Chart api tex and AMMathtran.php for Mathtran/old style Tex - only AMMathtex.php is now available in my package file - and one of these files will be loaded as a part of AM.php according to selection in settings) but we could use also mathJax fallback for pure LatexMathML already without any browser detections or mathML plugins (latexmathml script must be first and then MathJax renders mathML for all browsers). So we need again more settings there to choose which options to use - in AM scripts I had 2 fallbacks AMTcgiloc (MathML in FF) and Gemcgiloc (fallback also in FF to force latex)...

In mathml I have noticed one major problem - it is easy to add math tags inside math tags and then mathjax throws errors so ideally mathml should be in editor content area in a non-editable (protected) element (img title/alt etc) and editor plugin should be a little more advanced - like moodle_emoticons plugin is showing images in editor content area but saves emoticon filter code when you press Save.

Average of ratings: Useful (1)
In reply to Marc Grober

Re: Moodle 2.X math plugins

by Mauno Korpelainen -

I just made a huge leap forward - Thanks to your ideas and emails that we changed with David.

Asciimathml can use MathJax fallback and it was much simpler than I never thought - we just need to set asciimathml scripts to output always MathML and let mathjax output that mathml with best ever browser support!!!

The main trick can be done with

var isIE = false;

but in moodle's case we can go much further. We can set input/output tables configurable with php and settings which makes a sort of multilang code possible. For example if I want to let students in Finland write

`kulma alfa`instead of english asciimathml code `angle alpha` to render $$\angle\alpha$$ it will be possible since we can set php code to use local translated code (still it takes time to write that code)

I am now so excited I could jump 3 meters up smile smile

I must take a short break now but I will try to write the basic code for the plugins today - our schools start on Thursday so I will be busy with my daily job during the coming weeks but I have now 2 days good time to make this new plugin code the most flexible ever seen smile

 

In reply to Mauno Korpelainen

Re: Moodle 2.X math plugins

by Marc Grober -
Yes, just saw email. Also was writing to Alfred about future of geonext as I recall he was mentioning another app format they were working on. I am excited to see Frederic active re mathjax and David active w jsxgraph. We desperately need to get folk together but never could get much response to that effort. I am as always concerned that kludges not make transparency and universality impossible - math wars (as in browser markup wars) will work against the user. Math folk should understand need for babblefish* more than anyone. We really need a superset of math tags that are uniform (or so I have argued in the past) so that math can be used with same tags no matter the app. While your clever duck < math > is handy, it is a bit of ouroborus if you know what I mean. BUT-SEE needs to be packaged for tinyMCE so it can be used in any web2 app - a bit of an order, I know, but that is arguably the future of numeracy (assuming there is a future after Finnish steel pan bands and falling US bond rating - lol) Thanks, Mauno. And thanks to your wife wink * Hitchhikers Guide wink
In reply to Marc Grober

Re: Moodle 2.X math plugins

by Colin Fraser -
Picture of Documentation writers Picture of Testers

Hi Mauno, got it working first time everything is great, except I had the setting for the gif graphic at what seems too low a resolution, making it almost almost unreadable. Doubled the density and the obvious happened, the image is now too large, but quite readable. It is now dropped back to 150 and while it is large it is almost unreadable again. 

Density at 120

Image at density of 120

Density at 150 

Image a density of 150

Anything larger is obviously ridiculous and this is the best compromise, but it is not that tidy. I have tried a number of things but nothing seems to improve the quality of the image, without an increase in size.. thoughtful  Any suggestions would be most appreciated.. Cheers..

In reply to Colin Fraser

Re: Moodle 2.X math plugins

by Mauno Korpelainen -

In tex filter density 120 is fine but you should change gif to png in that tex filter settings list. If it does not help there might be some problem in you version of Imagemagick or Ghostscript (convert binary) that are used to convert tex images to png files. Mimetex outputs always gifs.

I have asciimathml plugin now about 80% ready with MathJax fallback and also LatexMathML has in coming file mathJax fallback which gives a huge output quality improvement - I suppose that I will get new files ready in 3 or 4 hours - and will some cool things later... wink

In reply to Mauno Korpelainen

Re: Moodle 2.X math plugins

by Marc Grober -
If I wasn't so disillusioned I suppose I would have finished the Tex tweak to bypass convert as one would have to have a very outdated TeX distro to still need it...
In reply to Marc Grober

Re: Moodle 2.X math plugins

by Mauno Korpelainen -

Well... that's a little unfinished procedure...

The first idea in my fallback settings was that those sites that want to use Latex and tex filter have some fully functional distro of Latex with convert binary (with ImageMagick or Ghostscript) and since most problems are caused by missing / non executable convert binary  most sites are forced to use mimetex or some external fallback. The second idea was that many sites may want to set fallback in settings and this setting is chosen first, if fallback setting is empty plugin checks that convert binary and if it is executable outputs images with texviewer.php file that is based on files of core tex filter - we could of course use dvipng etc but it would require changes booth to tex filter and texviewer. You can simply pass this by giving fallback url like http://korpelainen.net/cgi-bin/mathtex.cgi? in those Latex fallback settings.

BUT I don't think we need Image fallbacks after MathJax fallback anymore - my beta version of AMMathjax and asciimathml plugin and mathjax plugin are now included to both packages - you can for example download http://korpelainen.net/mplugb.zip and unzip the files over current test files - you already have MathJax and I changed the new files to use as default setting cdn files so mpluga.zip is needed only if you want to download all the files of mathjax again to your local site.

Tabs are still pretty empty but AMMathJax supports both asciimathml ( `...`), latexmathml ( $ ... $ ) and "forced fallback" ( @ @ ... @ @ - double @:s seem to cause here in moodle.org a syntax error wide eyes ). These settings are not yet configurable like mathjax delimiters - you can also use \textcolor , \colorbox and \density{value} in latexmathml (no plugin for that yet but I will implement full color support later) - try for example

$ \density{300}{{\textcolor{#fe6805}{#fe6805}}}$

colors

It is of course possible to change colors with editor textcolor and background color tools if you need only one color / notation but the benefit of latexmathml colors is that you can give notations like

$\colorbox{red}{testing dollars}\sum_{i=1}^{p}\sum_{j=1}^{q}\sum_{k=1}^{r}\textcolor{blue}{a_{ij}} \frac{\textcolor{green}{b_{jk}}c_{kl}}{\colorbox{Orange}{ text}}$

and asciimathml script converts this to mathml and Mathjax convert it to visible output for almost all available browser including mobiles and old browsers that just can use javascript.

I will start collecting the demo site examples tomorrow... smile

You can find the new settings from Site administration > Plugins > Filters > Math > Settings (and may need to click Notifications link first)

New settings

In reply to Mauno Korpelainen

Re: Moodle 2.X math plugins

by Mauno Korpelainen -

Just read an email from David L saying that "IE before 9 did not have createElementNS, so you'll need to modify the createMmlNode function..."

I will check those IE versions 8, 7 and 6 tomorrow - and get back when that issue is sorted - mixed

In reply to Mauno Korpelainen

Re: Moodle 2.X math plugins

by Colin Fraser -
Picture of Documentation writers Picture of Testers

Thanks Mauno, done and better.. At some point, when I get a bit of time, in the not to distant future, maybe..smile  I will strip all this out and reinstall it, a couple of times I think then note it as I go reinstalling it. Would you object if I was to write up all of it for Moodle Docs. I know it is here, but over time, this will become more obscure and buried under the volume of discussions. Or you prefer to do it yourself? I can't help you coding the plugins but I can write some documentation for it.. Cheers.

In reply to Colin Fraser

Re: Moodle 2.X math plugins

by Ravi Vare -

Hi Colin,

That's the spirit !!!

Best of Luck for Documetation of mplugin.

Ravi

In reply to Colin Fraser

Re: Moodle 2.X math plugins

by Mauno Korpelainen -

Documentation of these plugins will take a long time so all the help you can give is welcome.

I think I sorted this IE6-8 issue very late last night our time and I have 2 possible/optional IE fixes but right now I must go to a teacher meeting and current versions of asciimathml and asciisvg are broken in IE6-8 in latest packages on my test server. I will try to find that time to update packages to fully functional code as soon as possible (later today)

In reply to Mauno Korpelainen

Re: Moodle 2.X math plugins

by Colin Fraser -
Picture of Documentation writers Picture of Testers

Thanks Mauno, won't be able to start on it for a couple of weeks but will let you know when is up and running. The installation pages are going to be fairly large so might break it down a bit, which means there might be some editing for you, but not too much I hope. wide eyes

In reply to Colin Fraser

Re: Moodle 2.X math plugins

by Mauno Korpelainen -

My packages are now upgraded to new code.

Script lib/common/AMMathjax.php looks relatively stable now and renders MathML / MathJax fallback at least in latest versions of FF, Chrome, Opera, Safari and IE9 - browsers that support 'document.createElementNS' - and all of these render good quality output in asciimathml/latexmathml and asciisvg.

Those browers that do not support 'document.createElementNS' are handled like IE6, IE7 and IE8 and they use (sadly)
image tag fallback with asciimathml fallback url (if given in settings of tinymath editor) or texviewer.php / Tex filter latex or as a 3rd option my cgi mathtex server. I tried to render first fallback texstring from asciimathml script with MathJax latex fallback but it is not initialized so I had to use image fallback for old IEs until I find some way to "re-render" fallback texstrings in old IEs - I might try jQuery next...

I also fixed a couple of JSXGraph issues and all versions of IE show now JSXGraphs correct.

Themes might need some tiny css fixes too since graphs can be pretty large - particularly in mobiles and tablets such modifications are necessary. Graphs can be scaled to fit to small screens but it does not happen automatically...

My schedule looks busy right now since our schools start tomorrow but I will do my best to create that demo site next and once it is up and running you get some more material to add to Moodle Docs. I don't think we are even near the halfway yet - many modifications and new features & better tools should be available at the end of this year or next year but this is exactly the spirit of these open source projects: some ideas come and some go but something new is created every day smile 

In reply to Mauno Korpelainen

Re: Moodle 2.X math plugins

by Colin Fraser -
Picture of Documentation writers Picture of Testers

OK Mauno, will dl the newer packages and install them...and track them

Marc, Yes you Marc... you said.

"If I wasn't so disillusioned I suppose I would have finished the Tex tweak to bypass convert as one would have to have a very outdated TeX distro to still need it..."

You know yourself that there is always someone who gets comfortable with what they have and will not move. But reading between these two lines it would seem you have been supporting Mauno by adding code and ideas and suggestions. (And with me trying to follow some of your discussions and getting lost after the first comment or two.) So you have anything that can be used in the Docs?  Care to share??? .. tongueout  

In reply to Colin Fraser

Re: Moodle 2.X math plugins

by Mauno Korpelainen -

Don't be surprised if your navbar is in some odd place or missing... wide eyes

I noticed today a very funny bug that is caused by class .navbar that both jsxgraphs and moodle use.

If you edit file lib/jsxgraph/distrib/jsxgraph.css and add a new class .jxgbox before .navbar you will get navbar back to your moodle (where it belongs).

I tried to inspect where jsxgrahs actually use .navbar and it may be some relic from jsxgraph home site and we may not need at all

.jxgbox .navbar {
    color: #aaaaaa;
    background-color: #f5f5f5;
    padding: 2px;
    position: absolute;
    font-size: 10px;
    cursor: pointer;
    z-index: 100;
    right: 5px;
    bottom: 5px;
}

navbar

In reply to Colin Fraser

Re: Moodle 2.X math plugins

by Marc Grober -

Sorry Colin, but you seem to have me confused with someone who is being productive....

There is a Tracker item http://tracker.moodle.org/browse/MDL-23350 on the item I was talking about. The current config is that Moodle anticipates rather old TeX distros, which ended up requiring the convert binary. With the exception perhaps of Ubuntu that is no longe the case. And since with any current install of TexLive all the requisite binaries are in the core distro of that package, we cold make the TeX filter much easier to manage by avoiding convert as possible.  In fact, in as much as TeXLive is built to install by a user without root perms, one could arguably build an admin script somewhat along the lines I recommended for MathJax and use it to install Tex in the users designated location, which would get rid of a huge number of issues where users are lost because they do not have access to a system TeX install...  it could also make adding TeX macros (like longdiv, lol) easier by providing a way to install and reference them.