'Integration' of jsMath filter with MimeTeX

'Integration' of jsMath filter with MimeTeX

door Luca Mazzola -
Aantal antwoorden: 3
Hi,
we are tring to force an integration of jsMath with MimeTeX filter.
We modified tex filter: it doesn't operate if jsMath is active and javascript are available in the user's browser.
In this way, when possible, all the load is demanded on the client-side, making server more 'confortable' in page with many crunch of TeX code. At the same time, we offer to anyone who doesn't have the requested condition, a correct form anyway.

At now, the modified version operate quite well on moodle 1.6.0dev; because in 1.5.3+ we noticed some strange behaviours; even if we think these are minor problems (we are working on, clearly approve ).
All the difference is hosted into file filter.php in the tex filter. The attached file is from the last stable version.

As minor enhancement we provide a possible solution wink for the well-known feature of TeX filter: when someone modify the code, every double escape ('\\') is trasformed into a singol ones ('\'): our hypotesi is that every sequence of double escape is directly followed by a space, and we substitute every ('\ ') with ('\\ ') before passing the code to the filters.

Every comment, problem and suggestion is wellcome.

TIA, LkM.

P.S: If Davide Cervone would contact me, I'm very well to think about better integration way, because, at now, some choice isn't the best, but only a faster ones. Thanks, LkM.
Gemiddelde van de beoordelingen:  -
Als antwoord op Luca Mazzola

Re: 'Integration' of jsMath filter with MimeTeX

door Davide Cervone -
I haven't had the chance to look at your code, but this is a good project, and well worth pursuing. I will help in any way I can.

I have left you a message using the Moodle message facility (click on my name above and you should be able to view it). It gives my email address so you can contact me directly, if you wish.

Davide
Gemiddelde van de beoordelingen:  -
Als antwoord op Davide Cervone

Re: 'Integration' of jsMath filter with MimeTeX

door Luca Mazzola -
At first, I apologize myself for my poor English...

The main problem of the integration is the use of cookie to known if javascript is active on the client side ( and so block MimeTeX
filter to parse server-side the code).

But to achieve this goal, we need to set it outside the filter
itself, because before we read the presence of the cookie(with php code, an so decide) and then execute on the client side the
javascript section to set this value.

At now, we hadn't no other idea to resolve the problem without set a cookie in tho steps, as explained.

If you could see the code and have suggestions, corrections or
improvements, we are very pleased to hear them.

Thanks and best whishes, LkM.
Gemiddelde van de beoordelingen:  -
Als antwoord op Luca Mazzola

Re: 'Integration' of jsMath filter with MimeTeX

door Davide Cervone -

I have had the chance to look at what you have done, and the cookie idea is clever, but it has some problems:

  • The cookie will not be available on the first page that the viewer sees (since the cookie comes from the previous page that the user has viewed, and on their first page, there is no previous page). This is probably not too bad, since the first page they will see generally will be a login page or the website home page, and neither is likely to need mathematics. Even if it had math, it would be OK to use mimeTeX for that.

  • More serious, however, is the fact that you will have to disable the page cache if you use this approach. That is because the page will vary depending on what user is viewing it (and whether they have JavaScript enabled), so the cached page may not be suitable for the next viewer, since it was created using someone else's browser settings. (If you didn't turn off moodle's caching of pages in the Administrator's Filter Configuration page, you probably ran into all kinds of problems when you debugged this. If your page seemed to not respond to the changes you made, check that you have turned off caching.)

  • Third, the way the the tex filter interprets the delimiters for mathematics and the way jsMath does do not always agree. For example, with the tex filter, double-dollar signs introduce in-line mathematics, while in jsMath they are for displayed equations (centered in a separate paragraph). This means that the page will look different for different users, depending on whether they get the jsMath filter or the tex filter.

I have an alternative suggestion for you that overcomes all these problems. The idea is to let the browser make the decision about which filter to use, rather than the filter. That is, the filter inserts both the jsMath form and the tex form (in a clever way) and the browser shows only one of them. Here's the way it works:

The tex filter is modified to insert its images within NOSCRIPT tags, so they will not be processed when the user's browser has JavaScript enabled (but will be shown otherwise). Then the filter inserts the SPAN that jsMath needs, so that when JavaScript is running, jsMath will process and display the mathematics. The clever bit is to wrap the jsMath tex code in a SPAN that is marked with a CSS style for "display:none" so that when JavaScript doesn't run, the jsMath tex code is not shown by the browser. When JavaScript is running, jsMath will replace the extra SPAN with the typeset mathematics, and so it will be displayed in that case.

This means that when JavaScript is not running, the jsMath tex is not shown but the tex-filter image in the NOSCRIPT block is shown, while if JavaScript is running, the tex-filter image is not shown, but jsMath will process the hidden tex code and replace it with (visible) typeset mathematics.

Note that the same page is sent to every user, regardless of their browser settings, so caching will work, and this doesn't rely on cookies, so it works on the first page the user sees (and also continues to work if the user switches browser settings while viewing the Moodle site). Since the tex-filter is inserting the jsMath SPAN itself, this method does not rely on the tex2math component of jsMath (which is what the jsMath filter uses to convert dollars or other delimiters into the SPAN and DIV tags that jsMath uses), so the results will be consistent no matter which version the user sees of the mathematics (jsMath or mimeTeX).

Finally, if the tex-filter is made to insert the jsMath SPAN tags and the NOSCRIPT tags only when the jsMath filter is active, then if the jsMath filter is disabled by the site administrator, the tex filter will operate as is used to, regardless of the user's browser settings. Furthermore, jsMath can continue to operate on other tags (if you wish), independently of the tex filter.

So I think this takes care of all the contingencies. (Of course, someone will prove me wrong, but I think it looks good.)

There are several caveats, however:

  • First, you need to get the latest version of the jsMath filter (I recently updated the version on the CVS server so that the jsMath filter can be turned off in the administrator's menu. Due to the fact the Moodle ships the javascript from every filter on your system, regardless of whether it is active or not, it used to be that the filter would run even when it was not selected in the filters list. I only discovered that while working on this issue.)

  • Second, you must make sure that the jsMath filter runs before the tex filter (i.e., above it in the filter list). This is so that the tex filter can tell that jsMath is active.

  • Third, you should set the "processTEXtags" flag to 0 in the jsmath/filter.php file so that it won't translate the tex tags itself. (We want the tex filter to do that since it is the one that is setting things up to work with both filters.)

  • Finally, you probably want to set the "processSlashParens", "processSlashBrackets", and "processDoubleDollars" flags to 0 in the jsmath/javascript.php file. This will prevent jsMath from accidentally processing other mathematics on the page and so it will only process the math that the tex filter would normally handle.

I have attached a copy of the replacement for the tex/filter.php file that includes the needed changes. They are pretty minimal, and I have marked them with "DPVC" comments.

Hope this works for you.

Davide

P.S., I have not tested this on MSIE on the PC, as I don't have access to that over the weekend. But it should work. (Famous last words.)

Gemiddelde van de beoordelingen:  -