jsMath version 3.0 and new filter released

jsMath version 3.0 and new filter released

by Davide Cervone -
Number of replies: 20
I have released a major update to jsMath and a new version of the Moodle filter for it. You can download it from the contrib section of the Moodle CVS site. You will need to get the latest version of jsMath when you change to the new version of the filter, as it is not compatible with the other versions of jsMath (it is also available on the CVS site). It might also be useful to read the change log for details of what has changed in this version. One change that some of you might want to know about is that jsMath now uses a different set of ttf fonts (though it will still use the old ones if you have already installed them). One reason for this is that many have complained that they were too light on the PC, so I now provide them in a variety of darknesses that you can choose from.

The main changes are internal having to do with the way that jsMath loads external files. But this change makes it possible to overcome the problem Petr Kalis reported with jsMath in Wiki mode, and that was a driving factor in my getting version 3.0 out faster than I might otherwise have done.

This new version of the jsMath Moodle filter works in a very different way from the older one. My original version did most of the work in the filter itself, so that the text of the message was modified to include the JavaScript that gets jsMath going. That is no longer the case with the current jsMath filter. The filter does not modify the text (except to replace <tex> and </tex> references). All the work is done in JavaScript after the page is loaded. (This is what fixes the problem with Wiki mode, since the inserted JavaScript was being removed by the Wiki module.)

The filter uses jsMath's autoload plugin to scan the page for math and only load jsMath when it is needed. This will give you the same end result as before, but there is a change in the timing that you should be aware of. In the original filter, jsMath would be loaded at the point where the first piece of mathematics appeared on the page (and the page would delay at that point until jsMath was fully loaded, even though the mathematics would not be processed until the page was complete). With the new filter, however, the check for whether jsMath needs to be loaded is not performed until the page is complete, so the delay comes after the page is displayed. Since loading jsMath can take a noticable amount of time, there may be a significant delay between when the page appears to the user to be complete and when the mathematics is processed. (Most browsers will cache the jsMath files, so on subsequent pages, the delay will be considerably less, but the first page will have a noticable delay.) Because the page will already be displayed when this delay occurs, some impatient users may wonder why the math is not showing up right away.

To help out, the filter puts a small message in the lower left-hand corner indicating that it is loading jsMath (which can take a while), and when jsMath is running, it will put up a message indicating how far along it is. Observant readers will be able to use this to recognize that the page is not yet complete even though it has appeared on screen.

The important file in the new version of the filter is javascript.php, not filter.php, and the javascript.php file is the one that includes the configuration information that used to be at the top of filter.php. So if you want to change the settings (like what stings to use for delimiting mathematics), you will need to edit the array at the top of javascript.php. not filter.php. (The filter.php file only handles the <tex> tag, so the configuration in that file only controls that one option.)

Anyway, give the new filter a try, and please let me know if you have problems. Since jsMath version 3.0 is new and significantly different from jsMath 2.x, there may well be minor problems that need to be taken care of.

Davide

PS, this version of jsMath also takes care of some problems that cropped up with Firefox 1.5, so you may want to update if you have lots of firefox users.

Average of ratings: -
In reply to Davide Cervone

Re: jsMath version 3.0 and new filter released

by venkatesan iyengar -
Dear David,

Sorry I could not see math functions. I do not even see the jsmath button at right corner. However, it is visible in your webpage. All the PHPs are chmoded to 755, Js are also chmoded 755. Filter is already enabled (from 2.x version) in my admin. I did the upgrading by replacing the old files. Of course I did not replace that 7MB font folder. What is wrong?
In reply to venkatesan iyengar

Re: jsMath version 3.0 and new filter released

by Davide Cervone -
I assume you got the new filter.php and javascript.php files, right?

What browser are you using? If it has a JavaScript Console (check its menus), are there any error messages there?

You may need to clear your browser cache, because an important part of the filter is now included in a file that is created automatically by Moodle, and its name will not change, so your browser may have cached the version that doesn't include the new jsMath material. Try clearing the cache and let me know if you still get no mathematics.

Davide
In reply to Davide Cervone

Re: jsMath version 3.0 and new filter released

by venkatesan iyengar -
I have uploaded filter.php and javascript.php to moodle/filter/jsmath/ folder and all other files in /jsmath/jsMath/ folder. The old image fonts are there in jsMath/fonts folder. I tested in windwos IE6 and Opera 8 and both did not reder the equations. javascript console in opera did not show anything. I think the filter was not initiated. Any suggestion? Your site math functions look beautiful in my browsers!
In reply to venkatesan iyengar

Re: jsMath version 3.0 and new filter released

by Davide Cervone -
The key file is javascript.php. It gets incorporated into a common javascript file that is included in the HEAD of every moodle page. Try downloading the URL moodle/lib/javascript-mod.php from your server, and see if it contains what is in moodle/filter/jsmath/javascript.php. (On my site, that is ALL that is included, but I don't have any other filters enabled.) You actually have to download this through your browser, not look at the file on the server via the command line, as the contents of this URL are generated on the fly by the server when the URL is loaded.

If moodle/lib/javascript-mod.php is either empty or does not contain the 16 KB or so that is the jsMath javascript.php file, then that is the problem. If it DOES contain the jsMath code, then the problem is with that code. I suspect the former will be the case, as I the code works for me in MSIE and Opera (and Firefox and Safari and OmniWeb).

I still think there may be a caching issue either with the browser, or possibly with the server. If you are using a server cache (like Squid with Apache), that might be the problem, too. The old version of moodle/lib/javascript-mod.php might still be in the server cache rather than the new one that includes the updated jsMath code.

If you can, try restarting the server and its cache, and make sure you have emptied the caches in your browsers as well. If that doesn't do it, try adding a line like

    alert('here');
to the beginning of the jsMath javascript.php file, and see if you get an alert message when you load a moodle page. If yes, then you will know the javascript.php file is being sent to the browser. (If not, then you would need to look into the caching further.) Then try moving the message to the END of the javascript.php file and see if you still get the message (change the text of the message to make sure you are getting the new alert message not some cached version of the old one). If you get it at the beginning but not at the end, then there is a problem with the jsMath code.

When I was testing things, I found that I frequently had to empty the cache in between each test, as the old version of the javascript was till being used by the browser even after it was changed on the server.

Let me know what happens.

Davide

In reply to Davide Cervone

Re: jsMath version 3.0 and new filter released

by venkatesan iyengar -
Thanks for your prompt reply. I found that the javascript-mod-php (downloaded from browser) contains all the jsmath/javascript.php codes (14.8 kB). I tried to remove the server cache (since I'm on webhost, I did it from my cpanel). I included two messages alert('jsmath_begin_here'); at the beginning and alert('jsmath_end_here'); at the end and both works well. Still I could not see the math functions. Even my localhost (moodle with xampp on windows) also did not work. Sorry for bothering you so much. Since I overwrote the files of the earlier versions, I could not even go back.
In reply to venkatesan iyengar

Re: jsMath version 3.0 and new filter released

by venkatesan iyengar -
Presently I could render the math function in opera browser alone by using the older filter.php with latest jsMath version and not javascript.php version.
In reply to venkatesan iyengar

Re: jsMath version 3.0 and new filter released

by Davide Cervone -
The old filter.php is not really compatible with jsMath v3.0, though it could be modified to work with it (though that would not fix the Wiki problem that I was trying to solve with this release). I will work out the changes and post something as soon as I get the chance.

Davide
In reply to venkatesan iyengar

Re: jsMath version 3.0 and new filter released

by Davide Cervone -
OK, that rules out my first theory (caching problems), and that makes diagnosing it harder.

The next thing to check is that you have configured the javascript.php file the same as your original filter.php file. That is, make sure the settings are correct for the delimiters that you are using for mathematics in your messages. Are you using double dollars and \(...\) and \[...\]? Note that single dollars are off by default, and if you set your own delimiters, you will need to make sure they are set in the javascript.php file. If you were using <tex> tags, make sure the settings in filter.php are correct as well.

You can get back versions of both jsMath and the filter from the CVS archive, so you can go back to the old version if you need to. You can also get old versions of jsMath from the old versions page of the jsMath site.

If the settings are all correct, then I may have to ask if you can set up a test area where I can try it out and see if I can figure out what is going on. I just tried downloading the CVS copy myself and installing it again here, and everything seems to work. If you could make a public forum where I could test this out, I might be able to figure out what is happening.

Davide

In reply to Davide Cervone

Re: jsMath version 3.0 and new filter released

by venkatesan iyengar -
Here it is http://puchemistry.org/course/mod/forum/discuss.php?d=1.

Please use my test student login

login:student

pass:student
In reply to venkatesan iyengar

Re: jsMath version 3.0 and new filter released

by Davide Cervone -
Great, that was exactly what I needed to see. It turns out that the javascript.php file was not being smart enough about determining the location of the jsMath root directory. It had been looking at the current page's address and trying to find the "moodle" directory, but your site has "course" as its root rather than the default of "moodle". So the autoloading code was not able to find the jsMath directory correctly.

I have fixed this and put a modified version of the javascript.php file in the CVS repository. I think this will clear up the problem for you. I do not currently have access to a PC to test this on, but I'm pretty sure it will work in MSIE on the PC. (It works in Firefox and Opera on the Mac, so should work with those on the PC; MSIE is the usual trouble maker.)

Anyway, let me know if this works for you. Thanks for setting up the test account; that really helped.

Davide
In reply to Davide Cervone

Re: jsMath version 3.0 and new filter released

by venkatesan iyengar -
Thanks David, It is now fine and working great. Actually I was also thinking in the same line and I was about to mail you. You are excellant. Martin's moodlers are wonderful.
In reply to Davide Cervone

Re: jsMath version 3.0 and new filter released

by venkatesan iyengar -
Dear David,

Sorry to disturb you again. Now I lost my arrows. Earlier it was implemented through separate javascript files. I'm particularly interstested in rendering chemical equations, reversible reaction equations with single sided arrows double sided arrows, text above and below arrows, right and left sided harpoons etc. Is it possible to incorporate these things now. Some of my requirements are given below:
mimetex.cgi?x\rightarrow\limits^g_yz
mimetex.cgi?x\rightharpoon\limits^g_yz

and other combinations of these.

thank you
In reply to venkatesan iyengar

Re: jsMath version 3.0 and new filter released

by Davide Cervone -
Right, we had an external file (moreArrows.js) that needed to be loaded to add these features to jsMath. We did that by modifying the filter.php, and of course the new javascript.php does not include those changes.

Here's what you need to do. Put the moreArrows.js file into the filters/jsmath/jsMath/plugins folder. Then edit the javascript.php file as follows:

Just below the message "DO NOT MAKE CHANGES BELOW THIS" you are going to make a change. Just above the "findMathElements: 1," at line 73, insert

    loadFiles: "plugins/moreArrows.js",
so that you now have
    jsMath.Autoload = {
      loadFiles: "plugins/moreArrows.js",
      findMathElements: 1,
      findTeXstrings: 0,
      findLaTeXstrings: 0,
      findCustomStrings: jsMath.Moodle.customDelimiters
    };
That should cause the autoloader to load moreArrows.js whenever jsMath is loaded for a page.

If you deleted moreArrows.js, I can seend it to you again (or it may be linked to our previous discussion of this, where you can still get it).

Good luck.

Davide

(PS, it really is "Davide" with an "e", not "David").

In reply to Davide Cervone

Re: jsMath version 3.0 and new filter released

by venkatesan iyengar -
Thanks for your support. It is now working fine. I apologise for my spelling mistake in writing your name.
In reply to venkatesan iyengar

Re: jsMath version 3.0 and new filter released

by Davide Cervone -
No problem. Glad it is working again. No need to apologize; many people don't even see the "e".

Davide
In reply to Davide Cervone

Re: jsMath version 3.0 and new filter released

by venkatesan iyengar -
Sorry the moreArrows.js worked, only when I included at

if (jsMath.Moodle.mimetexCompatible) {
jsMath.Autoload.loadFiles = "plugins/mimeTeX.js";
jsMath.Autoload.loadFiles = "plugins/moreArrows.js";
}

and not at the place where you said. Let me test more arrow syntax (our organic chemistry teachers use quite frequently in describing their chemical reaction mechanism) and inform you.

thankyou
In reply to venkatesan iyengar

Re: jsMath version 3.0 and new filter released

by Davide Cervone -
Right, the mimeTeX plugin would overwrite the earlier setting of loadFiles.

On the other hand, your version will overwrite the mimeTeX file, so it will not be loaded. You could use

    if (jsMath.Moodle.mimetexCompatible) {
      jsMath.Autoload.loadFiles = [
        "plugins/mimeTeX.js",
        "plugins/moreArrows.js"
      ];
    }
instead so that both files will be loaded.

I have just released a new version of the jsmath filter that will allow you to put loadFiles (and loadFonts) in the configuration section at the top of the file, and will properly handle adding the mimeTeX code to the list, if requested.

I've also included the moreArrows.js file as one of the new extensions to jsMath, so it comes with the latest version (and you would load extensions/moreArrows.js rather than plugins/moreArrows.js).

Davide

In reply to Davide Cervone

Re: jsMath version 3.0 and new filter released

by Petr Kalis -
Hi Davide
Im glad you made a new version of jsmath filter because of meblush(just jokingbig grin). I just wanted to ask you, because i had similar problems like venkatesan, jsmath filter wasnt working, so i suspected autoload function. But just after i wrote big post with plea for help, i miraculously got jsmath to work(now i suspect caching problem or i dont know what, made many tries and errors)..but..just barely. I got this warning: "It looks like jsMath failed to set up properly. I'll try to keep going, but it could get ugly." and most of the formulas is not showing, some easy like $$x^2$$ are showing correctly, others ones arent showing at all.
So, i have to ask you for help after allwink
Thanks for advice.
Petr
In reply to Petr Kalis

Re: jsMath version 3.0 and new filter released

by Davide Cervone -
This error message means that jsMath.js was loaded properly, but that something went wrong during its initialization phase. This is where it sets up things like the jsMath button, determines the browser and loads browser-specific code (if needed), and defines the CSS styles needed by jsMath. One of these operations has failed.

First, what browser are you using?

Second, what settings are in effect in the javascript.php file? (Can you cut and paste the settings that you are using into a message for me?)

A number of people have had problems that are due to the browser or server cache containing older versions of one or more of the jsMath files. Be sure you clear the browser cache before loading the first page that contains mathematics. If your server uses a page cache, you might need to reset that as well (sometimes restarting the server will do that automatically).

If that doesn't work, I may have to take a look at it. Can you set up a test forum where I can view a page that contains mathematics? I might be able to figure it out from there.

Davide
In reply to Petr Kalis

Re: jsMath version 3.0 and new filter released

by Davide Cervone -
Petr:

I think I might have taken care of your "jsMath failed to set up" problem. It turns out that MSIE was sometimes having trouble locating the image fonts, and that could result in this message. Try getting the latest release (3.1a) and see if that helps. Otherwise, I'm waiting for more information from you. FYI, this release also include an error code in the "jsMath failed" message that should help me to locate the problem, so if you continue to get the message, please let me know the code that it reports.

Davide