Moodlev2.0 and MathJax

Moodlev2.0 and MathJax

by Colin Fraser -
Number of replies: 76
Picture of Documentation writers Picture of Testers
So far, I have been able to determine that MathJax works in Moodle 1.9.x, but no-one seems to be able to relate, in words of 1 or 2 syllables, how to activate it in Moodle 2.0. I am not that good that I can just see it clearly... I have had a few things go wrong trying to get it working and so far, not had to reinstall the v2.0, but I think I have gone as far as I can without some guidance.. cheers..
Average of ratings: -
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -
This may not be the recommended way but it is a quick way to get MathJax working on moodle 2.0:

1) Download the latest package from http://sourceforge.net/projects/mathjax/files/ and unzip it to your moodle subfolder lib (supposing that more than one theme is going to use MathJax)

2) Edit theme layout files (or base theme layout files) - supposing that you have a theme called colin in folder theme/colin and there is a layout file general.php add before </head> tag:


<?php echo $OUTPUT->standard_head_html() ?>

<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/MathJax/MathJax.js">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/noErrors.js"],
jax: ["input/TeX", "output/HTML-CSS"],
tex2jax: {displayMath: '@d','@d', inlineMath: '@i','@i' },
"HTML-CSS": {availableFonts:["TeX"]}
});
</script>

</head>

where you can use any delimiters (or functions/settings with php to produce those delimiters) instead of @d and @i that would be used here to render

inlinemath with tags like @i tex tags here @i or
displaymath with tags like @d tex tags here @d

The recommended way is to use theme config.php and javascript folder but then you are going to have problems with default paths etc.

If nothing happens clear theme caches or enable temporalely theme designer mode from theme settings page - if theme designer mode is disabled it is possible that only old javascripts are read from cache...
Average of ratings: Useful (1)
In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Thanks Mauno, .. again.smile Lets see if I am interpreting this right..

I have turned the Algebra and Tex Notation filters off altogether, I do not want them interfering with the MathJax and I want to be sure it is MathJax I am seeing, not the native filters. MathJax has been setup and the test page runs nicely, but I have not configured it to run generically, I want to make sure it is running in Moodle 2.0 before I try anything else fancy.


The script comes immediately after the <?php statement

I am assuming that the @ delimiter can be replaced or added to with a $ token and that the i and d are both used in this context as generic identifiers for text?

Like:

tex2jax: {displayMath: '@d','@d', inlineMath: '@i','@i' },
"HTML-CSS": {availableFonts:["TeX"]}

can be replaced with:

tex2jax: {displayMath: \[','\\]
'">'LB+LB','LB+LB'],['\\[','\\]', inlineMath: $$','$$'],['\\(','\\)'],[MJX,MJX">'$$','$$'],['\\(','\\)'],[MJX,MJX },
"HTML-CSS": {availableFonts:["TeX"]}

without issue...

The next problem I have is that the syntax highlighting has disappeared from
hasheading= ($PAGE->heading);
to
echo $OUTPUT->doctype() ?>,
as soon as I entered the script. It may not be a problem though, the script itself may be interfering with the highlighting, I have seen this before, and not had a problem - even though not understanding what has happened..

But then.. seeing as how I now have a blank screen in the course and the Notifications page is filled with a lot of php coding from the general.php file which corresponds with the loss of syntax highlighting exactly,.. so maybe there is something not right.. oh well.. off to work, try again after..

Thanks anyway, Mauno, its a start..smile
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

Well... you did not do like I said... or maybe my previous post was not clear enough wink

Script tags should be just before </head> tag.

My test site has some other scripts too but MathJax need to be after other head stylesheets and javascripts. Attached the whole head section of my general.php - after echo $OUTPUT->doctype() ?> :

<head>
<title><?php echo $PAGE->title ?></title>
<link rel="shortcut icon" href="<?php echo $OUTPUT->pix_url('favicon', 'theme')?>" />
 <meta name="description" content="<?php echo strip_tags(format_text($SITE->summary, FORMAT_HTML)) ?>" />
<?php echo $OUTPUT->standard_head_html() ?> 
<script src="<?php echo $CFG->httpswwwroot ?>/lib/AM.js" type="text/javascript"></script>
<script src="<?php echo $CFG->httpswwwroot ?>/lib/jsxgraph/src/loadjsxgraph.js" type='text/javascript'></script>
<script src="<?php echo $CFG->httpswwwroot ?>/lib/jsxgraph/src/GeonextReader.js" type='text/javascript'></script>
<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/MathJax/MathJax.js">
MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/noErrors.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {displayMath: '@d','@d',  inlineMath: '@i','@i' },
    "HTML-CSS": {availableFonts:["TeX"]}
});
</script>
</head>

Red part is for MathJax, the previous scripts are asciimathml and jsxgraph scripts (they have nothing to do with MathJax configuration)

You can use any configuration you want - see http://www.mathjax.org/resources/docs/?configuration.html - but be carefull to not break actual php or javascript code, one missing character (for example backslash) or wrong character can break code...

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Nah, your instruction was clear, but at that time of the morning, my English is rubbish... We don't speak it here in Oz...smile

In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Anyway, after putting everything in the right place.. ahem.. I went to the page and used the code given there with the $$$ tokens. and wonder of wonders.. it doesn't work...

The image is showing what happens, but the code has been changed to read a $$$ tokens.

However, looking at the code I see the line:

<?php echo $CFG->httpswwwroot ?>/lib/MathJax/MathJax.js">

but why the https???

I thought the config.php file was $CFG->wwwroot well it is, but...
I am not using a secure server, it is a localhost actually that I am testing this out on.. I am thinking wondering if it is looking in the right place, change the line and still no response. (I have put the MathJax folder in the right place.. the Algebra and Tex Notation filters are still both turned off.)

Attachment mathjaxnotworking.png
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

I made some further testing and found a couple of possible reasons for failures:

- obviously javascripts don't work through parent theme (base) layout files like I expected

- order of different javascripts is essential, if you have some other scripts or filters like AsciiMathML rendering the same tokens (for example single dollars)

- check that your test pages are really using that theme / layout file where you added javascripts, for example front page is in most themes using frontpage.php layout file

- MathJax is very slow to render maths, if it takes too long to render equations browser may stop loading ( = timeout )

- paths may not be correct, for example lib/MathJax/MathJax.js may be in lib/MathJax/MathJax/MathJax.js or some typo error might prevent loading ( mathJax/Mathjax/MathJax/mathjax )

- some other javascript error / conflict with some other script might prevent loading MathJax.js

What ever the reason is Firefox error console might tell something, IE8 debugging tools something else and so on.

In my test theme

<script type="text/javascript" src="<?php echo $CFG->httpswwwroot ?>/lib/MathJax/MathJax.js">
MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/noErrors.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {displayMath: '@ @','@ @',  inlineMath: '$ $','$ $' },
    "HTML-CSS": {availableFonts:["TeX"]}
});
</script>

renders equations between double dollars and double @:s fine (I placed to previous example one space between $:s and @:s because moodle.org is using tex filter and algebra filter - there should be spaces in real world... )

I would not disable tex filter because init code of tinymce is testing if tex filter is enabled and default editor shows dragmath only if tex filter is enabled - you should be able to use any tokens with MathJax, for example

tex2jax: {displayMath: 'colin','colin',  inlineMath: 'mauno','mauno' },

Although I have been testing this full "math package" with all possible math scripts and separate editor with different toolbar row of math plugins during the past few days where it really does not matter what the default settings are...

Oh - almost forgot - $CFG->httpswwwroot works always in moodle, no matter if it is http or https site, moodle takes care of that...

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
just replaced the previous script with this one and after 90 seconds, it has a header but is still loading... what am I doing wrong?

First, I do not know enough about the PHP or the Javascript that makes this all work, so technical explanations are wasted. I know enough to be considered clueless actually..smile but that is all.

I fired up the TeX and Algebra filters and used the @@ to denote some TeX now it finished loading and I have a white screen... but it will not even bring up the front page now... This just keeps getting better and better... Unbelievable....


From the error console...
Warning: Expected declaration but found '*'. Skipped to next declaration.
Source File: http://192.168.1.109/moodle20/theme/yui_combo.php?2.8.1/build/assets/skins/sam/skin.css
Line: 17

then it just goes to the next error and so on until I get to...

Warning: Expected declaration but found '*'. Skipped to next declaration.
Source File: http://192.168.1.109/moodle/theme/standard/styles.php
Line: 5931

Something bit it...

Commented out the script, going into the database to change the text from @@ to $$ and see if that makes a difference...
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

I don't know - maybe your test PC is running out of memory (RAM) - or "something" just breaks either php or javascript. It can be caused by one character - or one missing file.

What theme are you using, is it one of the core themes or some custom theme?

I could modify some core theme, zip it and give you a download link to test if the problem is in your code, my code or in Mathjax - or somewhere else mixed

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Using the Serenity theme, (big fan of the tv show Firefly..hahahaaa!!!) Weird is my specialty btw... I can make a mess of anything.smile

Thanks Mauno and I really do need to be able to get it working... for 300 odd Moodle sites in my 300 odd school districts. If it does not work, then it lacks credibility, then the obvious, people will look for things to criticize.

Not that there is any pressure on anyone..big grin

Cheers..
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

I tested adding that piece of code to 3 layout files of Serenity theme and mathematical notations were rendered without problems in a few seconds.

Attached zipped those 3 files and I tested tags

<p>@d \alpha +\frac{2}{3} + f(x)=\displaystyle\int\limits_1^2 e^x\,dx @d</p>
<p>This is inline maths @i \alpha +\frac{2}{3} + f(x)=\displaystyle\int\limits_1^2 e^x\,dx @i</p>

One more possible cause of problems might be eaccelerator so if your test site php.ini has a row like

eaccelerator.enable = "1"

you should set it to

eaccelerator.enable = "0"

or changes may not take effect in php files...

In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Marc Grober -
Colin,

It will work, have no fear. I am twiddling with a php script to do a mathjax install and update to take some of the complexity out of mathjax, and it is very solid with Moodle 1.9

Casey is right in suggesting that it should be set up for moodle as filter (ASCIIMath also) It is not a Herculean task to do that, just takes some time without distractions wink

As far as a setup for 300 schools, I would do an image on Linux using texlive so you had access to tlmgr and then patch to use dvipng as I proposed, or hack Tex filter so it uses mathjax instead. As Mauno notes, petr hardcover dragmath to Tex filter for time being in M2
In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Marc Grober -
Since I am fiddling with tweaking the code that tests for the Tex binaries, perhaps we should test for existence of mathjax or asciimathml and then use it instead of Tex, so that we can bypass having Tex filter actually parsing in order to have dragmath work?
In reply to Marc Grober

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

No problem, Marc - I have used some days now in testing that optional moodle 2.0 editor - "tinymath" - instead of default tinymce configuration and anything is possible using themes, filters and what ever tools we want to use.

We had the best ever summer here in Finland - sun was shining all the time - so it was really fun to relax and enjoy all that rest and peace...wink

It was actually easy to create a new "texviewer" for Tex filter image fallback - both for moodle 1.9 and moodle 2.0, some days ago I upgraded some of the "old" plugins to moodle 2.0, I have an editor switcher ready in my test PC (yui module) and things are looking good right now. Should not be hard to use Mathjax in editor plugins and in any fallback or filter if necessary.

The latest MathJax is faster than previous versions but it is still relatively slow in IE (what isn't???)

I suppose that editor administration will change a lot in the near future and we will see that day when you will be able to select the tools you need from site wide editor configuration or user preferences. Both are already possible with existing code on theme side (using administration of theme settings and yui user preferences) - there are just no docs yet about using them.

And things are going slowly forward...

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Marc Grober -
We had one of the rainiest summers on record here with an average temp in the 50s - mold in the flowerbeds and between my toes.... climate change. I am second gen here so no access to EU passport sad

I had started tweaking the tex filter to use dvipng (http://tracker.moodle.org/browse/MDL-23350) which is why I am wondering whether it might not be handy to go ahead and add the features necessary to have the core tex filter check for the existence of other libs and fork. We could then rename Tex filter to "Math Notation FIlter" and all we need to do arguably is add the necessary CFG values and locations and tweak the actual filter to use the appropriate code depending on the flags.... that leaves Petr's hard code in place, makes it easier to use multiple math filters as one filter, etc. Maybe not the "Moodle Way" but more conservative than what we have been doing - lol

I suppose an important question is whether mathjax, asciimathml, jsxgraph etc should be addressed via formal Moodle filters or in other fashion (such as user or admin selected themes etc.) I would still like to see some math themes available for Moodle.org so we can intelligently discuss same ;=}

I am concerned that we are going to see some early adopters try to roll our Moodle 2 before all tools are ready for Maths (as well as other areas) and then see a stampede of hasty kludges.

Are you caching the webfonts when you use mathjax with IE, as that is where the time gets eaten up.

by the way, did you check out the work that was done with mathjax and jsxgraph? I need to update our forums to reflect the release of MathJax v1.0 and I need to get a doc page started for MathJax. I had hoped that Casey might get to that but it sounds like he is overloaded. Likewise I suppose we shold start a doc for jsxgraph... and I should create plugin entries for both and get Anthony to approve them, at least as stubs.

I do have M2 running now on php 5.3 so I think am ready to test install of your packages when you have them prepared.
In reply to Marc Grober

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

When Colin asked about MathJax I downloaded the latest version of MathJax (MathJax-v1.0.1a) from http://sourceforge.net/projects/mathjax/files/ and I have used JSXGraph version 0.81 from http://sourceforge.net/projects/jsxgraph/

JSXFilter works ok to render the graphs that GeoNext applets produce and filter tags are in editor plugin re-editable in applet in all other browsers except IE - one of those issues I don't understand (IE does not get the dynamic value sent to given applet param although IE does get the static value for the same param)

I have also found a nice solution to get tex filter tags re-editable in editor as selectable images or tex filter code so that you can see in editor the math you save (as image or tex filter tags). The same method can be used with any tex renderer, internal or external, including MathTran and GoogleTex. The last remaining task is to combine all of these to one plugin - they are still separate plugins now. And I need to create new mathJax plugin code as well. Tiny tasks here and there...

The main problem with filters is that they are currently used for replacing parts of content with some other content using php and the main benefit of using filters for rendering mathJax or AsciimathML javascripts could be that those scripts would be used everywhere - with all themes and all resources that use filters. Theme system is more flexible than filters because then you can use different settings with different themes and you are not forced to use site wide settings if you don't want to - it is easier that way to restrict use of some scripts to some (math) courses only...

The same way all teachers and students don't want to use math plugins (not even dragmath) and it is reasonable to allow language teachers use language teaching tools and math teachers choose math plugins... and now it's finally possible thanks to new user preference code that Sam Hemelryk introduced in Splash theme - http://tracker.moodle.org/browse/MDL-23674 

I used the same idea for editor selector and it's a cool way to change editor on the fly. It has taken quite a long time to get familiar with the new moodle 2.0 theme engine with lots of new features but it really gives a huge amount of extra flexibility to theme level and layout files with theme settings administration allow us to define for example tokens at theme if we want. It means that if you use for example default latex you can set one theme to use tex filter code with php texviewer (based on texdebug.php) even without actual tex filter - either with Mimetex or local distribution of latex - and other theme can use for example Mathjax for those same tokens to render it with mathJax.

Some of my recent time has gone to jquery testing - I have compared jquery plugins and yui2 plugins and I still think that jquery plugins work better than yui2 plugins but I haven't reached yet the "heaven of yui3 plugins"...

I will make a nice moodle 2 math test package ready with a very unique theme during this week and send you a download link after some days, Marc. big grin

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
From what I have seen in the test web pages I have has shown that MathJax is a versatile and clean tool, much cleaner than TeX Notation tool. Marc, if you can generate code that would make it a filter, then that would be a brilliant alternative. I understand what Mauno is talking about with regard to site wide, rather than thematic approaches, but from a different aspect.

Filters that are not native to Moodle require to be maintained outside the normal upgrade process, dependent on third parties, and if the person who is doing it falls by the wayside somewhere, the filter loses its driver. In another aspect, they also need be installed, and often they will need to be reinstalled. I know that Mark Dreschler had something to say about this in his regular column, Joining the Dots:

"So what’s it all about then?

The potential problem (and I stress the word potential there) with open source software is that the effort required to upgrade versions is often loosely proportional to the distance away from the ‘pure’ core code that you’ve ventured. The more customisations, hacks, extensions and plugins you’ve implemented, the more thought you’ll have to put in to upgrade. From what we’ve seen at work in our internal testing, a ‘clean’ Moodle 1.9.x site upgrades neatly to the pre-beta Moodle 2.0, just like it should. The grey area we’ve seen coming for ages was how much effort would be required to upgrade Moodle sites running (in particular) third party plugins."


To me, there is a competing need, and designers are going to have to be very careful about how they resolve these issues. From a User POV, the bottom line is always going to be "ease of use" which is why "complete learning packages" will become a more attractive option, why I am agitating for a fully integrated Moodle/Mahara/MediaWiki/WorldPress package in our working environment, complete with single site logins... (sigh...)

As for my immediate problem, it died.. something broke it and I am not sure I need to find out what - and I doubt I have the skills to do so anyway. The errorlogs I have seen reveal nothing that registers as important to me,. Even if I could access the Moodle 2.0 error logs, they would not reveal too much, I had not reinstalled it that long ago, it is last week's build, and I had not turned on full error checking.. Just dump it and reinstall.. quicker, and start again. This time see if I can get it to work...haha!!!

Thanks guys, really appreciate what you have done so far, and as someone else one said "I'll be back!"... tongueout
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
OK I'm back...

this is an error i get..

Warning: Expected declaration but found '*'. Skipped to next declaration.
Source File: http://192.168.1.109/moodle20/theme/yui_combo.php?2.8.1/build/assets/skins/sam/skin.css
Line: 9

Then, when I look at the code, it reads:
.yui-skin-sam .yui-ac{position:relative;font-family:arial;font-size:100%;}.
yui-skin-sam .yui-ac-input{position:absolute;width:100%;}.
yui-skin-sam .yui-ac-container{position:absolute;top:1.6em;width:100%;}.
yui-skin-sam .yui-ac-content{position:absolute;width:100%;border:1px solid #808080;background:#fff;overflow:hidden;z-index:9050;}.
yui-skin-sam .yui-ac-shadow{position:absolute;margin:.3em;width:100%;background:#000;-moz-opacity:.10;opacity:.10;filter:alpha(opacity=10);z-index:9049;}.
yui-skin-sam .yui-ac iframe{opacity:0;filter:alpha(opacity=0);padding-right:.3em;padding-bottom:.3em;}.
yui-skin-sam .yui-ac-content ul{margin:0;padding:0;width:100%;}.
yui-skin-sam .yui-ac-content li{margin:0;padding:2px 5px;cursor:default;white-space:nowrap;list-style:none;zoom:1;}.
yui-skin-sam .yui-ac-content li.yui-ac-prehighlight{background:#B3D4FF;}.
yui-skin-sam .yui-ac-content li.yui-ac-highlight{background:#426FD9;color:#FFF;}

Which suggests there is conflict or an error in the skin.. I have no tools or any idea how to redress this though.. There are a lot of lines that have been skipped like this. BTW, this is a reinstall of the earlier white screen, took me all of about 6mins to get it up and running so whatever, bit me the first time is part of the Moodle code, which I suggest is related to the use of the @@ and the TeX Notation or Algebra filters.

And it is using the TeX Notation filter, even though I have added the MathJax code where it is supposed to be, and yes, I have copied the MathJax folder (complete) to the moodle/lib folder.

In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

Those are not errors, they are warnings caused by YUI underscore/star hacks that are not valid css expressions - but people use them to give different css for IE 6/7

http://en.wikipedia.org/wiki/CSS_filter#Star_hack

If tex filter is enabled it is used before any javascripts so if you want to use tex filter, use different tokens for mathJax expressions...

If mathJax is not loading at all (you don't see any "Loading" text in the left bottom corner of your screen) there must be something else wrong - but I have no more ideas left...

You did not get any bold error messages in Firefox error console - javascript errors - or did you?

Or IE8 developer tools (F12 and Start debugging) or Chrome mouse right click - Inspect elements - Resources - Enable resource tracking don't give any missing files etc?

In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

Colin,

do you actually see the script tags in source (in Browser - Show - Source) before </head> ? They should be visible in source if you add script tags to layout files.

If yes, some files from MathJax package (from Sourceforge) might be missing.

If no, it might be some server cache issue (eaccelerator etc)

Attachment colin.gif
In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Very definitely in before the </head>

<script type="text/javascript" src="http://192.168.1.109/moodle20/lib/javascript.php?file=%2Flib%2Fjavascript-static.js&amp;rev=156"></script>
<script type="text/javascript" src="http://192.168.1.109/moodle20/theme/javascript.php?theme=serenity&amp;rev=157&amp;type=head"></script>
 <script type="text/javascript" src="http://192.168.1.109/moodle20/lib/MathJax/MathJax.js">
 MathJax.Hub.Config({
 extensions: ["tex2jax.js", "TeX/noErrors.js"],
 jax: ["input/TeX", "output/HTML-CSS"],
 tex2jax: {displayMath: '$ $','$ $', inlineMath: '$ $','$ $' },
 "HTML-CSS": {availableFonts:["TeX"]}
 });
</script>
</head>
<body id="
And I am assuming that it is right, at least if I was coding this by hand it I would think it in the right place

Then if the code is incomplete.. would it work in the browser.. I have a script I tested in my own page and that worked, I did not just rely upon the basic test or samples that come with it.

I have established control over both an inlineMath and displayMath in a normal web page. This was actually quite easy, once I got the link pointing to the right place. So could that be the problem?

So here is a grab from Firebug.

Attachment mathjaxnotworking02.png
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
OK Got it working..duh!!!! And your comment got me thinking about it, Mauno, so I went back and started again.

The script I ended up using was, essentially, the first one you gave me, but with a couple of changes (see below). I turned off both the TeX Notation and the Algebra filter and it worked, but it it is going to need some refinement, I am going to have to swap the inline and display around if am going to get lazy on it...big grin Huge relief there... so simple.. but I don't drink and I don't do funny green cigarettes or other forms of candy that do not contain a lot of C6H12O6, so why was I stressing?

Now, I am thinking that if the use of the MathJax is thematic then it is going to cause a number of issues. It will mean a lot of people are going to get very annoyed because they will not have access to the theme folder. I suspect Marc is right, it will need to be setup as a Filter.

EDIT: Swapping the tokens around did not do a lot.. going to have to do a load of editing... <sigh>... well it does give me a real chance to check out the editing capabilities of TinyMCE. What a great opportunity this has been!!!

Attachment mathjaxnotworking03.png
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Marc Grober -
Colin,
If you are writing about editing existing Tex then slow down as there should be no need.....
In reply to Marc Grober

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Marc, I was in the process of upgrading my TeX test pages from 1.9.9 to 2.0 and I thought I would use MathJax. Installed, and run and teted considerably easier than I expected - except when I went to Moodle. That is when I started stressing..blush

When Mauno and you came to the rescue, I knew it would get it working, but when it didn't mmm I really though there was a problem.. (and there is but the one you pointed out, not the one I thought there was). dead

So when Mauno was talking about files missing, or eaccelerator, I knew it wasn't eaccelerator, so I was looking at it from the wrong view, So I took the code I used in my test pages, which is what I should have done in the first place, and surprisesurprise it ran like a dream.

I am not going to be able to get away with not editing the code, the samples I have used have the triple$ for examples and $$$ tokens which MathJax is rendering as TeX$ and Tex and tossing bits of inline code all over the page. But I can always fix that... cool

In the meantime, I am still experimenting and have just started. I am wondering though how the geometry is going to be rendered that is for sure..thoughtful



In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Marc Grober -
I am not sure what you are saying as you appear to be speaking australian, croiky, and I don;t know that - lol

but as Mauno indicated, you can set as many different tokens as you want, so there should be no reason that you existing Tex in Moodle couldn't be rendered without changing your Tex (though MathJax does not do all Tex and somethings, as with ASCIIMathML, are not implemented.) Remember, you can use replace.php fix toeks in the db, and your IT guy can show you how to use perl, sed, and awk to do the same for anything in moodledata.

BTW, mathjax does interact well with jsxgraph (asciimathml was a bit more problematic, though Mauno's hack is now bundled with jsxgraph) and jsxgraph does an incredible job. htmlarea can also be hacked to implement geonext to give you the ability to give the student applet access to constructions (I am hopeful that Mauno has this all shrinkwrapped for M2 by winter solstice!) But with or without geonext, jsxgraph can provide a wonderful resource and can be invoke the same way you invoked MathJax, and you cold invoke asciisvg and use it as well, either standalone or as included in asciimathml 2.
In reply to Marc Grober

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Ahh not Strine at all, just typos Marc..bwwwaaahahahaaa!!!!

but I, at least, do not swear at people here... e.g.

toeks in the db, and your IT guy can show you how to use perl, sed, and awk...

Ha, some of "my" IT guys can barely find their way around their offices... I am afraid they have all been seized with the power of the Dark Side, 'Soft Lords, all of them... just so long as I don't hear voices telling me to "Use the Force, Colin", or "Go to CandyBar! Seek out soda!" I should be OK, though..smile


In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
OK... I have downloaded jsxgraph and placed the plugin into the plugin folder of 2.0...

As usual, nothing ever just works for me, be too simple. First issue, the plugin does not seem to be being registered properly

[ [filtername] ] (filter/jsxgraph)

is appearing in the filters table not just the name. I am sure that I am not supposed to get that. Is the plugin not for 2.0? Have not tried 1.9 and much prefer not to. Seems we are planning to go over to 2.0 early next year, after first few updated releases catch any major problems before making the commitment. Also gives us some idea of what we need in the way of postnatal training for teachers. I really want to kep ahead here, in my own bumbling way.. Or am I just too early?


In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Marc Grober -
Here is what I would suggest since you apparently insist on banging your head on the wall:

Don't use jsxgraph as a filter (remove it)
Go to jsxgraph wiki and check out example of jsxgraph working with mathjax
Edit your header so that instead of invoking just mathjax you are invoking both as demo'd in wiki example

Create a moodle resource based on the example in the jsxgraph wiki page with the example. View the source and make sure it is properly invoking both

Report back

You should have nonproblem finding the example I am referencing, but if you can't locate it let me know and I will dig it up.

The gorse be with you
In reply to Marc Grober

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers

Early is good ..right??? cool

And yes, Marc, I am a masochist, if I wasn't I would have gone into some occupation that is considerably less stressful than teaching.. like politics or oil well fire fighting or some such..tongueout 

I like to dive in at the deep end, which means I don't hit my head. Sure, it also means I make a mess of most things, but eventually I learn, and for an old guy, learning is perhaps, the last of all the great adventures, and leads to be best of all possible worlds, an old age without dementia..clown mmm maybe...

Going to have to take a step back and get the basics right first..

   

In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
This is gunna be hard work I can tell you.. big grin

Got the example and I have invoked the jsxgraph and MathJax code in the sample given, but the sample makes far too many assumptions as to what the user, moi, knows. So I plead "je ne compris pas".

I have the JXG.JSXGraph.initBoard('box',... sample working but when putting the MathJax code in it fails. So, I have jsxgraph working but th-th-th-th-that's all folks....

This is btw my MathJax test page, and that too works. I have the jsxgraph calls appearing before the MathJax call, and the same with the scripts.

And guys, I know this may be getting a little tiresome, but I am learning lots here, and what more can I ask - and I really appreciate the effort you are making for me...
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -
It's good to have people like you, Colin, testing all possible and impossible situations we can see in moodle big grin

It may take some time until all "experimental features" are even partly functional - remember those "buts".

I was once again happy and proud of myself yesterday when I had a new prototype of Mathjax plugin ready and functional for tinymce and moodle 2 - and it even worked faster than google chart api tex plugin and all those other 1.9 plugins I have been slowly upgrading to moodle 2. No problems in FF, no problems in IE (WoW) - and what happened - web kit browsers Safari, Chrome and probably also Opera did not show notation preview like FF and IE did... so it's time to look for some other method to render mathjax in preview window. MathJax does not render image tags like other renderers so the plugin must render first javascripts in some window inside plugin, then change dynamically notations and finally initialize the mathjax script to render maths inside that window inside outer plugin so that all browsers render preview the same way...

The main problem with moodle 2 is that you can't expect things to work the same way like they did in moodle 1.9 - most likely they DON'T WORK the same way, and JSXGraph filter is one of those million of tiny things that need some more checking of code... dynamic script examples http://jsxgraph.uni-bayreuth.de/wiki/index.php/Using_MathJax do work if you have all the needed script tags loaded, css for jsxgraphs (for IE) loaded and actual scripts rendering the nice looking graphs loaded to correct place on pages BUT we have a long journey to go before such examples can be used in a simple way (disable editor from your profile and so on...)




In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
For me then it is a simple case of testing the limits of everything and if I get it working then anyone can use it.. that would be good.

I am, at this point, going to continue playing with this, see what is possible and what is not. Going to have to I think.

I am agitating for a set of PHP Apps to be adopted and then integrated to allow a single login process that we can use in our schools environments. I need to be able to tell everyone that it is possible, to log into the suite and access each app, as required. Inherent within that is that there needs be a common set of tools, like a TeX tool that I can use in Moodle, and in MediaWiki and in Mahara and in WordPress which is the same in all the apps and uses the same standards and can be, if required, copied from one to the other easily and with a minimum of fuss. This is the end game anyway, but right now it is so far away.. and I know so little...
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
moz-screenshot-5.pngmoz-screenshot-6.pngmoz-screenshot-7.pngmoz-screenshot-8.pngmoz-screenshot-9.pngmoz-screenshot-10.pngI have done what Marc suggested and a little more I think...

I put the jsxgraph folder into the moodle/lib folder.

I copied the script and styles links into the theme's general.php file, immediately before the MathJax code.

I then copied and pasted the code I used in the test page and it all worked as it should, the code:

<div id="box" class="jxgbox" style="width:500px; height:500px; background-color: #cacaca;"></div>
<script type="text/javascript">
var board = JXG.JSXGraph.initBoard('box', {originX: 250, originY: 250, unitX: 50, unitY: 50, axis:true,showCopyright:false});
</script>

I added a colour to the div and changed the Copyright value to false. (I know, a bit naughty, but I wanted to make sure that it was my test that was being displayed, not something downloaded from Bayreuth Uni without me jeopardizing the integrity of the code.)

It all went swimmingly well... but...except for... um... this...

The Topic Outline panel... now you see it, now you half see it...

I better go ..election day tomorrow... and working in it for most of the day...


Attachment openingandcollapsed01.png
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Marc Grober -
As Mauno suggests, things will need a bit of tweeeeking, but to address such things one must take tiny steps, not great giant gallumphing Aussie strides - lol. And such such approaches are kludges, so we should eventually have a formal simple way of making such functionality available, a process palatable even to the crankiest down under wink You go elect someone; this stuff will still be here for you tomorrow.
In reply to Marc Grober

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -
Marc,

I have that MathJax plugin preview problem solved now with external (movable and scalable) preview window and I am trying to minimize next the number of possible math plugins in tinymce (optional "tinymath" editor configuration) toolbar and in most cases it is possible to use one plugin to output different output/syntax and tags with different selectable tokens. Still the list is long - even if those plugins were in a separate math plugins toolbar. To avoid mixing of syntax it might be best to use different plugins for different base syntax but how do you prevent people writing "mixture code" - remember those nth roots etc

Each "output format" has some benefits, for example it's nice to see those images in editor screen and it is nice to be able to edit those images with one click in plugin. On the other hand script, applet, embed and sometimes even img tags can cause real problems inside the editor content area, media plugin of tinymce does not yet support svg and so on. Anyway - here we go again - slowly forwards:

1) Core DragMath plugin:

several output formats but can be used also inside other plugins

2) LaTeX plugin:
MathJax (internal javascript)
Texviewer (internal img tags with local LaTex - Texlive, MikTex...)
Cgi mathTex (external img tags with cgi mathtex and LaTex)
LatexMathML (internal javascript with mathML/image fallback)
Tex filter latex syntax

3) Mimetex plugin:
Texviewer (internal img tags with local Mimetex...)
Google Chart API TeX (external img tags)
Cgi mimetex (external img tags with cgi mimetex)
Tex filter mimetex syntax

4) Mathtran plugin:
Mathtran (img tags with external mathtran)
Mathtran filter

5) AsciiMathML plugin:
AsciiMathML (MathML/image fallback)

6) Wiris plugins?
Others renderers?

7) JSXGraph (SVG/VML/javascript/filter) + GeoNext (Applet/filter)
8) AsciiSVG (David's plugin, SVG/GD fallback to embed/img tags)
9) GeoGebra (Applet/filter)?
...

Plus we need that common math filter with settings (for which options to use and drop) and possible user preferences and local customazations. MathJax as a package is larger than moodle itself but it seems to solve most math rendering problems we have had. It allows also font color and size control with outer spans and that works even in IE - untill you try print preview with scaled fonts in IE - but it's probably only a css issue.

Any new suggestions? These are still "prototype plugins"... and different settings can be set in filter settings, theme settings, user preferences (most difficult but possible) and in actual scripts.

PS. The test package will be coming some day during the next week(s)... I should just first cut grass, help my youngest daughter to create birthday party invitation cards and so on... days are too short for all these interesting issues wink









In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
If I may butt in here, Mauno...

I know this is an area of expertise for you and Marc, you guys have been at this for a long time, and I am a newbie, not even a neophyte yet... but it strikes me that in trying to generate as many different options as you can, the fundamental principals of providing a viable platform that is user friendly, a relatively easy learning curve (an optional extra in this area) and above all, works, is being somewhat negated. The issue then becomes that you can be spending so much time on trying to develop something extraordinary that you lose sight of the idea that it is a product that has limited use.

I do not suggest anything that would compromise the integrity of what you have done, but if you are trying to build a Rolls Royce on a Trabi budget, it is just not going to work. (The Trabi was ugly, woeful and, really, just not up to it, but it mostly worked, like the Tex Notation Filter.) Personally I would like to see a tool that I can just use, easily, and spend time going over it to learn the basics, then more advanced stuff. If I am confronted with 9 different options, each with their own little quirks, I might just give up in frustration before I have learned how to do even simple things.

If I am a User, new to Moodle 2.5 in 2013, I want a tool that I can use to develop formula, functions, equations as examples, for tests, for challenges, that I can smoothly transfer to a quiz. If I can also use that same tool to draw geometric shapes and add labels easily, for trigonometry, then bonus. If I can add in charts for quadratics, distributions and other statistical analysis, then I am out in front. I don't care if I need three different tools as long as I can be fooled into thinking it is an all in one package. It does not matter to me the guy who put this together is now occupying the Lucasian Chair, all I am interested in is "does it do what I want it to do?" and "Can I learn this quickly enough to make it useful?".

What you guys do is brilliant, I doubt there would be too many people who could do it, or be as good at it, or be as conscientious, as you two, but please remember that it is mere mortals like me that will be using it. It needs to be simple and straightforward - something I have noted that is severely lacking in some TeX and related tools...

Agghh enough, late and tired after a long and nightmarish day...
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

Yes, I have all the time wanted to create something simple and easy-to-use but the point is that what ever you do it does not fit to all sites.

Some sites can use what ever maths, some can't do anything. It all started from a need to find an "universal renderer" that would work everywhere - and after some years of work I have noticed that there is no such renderer - and probably never will be...

MathJax IS nice but it will most likely never find it's way to core moodle. Every one of those scripts has some BUTs:

I am not allowed to to run scripts on shared host...
My mootools scripts have conflicts with your javascripts...
Our school is using IE6 and won't change them...
We can't install any plugins or filters...
This script can't be used offline... and so on (list of "buts" is endless)

And still all those people WANT or NEED maths - just give me those scripts, Colin!!! big grin

Therefore I decided to try all possible scripts... no matter if I need them or not, just to test some possible solutions for those of us who have no tools at all available...

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Agreed, I have been in schools where the IT guys will just not move out of their comfort zone. "Does not matter what is available, if it does not fit into what I can see, I won't fix it if it is not broke." An attitude I have run into before and will again... Sometimes they need to be dragged kicking and screaming into the future though, by someone on the spot. This often makes me unpopular..big grin It is hard enough for me on my own, but when I got to drag someone else along, gawd, very difficult, not always successful and usually alienating.

The buts, the toos, the else's, the ands, are always going to get in the way - always have, because the picture a lot of people who make decisions on these things have of their world is surprisingly limited, and it should not be.

I think this is why we need simplicity even in extremely complex systems, just to be able to cope with it.

You are certainly right, one size does not fit all, so perhaps several, but not all, options need to be included as core. This allows people to make decisions for themselves, to pick something they think they need. Sure they will not always get it right, but if they can, and are honest, they will make a little effort if they have the opportunity to experiment with it, and chose what they think they need. As long as there is sufficient documentation to support their choice at our end, sooner or later they will get what they need.
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -
I think we can get close to a solution where the structure of adding plugins is there in core files and advanced users (universities etc) can install and use advanced plugins if they want/need to but we can still give some simple tools for typical schools too - starting from dragmath.

One of those tiny things that make using of maths easier is that you SEE the notation in editor. Not as tex filter code but as an image. Therefore I have added those output selection lists to my test plugins. If default value is set to images and if administrator of site has checked that math renderer does work users don't need to worry about different syntax of different latex distributions. They can just open dragmath, edit those notations that are avilable in dragmath, click to insert notations to editor and see WYSIWYG notations (hopefully) - the same notation that renderer shows on pages of moodle. We can go further and let users select that renderer or plugins that can use different code because some advanced users need some special code - and we can suppose that these advanced users know the syntax of latex - what ever distribution it is. It is possible to use all of these renderers at the same time on pages but if we mix the code to one plugin we get a mess - mathtran, mimetex and texlive all use different code for nth roots, googletex can use background colors and so can tex live but with different code while mimetex can handle only a handful of colors and mathtran can't use them at all. It may be difficult to get mathJax to render maths in actual editor screen, old scripts of asciimathml by Peter J and David L used mathml for FF and a clickable span tag for fallback images (javascript changed the class of spans to show code/image) but it is getting complex with MathJax. Using MathJax in plugin is easy and using it elsewhere in moodle is easy and MathJax supports most of the latex commands that Texlive does. Still a school teacher may ask a simple question - how do I create a simple fraction where 2 is red and 3 is blue - thoughtful - and how do I change fonts inside mathematical notations - and you will notice that your renderer is stuck. It can be done but not with most of these renderers.
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -
And graphs have been even more difficult to use - if we can use applets like GeoNext and GeoGebra in a plugin, or even offline, and either use future jsxgraph plugin to render dynamic graphs using those applet strings or saved files without need to use actual applet tags in editor we are close to an user friendly situation. In editor toolbar you can click the icon to open geonext applet, draw those circles and lines and save. The only remaining problem here is that you can't currently see the graphs in editor screen and we need to use a filter to change those long graph strings to actual graphs. But it may be a better option than using of script tags, applet tags, object tags and embed tags in editor - usually most users (other than administrators) are not allowed to use those tags in editor for security reasons but it will be safe to use filters to handle code coming from applets because those tags can't include malicious script tags - only graph tags.
In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Spaghetti, and a lot of people are going to be allergic to the sauce.

I can appreciate the scope of the problem and not sure I can help at all, but I can test stuff for you. Just remember, I am not a programmer and, being recently housebroken, barely literate, but I will do what I can.. thoughtful



In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Marc Grober -
You and Colin have been so, mmmmm, prolific on this topic that it will take me some time to catch up, lol.

Your list offers some intriguing combinations which would arguably be better understood through a matrix since some plugins address input while others address output and others yet address output fallback while others provide various combinations of all the above, lol. I can see why someone like Colin would feel his eyes rolling up in his head and his Blood Pressure rising wink

As I noted earlier, the nicest bit to me about MathJax is not the Tex rendering but the structure that allows the kind of pre and post processing I was arguing for with respect to asciimathml. MathJax can parse anything with an appropriate input jax file, and output anythign with an appropriate output jax file, so that it could do maxima for that matter, as well as webworks algebra, or asciimathml, and it can be configured to take advantage of whatever resources are available )so for example the file I posted allows MathJax to take advantage of the local availability of STIX fonts and a browser that is MathML compatible.

In sum, I think the core Tex filter for moodle should be redone to test for other options/libraries and I think that core Moodle should eventually include the ability to input and display math notation as I don;t agree with others that Math notation is outside Moodle's core focus. To that end I think that though asciimathML with googlecart api fallback might be the best candidate for inclusion, absent more energy on development and recognizing all the issues we have discussed to date, MathJax might be the best candidate, no matter its size, together with DragMath. And, should others decide to write to MathJax's API, that makes things that much simpler in Moodle.

SHort term wise, I would like to hear your rationale for your groupings (e.g. I don;t know why Mathtran is ina separate plugin, as opposed to being included with all the URL based plugins like mathtex, mimetex and google api.) I am going to think on your post for a bit, but did want to respond before you thought I had been overcome by mold and spored - lol

I do need to note that there is a potential issue with printing MathJax based resources (see, https://sourceforge.net/projects/mathjax/forums/forum/948700/topic/3819537 .)
In reply to Marc Grober

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

The only reason to my grouping is syntax - Google chart api is using mimetex syntax with some extra features while mathJax supports mostly the same latex as TexLive or MikTex - mathtran supports mostly old TeX.

Yes, I like Mathjax - and just noticed today that you can even mix normal unicode characters among mathematical notations INSIDE tokens, not only with \unicode {xxxx} - for example \frac{\alpha\beta\gamma}{αβγ}  ⊯  x + 2   testing      \alpha {\unicode{x270C}}^{ \unicode{43}} inside MathJax tokens works ok.

You can also partly control outer css with spans and styles but it's not yet perfect. FF seems to use default browser font for unicode characters and IE is using probably Tex font or Stix on my test site - anyway some parts work incredibly well, better than with any other tool.

Geonext applet works as well as dragmath and with jsxgraph filter those graphs are re-editable but I should probably change the plugin to produce img tags and filter should change those img tags to script tags - otherwise it is hard to find a solution to handle editor content area with graph size place holders or hyper long graph strings...

Attachment geonext.gif
In reply to Marc Grober

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

If it gives some relief to some users I have now set jsxgraph filter to render script tags if theme config.php does not have a line

$CFG->JSXGRAPHS = true;

in which case filter does not render script tags and it is possible to use custom scripts and css for jsxgraphs in different themes.

It looks like I can get the first package ready on Wednesday and I will add those new plugins and features as soon as they get ready.

The main problem with filter script output is that it renders script for each filtered graph and I haven't found a way to push script tags only once to header (or at all to header). Therefore theme based script tags work better. The good point is that even if some custom or core theme had no jsxgraph tags it can use jsxgraphs through filter - and we don't get "JSX is not defined" errors if javasript files are missing from theme.

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
Sounds serious, Mauno...big grin.big grin.big grin.big grin

Most themes seem to be working off base, that I have seen, so why would the script not fit onto the end of the base theme as a call to MathJax and jsxgraph scripts rather than as a part of the general.php? Or would it be better to place the scrips as part of the javascript array called on Line 150?
In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

Well... I have 3 good reasons:

1) My scripts do not need any hacks to core files so all you will need to do is install new files to correct places (or uninstall them from same places) - filters to filter folder, lib files to lib folder, editors to lib/editor folder, themes to theme folder - but no core files should be overwritten or edited

2) It does not seem to work through base theme layout files - script tags get never rendered if you place them to Base theme layout files (I thought they should but it did not work...)

3) In my opinion we could place all such javascripts that we use in several places to lib folder:

lib/dragmath/
lib/jquery/
lib/jsxgraph/
lib/geonext/
lib/MathJax/ (or should it be mathjax?)

and so on - unless themes have some good reason to use different files for different themes. No matter if they are core files or not.

I am never serious - setting this kind of timelines and promises is simply the only way to get things done - as a matter of fact I am "by default" lazy and indolent big grin

- but Marc and I just started this endless testing a couple of years a go with AsciimathML and some other editors like Xinha and FCKEditor. Looking back to those days we have gone long step forward... seriously...

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

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers
From the PHP pages I have looked at I can assuming that the /lib folder is freely available to any page that requires anything from that folder and can be invoked specifically by a setting somewhere, perhaps in the Manage Filters page?

That would make things certainly easier, and a lot more user friendly..

As for this comment of yours Marc:
"...I don;t agree with others that Math notation is outside Moodle's core focus."

In so many ways computers are linked so precisely to Maths but without sophisticated and often expensive and usually high learning curves (well the ones I have seen) programs, computers are not really used for much beyond basic Maths in many schools. Most schools adopt the line of least resistance and use poor substitutes which leave kids wondering what that was all about, or mind numbed from the inanity of the program. The teaching of Maths has declined in this country for a number of reasons, and one of them, I suspect, is that the tools available on computers do not get to the essence of the subject. Far from being outside the core interest of Moodle, it should be of stellar importance. Humanities and social sciences many earth sciences are more than catered for in Moodle, but not maths, not physics, not chem and these are absolutely core subjects to the schools. I noticed this long before I stumbled across TeX and took an active interest in the possibility of using Moodle for teaching Maths - and so have others. If Maths teachers can access these kinds of tools, then I suspect that Maths may even recover some of its lost ground.



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

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -
Marc,

are there any reports about odd functionality of \not ?

http://www.mathjax.org/resources/docs/?tex.html gives \not in the list of supported tex commands but if you try latex like

\not = or \not{\alpha} to get $$ \not = $$ or $$\not{\alpha}$$

mathjax shows slash too much to the right ???

If you use workarounds like \not{\;=} or \not{\;\alpha} you get slash to correct place but some extra space at the same time.




Attachment notpossible.gif
In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -
And \not does not seem to be scaled at all if you scale the other maths.It is of course possible to use unicode characters as a workaround...
Attachment not.gif
In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Marc Grober -
Yes, I have confirmed your findings and posted to Mathjax forum at https://sourceforge.net/projects/mathjax/forums/forum/948701/topic/3826870

However, I am using FF,STIX locally and MathML display and the slash is scaling:

Attachment slash_for_not_LARGE.png
In reply to Marc Grober

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

I scaled to 500% with

<p><span style="font-size: 500%;">@i \not\parallel\not\beta\not\gamma @i</span></p>
<p><span style="font-size: 500%;">@i \alpha\gamma\beta\sum\not\approx...\not\asymp...\not\prec...\not\sqsubseteq @i</span></p>

and the problem is not in scaling but IE hides some parts of slashes so it is some kind of a css bug in MathJax.

Attachment scaled.gif
In reply to Marc Grober

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

Marc,

Thank You for posting https://sourceforge.net/projects/mathjax/forums/forum/948701/topic/3826870

Problem solved - upgrading Stix fonts from version 0.9 to 1.0 (suggested by Davide) worked nicely and \not is rendered pretty well now.

If you need to upgrade your Stix fonts close all programs using Stix first - font files in use can't be upgraded... ( I had to do it twice )

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Marc Grober -
Speed of mathjax was actually pretty snappy if you configured to allow mathml and you used a mathml compliant browser and had appropriate fonts installed.

Directory structure can be almost as confusing as bracketing in hub file. BTW, Colin, you don't need to have all the hub stuff in the theme if you change defaults in mathjax config-hub just allows for local tweaking.

I guess I need to build the mathjax doc page, the example config I posted seems to be less explanatory than I had expected
In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Inline JS like this is really horribly, and doing it this way means editing every theme layout file.

It would be better to find a place where you can do

$mathjaxconfig = array(
'extensions' => array("tex2jax.js", "TeX/noErrors.js"),
'jax' => array("input/TeX", "output/HTML-CSS"),
'tex2jax => array('displayMath' => array(array('@d','@d')), 'inlineMath' array(array('@i','@i'))),
'HTML-CSS' => array('availableFonts' => array("TeX"])),
);
$PAGE->requires->js('/lib/MathJax/MathJax.js');
$PAGE->requires->js_init_call('MathJax.Hub.Config', array($mathjaxconfig));

It might work to do that in the theme config.php, but that is a bit of an abuse.
In reply to Tim Hunt

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

Tim,

I agree that your method is sweat but I haven't found any other method than layout files that works - if you find a place where other than theme layout code works, for all themes with one shot or even for one theme or where MathJax javascripts can be initialized otherwise,  please let me know. The method to place mathjax to theme javascript folder is worse because mathjax as a package is larger than moodle and duplicating mathjax files is not a good option so it should be in lib folder + MathJax gets never initialized with theme config.php & theme javascript folder method.

Hacking core files is the worst option, custom themes don't override any core code...

Placing this code to theme config.php renders blank page...

Can it be done with filters? Moodle 1.9 used to read javascript files from filter folder because lib/javascript-mod.php had some lines that checked filters, modules and blocks folders and if there was a file javascript.php it was automatically read but I haven't found such code from moodle 2 sad

I suppose you could use this php code in layout files as well but you will still need to add that script to all layout files - php tags or javascript tags...

In reply to Tim Hunt

Re: Moodlev2.0 and MathJax

by Marc Grober -
I think best option would be standard default reference to a library js file and folder something akin to what we saw in the buggy asciimathfilter situation where the file and any js lobs in folder are called at the top of the header by default.

That makes implementation very easy, it means one could even do php GUI config for it, user does not have to worry about php moodle hacks, and code can live outside moodle.
In reply to Marc Grober

Re: Moodlev2.0 and MathJax

by Marc Grober -
Maybe I should explain, Tim. The asciimathml filter continued to work even after it was turned off. It looked at the time like it was being sourced because of it's location (I recall a js_required or some such) irrespective of the filter switch. We avoided that behavior be relocating the js file and invoking in meta.php

If by default all themes referenced a sitewide file (which could be turned on/off or changed in theme configuration) this and other matters might be addressed more easily, while theme based filtering would be that much easier to manage.
In reply to Marc Grober

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

Yes, and standard theme meta.php could be used because most themes did use standard theme meta.php

Base theme layout files don't seem to initialize mathJax javascripts for other themes using Base theme as parent theme but I might have tried a wrong method -or made some mistake.

The old Asciimathml filter did use file javascript.php (automatically read from asciimathml filter folder that had code

var wwwroot = document.getElementsByTagName("script")[0].src.replace(/((.*?)\/lib\/.*)/,"$2");
document.write('<script src="'+wwwroot+'/filter/asciimath/ASCIIMathML.js"></script>');

but as far as I have seen such methods can't be used in moodle 2

Themes can still use javascripts with several methods and this layout file method is one of them - even if it may not be the recommended one like I said in my first post and even if inline javascripts may look horrible ... wink

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Darian Leduc -

PLEASE PLEASE HELP ....

you stated in your blog that:

2) Edit theme layout files (or base theme layout files) - supposing that you have a theme called colin in folder theme/colin and there is a layout file general.php add before </head> tag:


<?php echo $OUTPUT->standard_head_html() ?>

<script type="text/javascript" src=

"<?php echo $CFG->httpswwwroot ?>/lib/MathJax/MathJax.js">


MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/noErrors.js"],
jax: ["input/TeX", "output/HTML-CSS"],
tex2jax: {displayMath: '@d','@d', inlineMath: '@i','@i' },
"HTML-CSS": {availableFonts:["TeX"]}
});
</script>

</head>

Problem is -  have no general.php file to edit.  I am simply trying to get mathjax working. I do not know whcih php file to hack so that all pages within a certain course have mathjax capabilities. Using hosting server that does not allow 'installing' of binaries such as memtex.exe  etc....

So long and short is:

Where do I add your 'magical' green text as seen above? Whcih config file will automatically put onto each page - right at end of the header. I was trying to edit the standard them and changed the header.html file, but no dice...

 

Also somewhere I read that maxjax can be put into any folder ?  I have put it into the filter folder.  What is the correct path syntax in the green example above?

And lastly ... how does moodle detect that this filter exists.  I assume I need to edit some kind of cobnfig.php file in moodle ... I am quite confused.  Please have mercy and do help if you can....

MERCI in advnace


In reply to Darian Leduc

Re: Moodlev2.0 and MathJax

by Colin Fraser -
Picture of Documentation writers Picture of Testers

I hope you understand that this conversation was centred on testing out different Tex generators in Moodle 2.0 and that all themes in Moodle 2.0 have a structure that includes a file called general.php in the theme/<name>/layout/ folder.  We also need be careful here that the scripts be added to the child theme, not the parent theme/s. For example, if you open the brick theme, then look at the config.php file, you will see a line that reads

$THEME->parents = array('canvas','base',);

If you look at both canvas and base, they will have a general.php file in the /layout folder, but you do not put the script there, it goes into the /brick/layout/general.php file.

But that is not the end of it. Muano is in the process, is probably putting the finishing touches to it now, making it all easier without having to edit code at all. Remember, this is all in Moodle 2.0 and will be available, hopefully, as core for a future release.

If you are using Moodle 1.9.x then none of this is relevant at all.

 

 

 

In reply to Colin Fraser

Re: Moodlev2.0 and MathJax

by Alekx Zarley -

Hi, Colin -

In this last posting, you mention that Muano is still in process on this.  Has anything been worked out now that 2.0 is released?  What I mean is, is editing the general.php file as mentioned in this discussion the way to get this done or has another (better?) way been discovered?

Thanks.

In reply to Alekx Zarley

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

At least using theme layout file configuration (based on http://www.mathjax.org/resources/docs/?configuration.html ) allows you to use MathJax on all pages of moodle in a fully functional way - using the recommended javascript loading methods of moodle 2 may fail because MathJax itself is using rather special methods to render maths - see also http://www.mathjax.org/resources/docs/?dynamic.html#ajax-mathjax 

After example about loading mathJax dynamically there is even a note saying:

"Note that the only reliable way to configure MathJax is to use an in-line configuration of the type discussed above. You should not call MathJax.Hub.Config() directly in your code, as it will not run at the correct time — it will either run too soon, in which case MathJax may not be defined and the function will throw an error, or it will run too late, after MathJax has already finished its configuration process, so your changes will not have the desired effect."

I did test (2 months ago) rendering MathJax with filter but it was not fully functional - for example User profile and first one of two "optional versions" of Chat did not render mathjax code with filter code even if most pages and resources did. And sadly I have not found any docs about the "correct/recommended way" to use javascripts in moodle 2 filters (if there is some preferable way???)

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I don't understand Mauno. That page you link to tells you exactly how to get mathjax to start up property from JavaScript anywhere in the page. Why can't you use the JavaScript code they give, put into the page using Moodle's standard methods?

Mind you, I hope that page is wrong. I refuse to believe that the only way to load MathJax outside head is to use JS code to generate another <script> tag.

Try this. Create filter/mathjax/module.js. In there, put

M.filter_mathjax = {};

M.filter_mathjax.init = function(Y) {
Y.on('load', function() {
MathJax.Hub.Config({ config: "MathJax.js" });
MathJax.Hub.Startup.onload();
}, document.body);
}

Then, in your filter PHP code, put

$PAGE->requires->js('filter/mathjax/MathJax.js');
$PAGE->requires->js_init_call('M.filter_mathjax.init');

That is all typed off the top of my head into this email, and not tested, but I feel it should work (once you get all the paths right). Obviously, you could extend that to pass specific bits of configuration from the PHP code to the JavaScript.

In reply to Tim Hunt

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

Thank You Tim!

I will try it right away - and I think you might have just given "the missing key", the most valuable info I have been looking for with this module.js code smile

Is it documented anywhere in filter docs or javascript docs? I have used yui code in themes and have seen it in some modules (chat for example) but did not know that you can use it in filters as well (or originally HOW to use javascripts in moodle 2 filters smile ).

 

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

This should be in the JavaScript docs Development:JavaScript_guidelines. When I was updating the JavaScript in the quiz, I did try to update the docs with what I learned. Also note that a lot of the detailed documentation is in the PHP docs in lib/outputrequirementslib.php.

I think it would be better to use $PAGE->requires->js_module for the mathjax script, if possible. Then you could say that the filter/mathjax/module.js code requires that other code, and that should ensure that things are loaded in the correct order. But working that out might take a little more effort.

In reply to Tim Hunt

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

It will really take some time to work it out smile

Looking at my original source of my first trials (before $PAGE->requires->js_module trials) I was able to render javascripts and they were visible in source:

<script type="text/javascript"> //<![CDATA[ M.yui.add_module({"filter_mathjax":{"name":"filter_mathjax","fullpath":"http:\/\/localhost\/moodle\/moodle\/lib\/javascript.php?file=%2Ffilter%2Fmathjax%2Fmodule.js&rev=168","requires":[]}}); //]]> </script> <script type="text/javascript" src="http://localhost/moodle/moodle/theme/javascript.php?theme=arialist&amp;rev=-1&amp;type=footer"></script> <script type="text/javascript" src="http://localhost/moodle/moodle/lib/javascript.php?file=%2Ffilter%2Fmathjax%2FMathJax%2FMathJax.js&amp;rev=168"></script>

but mathJax did not seem to initialize the configuration anyway and did not render the maths - but I am sure there is some proper order to get mathJax initialized.

I think I will try to use the default configuration for a start (given by MathJax itself) and try to require configuration part next.

In reply to Tim Hunt

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

Tim,

if you have some time some day to try this filter approach it might make many people on Mathematics Tools forum happy.

I can't get it work right that way - javascripts are there in source but they don't initialize mystical MathJax onload scripts. I don't know if it is caused by timing, wrong paths. I tried even with unpacked versions of mathJax files - no luck!

In my tests the only method that works on all pages of moodle is still through layout files of current theme.

On the other hand if I create another simple filter for AsciimathML javascript with code like

function asciimath_filter($courseid, $text) {
  global $CFG,$PAGE;
  $PAGE->requires->js('/lib/common/AM1.js');
  return $text;
}

the script works (if filter is enabled) on most pages but not for example in User profile. If I use theme files to render AsciimathML I get Asciimathml rendered with no problems in User profile.

Is there any good reason for this behaviour - missing context etc?

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I probably don't have time, but I do you have a Zip file, or git repostitory, that shows where you have got to, and has everything I might need in it?

In reply to Tim Hunt

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

All the basic docs are in http://www.mathjax.org/resources/docs/ and you can download the full MathJax package from

http://sourceforge.net/projects/mathjax/files/MathJax/v1.0.1/MathJax-v1.0.1a.zip/download

It includes a folder MathJax and inside that folder are both minimized and unpacked versions + Tex fonts that make mathJax cross browser compatible.

At the beginning of my previous posts you can see the idea of using MathJax.js script with theme layout files and how to change tokens and other settings - all the configuration options are documented on MathJax main site

The main point is that it would be much easier for new moodlers to render mathjax scripts with filter if you just could create such a filter that renders mathjax - or some other "universal method" - editing theme layout files works fine but some users are not allowed to change their site themes or do not trust their capability to edit theme files wink

Stix fonts can be useful as well but they are not at all required. If you want you can for example set

jax: ["input/TeX", "output/HTML-CSS"]

and

preferredFont: "TeX"

or use just default settings of MathJax.

You can also obtain mathJax via git - see http://www.mathjax.org/resources/docs/?installation.html

In reply to Mauno Korpelainen

Re: Moodlev2.0 and MathJax

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Actually, as of a few days ago, we have a new admin setting in Moodle 2.0: Admin -> Appearance -> Additional HTML -> Within HEAD

I only discovered that today, but it looks like the answer.

Average of ratings: Useful (1)
In reply to Tim Hunt

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

Thanks again Tim!

This is a very useful setting and it works fine. I suppose people need to use there absolute paths for scripts - php tags did not seem to take effect - in my test install ( http://localhost/moodle/moodle ) I used the following tags and MathJax worked like a charm also in User profile:

<script type="text/javascript" src="http://localhost/moodle/moodle/lib/MathJax/MathJax.js">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/noErrors.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX", "output/HTML-CSS"],
tex2jax: {displayMath: '@d','@d',  inlineMath: '@i','@i' },
"HTML-CSS": {availableFonts:["STIX","TeX"]},
preferredFont: "TeX"
});
</script>

The main advantage to theme layout files is that with this admin setting it is possible to use certain scripts on all pages and themes of moodle without need to edit all theme layout files. On the other hand if you need to disable scripts on some pages theme layout files give some more flexibility and if custom filters were functional it would be possible to use filter code context based.

Anyway - now we have two fully functional ways to use mathJax - Great! smile

In reply to Tim Hunt

Re: Moodlev2.0 and MathJax

by Dmitry Borovikov -

Dear Tim,

Could you help me with following issue?

I installed MathJax and it work almost correclty. But when I inserted following string:

There are two solutions to @d ax^2+bx+c=0 @d and they are

I got:

There are two solutions to

ax2+bx+c=0

and they are

So the equation breaks my origin string. How can I fix it?

Thank you in advance!


In reply to Dmitry Borovikov

Re: Moodlev2.0 and MathJax

by Mauno Korpelainen -

Dmitry,

isn't that exactly what you are supposed to see (except that current moodle 2 themes have an yui reset code bug with superscript/subscript... http://tracker.moodle.org/browse/MDL-25565  )

Displaymath adds linebreaks before and after notation and shows your notion centered while inline maths shows notations as a part of other text

So if you have used displayMath: '@d','@d',  inlineMath: '@i','@i'

try

There are two solutions to @i ax^2+bx+c=0 @i and they are...