JsMath/JsTex instead of mimetex

Re: JsMath/JsTex instead of mimetex

by Martin Dougiamas -
Number of replies: 54
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Davide is now maintaining this module in cvs:/contrib/jsmath

The latest version can always be downloaded as http://download.moodle.org/download.php/modules/jsmath.zip
In reply to Martin Dougiamas

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
One thing to be aware of with the CVS version: since the directory in the CVS repository is called "jsmath" rather than "jsMath", the filter it contains expects to be in a directory called "moodle/filter/jsmath" not "moodle/filter/jsMath", as I suggested above. So if you ever get a new copy, you will need to change the name of the directory. This will require you to deactivate the old jsMath filter and then activate the new jsmath one. Sorry about that, but they seem to prefer all lower-case names in the CVS directories, and I didn't want to have the two names to be inconsistant.

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Sjaak Kamerling -
I have a problem with these jsMath-things. I created within Fantastico a Moodle-environment. The algebra- and TeX-filters don't work, so I installed jsMath; I tried with moodle/filter/jsMath + moodle/filter/jsMath/jsMath and with moodle/filter/jsmath + moodle/filter/jsmath/jsmath;
in both cases nothing happens; within moodle-administration I activated jsMath, but when I type in one of the input-windows mathematical text between doubledollarsigns the input is not 'translated' in mathematical text;
am I doing something wrong?
I have downloaded the latest version(b) from the jsMath-website and from the cvs-environment I downloaded the filter.php-file.
In reply to Sjaak Kamerling

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
I think there is one more combination that will work for you: moodle/filter/jsmath with moodle/filter/jsmath/jsMath.

When you view a page containing mathematics (like the one you created using double dollars), you should see a small "jsMath" button at the lower right-hand corner of the screen. If you do, then jsMath and the filter.php have been installed correctly. If you see this and are still not seeing typeset mathematics, let me know.

If you DON'T see this, then it is probably a configuration problem. Here are some things to try: first, view the source of the page that contains the mathematics, and look for jsMath.js (it should be in a SCRIPT tag near the first piece of mathematics on the page). If you see this, then the filter is running correctly, but jsMath is not loading. Check the URL for jsMath.js to make sure it matches the location of jsMath on your server. (It should be something like "http://yourserver.edu/moodle/filter/jsmath/jsMath/jsMath.js".)

If the URL is correct and you still aren't seeing mathematics, try typing the URL into your browser by hand and see if your browser can load the jsMath.js file, or whether you get an error message. It is possible that the file permissions are not correct and the server is not sending the jsMath.js file. You should also check that you can load the moodle/filter/jsmath/jsMath/plugins/tex2math.js file as well. if either of these fail to load, you will not see any mathematics.

You might also be able to get more information from the web server's error log, as this may tell you more details about why one of the files is not being able to be served (e.g., file doesn't exist, file permissions don't allow it, etc.)

Hope one of these helps.

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Sjaak Kamerling -

Thanks for your fast answer. Now, with the right capitalizing, I get the jsMath button! Unfortunately I don't see typeset mathematics. In the places that are doubledollarsigned, there is blank space.

In reply to Sjaak Kamerling

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
OK, that probably means that you have jsMath installed properly, but that is is not processing the math correctly. If the math has been removed from the page, that means jsMath has partly run (it has located the TeX code), but probably crashed trying to process it, so it never was replaced with the typeset math.

Can you tell me what browser (and version number) you are using, and one what type of computer? Also, can you tell me the version number of jsMath that is reported in the jsMath control panel (obtained by clicking on the jsMath button at the bottom of the screen). Finally, what font mode are you using (it is listed just below the jsMath version on the control panel, in parentheses)? You can send me this information my email and once we get things worked out, I will summarize to this forum; no need to carry on a debugging session on line.

If your browser has a JavaScript Console, are there any messages listed there? (Look through the menu items to see if there is a JavaScript Console anywhere. Note that the Java Console is a different thing.)

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by kathy hooper -

Hi'

I can get JsMath working on my home server running moodle 1.6, but not on the one at school running 1.5+.Here I get the error messages -

Notice: Use of undefined constant version - assumed 'version' in C:\apachefriends\xampp\htdocs\filter\jsmath\filter.php on line 54

Notice: Use of undefined constant processDoubleDollars - assumed 'processDoubleDollars' in C:\apachefriends\xampp\htdocs\filter\jsmath\filter.php on line 55

Notice: Use of undefined constant processSingleDollars - assumed 'processSingleDollars' in C:\apachefriends\xampp\htdocs\filter\jsmath\filter.php on line 56

Notice: Use of undefined constant processTEXtags - assumed 'processTEXtags' in C:\apachefriends\xampp\htdocs\filter\jsmath\filter.php on line 57

Notice: Use of undefined constant mimetexCompatible - assumed 'mimetexCompatible' in C:\apachefriends\xampp\htdocs\filter\jsmath\filter.php on line 58

Notice: Use of undefined constant scale - assumed 'scale' in C:\apachefriends\xampp\htdocs\filter\jsmath\filter.php on line 59

Notice: Use of undefined constant showFontWarnings - assumed 'showFontWarnings' in C:\apachefriends\xampp\htdocs\filter\jsmath\filter.php on line 60

Notice: Use of undefined constant filter - assumed 'filter' in C:\apachefriends\xampp\htdocs\filter\jsmath\filter.php on line 61

Notice: Use of undefined constant loaded - assumed 'loaded' in C:\apachefriends\xampp\htdocs\filter\jsmath\filter.php on line 62

Any ideas?

thanks   kathy

In reply to kathy hooper

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
It sounds like the version of php on the two machines is different as well (or at least have a different level of error reporting enabled), and that the one at work is complaining about the way the array at the top of the file is constructed. Try replacing
    $CFG->jsMath = (object)array(
      version => 1.0,               // version of this file
      processDoubleDollars => 1,    // process $$...$$ in text
      processSingleDollars => 0,    // process $...$ in text
      processTEXtags => 1,          // process <tex>...</tex> in text
      mimetexCompatible => 1,       // make jsMath handle mimetex better
      scale => 120,                 // the default scaling factor for jsMath
      showFontWarnings => 0,        // show jsMath font warning messages
      filter => 'filter/jsmath',    // where the filter is found
      loaded => 0                   // internal use
    );
with
    $CFG->jsMath = (object)array(
      'version' => 1.0,               // version of this file
      'processDoubleDollars' => 1,    // process $$...$$ in text
      'processSingleDollars' => 0,    // process $...$ in text
      'processTEXtags' => 1,          // process <tex>...</tex> in text
      'mimetexCompatible' => 1,       // make jsMath handle mimetex better
      'scale' => 120,                 // the default scaling factor for jsMath
      'showFontWarnings' => 0,        // show jsMath font warning messages
      'filter' => 'filter/jsmath',    // where the filter is found
      'loaded' => 0                   // internal use
    );
in moodle/filter/jsmath/filter.php.

The error messages seem to be complaining about the names being used on the left of the arrows, which php is trying to interpret as constants. Putting the quotes around them should clear up the messages. Good luck. Davide

In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by kathy hooper -

Thanks for that Davide,

it is almost working without errors - just one

 
Notice: Undefined property: stdClass::$loaded in C:\apachefriends\xampp\htdocs\filter\jsmath\filter.php on line 84

line 84 is

if ($CFG->jsMath->loaded) {return $text;}

any further ideas?

thanks

kathy

In reply to kathy hooper

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
Well, my first thought was that perhaps the $CFG->jsMath object was not getting set up properly, but the fact that it got past $CFG->jsMath->processTEXtags several lines earlier suggests that it is.

So my second guess would be that something is not right with the initialization of the 'loaded' property at the top of the file (around line 60). If you inserted the quotes that I suggested above by hand, check that you have not accidentally inserted anything else on the 'loaded' line (like perhaps an extra space or character inside the quotes).

If you copied and pasted the code from my message, that probably won't be the problem. In that case, can you email me the copy of the filter.php that you are using? I'll see if I can see anything that might be the problem. Also, can you determine what version of php you are using?

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Sjaak Kamerling -

Hello,

I replaced the 2.3b-version in 2.3c, but this is no solution for my problems; I get exactly the same behaviour as I mentioned above and described in my email I sent you.

In reply to Martin Dougiamas

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
I have just updated jsMath to version 2.3c, which works around a bug in MSIE that can cause it to incorrectly display mathematics that appears within tables when the widths of the columns are determined by the widths of the mathematics (e.g., when the math is the widest thing in the column).

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Stéphane Goussault -
Hello,

I work with jsMath version 2.3c and moodle 1.5.2
I've configured the filter to process with simple dollar. It works with IE6, firefox mozilla and opera

When I configure the filter to process with double dollars. It works with mozilla firefox, opera but not with IE6.
In IE6, the filter seems to process the mathematics but finally nothing is displayed. I tried several options in the jsMath control panel but without results.
The javascript console indicate an error
ligne : 184
Car : 96
Erreur : '/' attendu
Code: 0
URL : http://s139702870.onlinehome.fr/moodle/mod/resource/view.php?id=1726


With firefox mozilla (double dollars configuration), I always have a javascript error
Erreur : unmatched ) in regular expression
Fichier Source : http://s139702870.onlinehome.fr/moodle/mod/resource/view.php?id=1726
Ligne : 222, Colonne : 31
Code Source :
 jsMath.tex2math.pattern.tex = /((^|[^\])(\[^\[\(])*)(\\((([^\]|\[^\)])*)\\)|\\[(([^\]|\[^\]])*)\\]|(\$\$)(([^$\]|\.)*)\9)/;

Thanks for your help.

Stephane
In reply to Stéphane Goussault

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
You need to get the latest copy of the filter.php file from the moodle CVS repository. (See http://cvs.sourceforge.net/viewcvs.py/moodle/contrib/jsmath/). The one linked to the message above is no longer current.

Let me know if that doesn't take care of it for you.

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Stéphane Goussault -
I've the latest copy of the filter.php file.
I don't have anymore javascript error.

In IE6, I noticed that when in the code of the page, mathematical formulas are between paragraph tags <p> , they are not displayed.

Stephane


In reply to Stéphane Goussault

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
I am not able to reproduce this. Do you have a public forum with gues access where I can see this in action? If not, can you post an example that exhibits the problem? Thanks.

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Stéphane Goussault -
Hello David

You can see the problem on  my test site

http://s139702870.onlinehome.fr/moodle/

go to the course category "Mathématiques" and the course "Test Jsmath"
You can use the forum.

Connect as a guest

Thanks

Stephane

In reply to Stéphane Goussault

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
Thanks Stephane, that helped. I was able to locate the problem, and have updated jsMath to 2.3d. The new version should take care of your missing mathematics (I hope). This is also the problem that Sjaak is reporting above.

You can get the new copy of jsMath either from the jsMath site, or the Moodle CVS repository.

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Stéphane Goussault -
Thanks very much Davide,

Now, it works very well for me in Mozilla firefox, IE6 and opera

Just a detail in IE6
When I create a web page with a mathematical formula, the width of the formula goes beyond the space box create by moodle.

Stephane


Attachment formule.jpg
In reply to Stéphane Goussault

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -

I don't get the same results that you do.  Here is a screen snapshot from your site as I see it from here (using IE6.0.29)

Attachment formula.jpg
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Stéphane Goussault -
Hello Davide,

The problem is not in the forum but when I create a web page in moodle (function Add a ressource =>Compose a web page).
In my course click on the link "essai" and you can see the problem with IE6.029
http://s139702870.onlinehome.fr/moodle/
category : Mathématiques
Course : Test JsMath

Thanks

Stephane

In reply to Stéphane Goussault

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
OK, I see what you mean. I have identified the issue and am working on a solution.

Davide
In reply to Stéphane Goussault

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
OK, I think I've fixed this problem. I had to work around a bug in MSIE that caused it to incorrectly measure the widths of formulas inside tables. (It turns out that the hidden box being used to measure the widths was allowing the formula to wrap when it appeared within an element whose default size was too small for the mathematics, so its width was being read as too short.)

I also worked around a bug in Opera that prevents it from measuring the mathematics within some tables, and fixed a bug in jsMath that was causing Opera to misalign mathematics within tables.

Finally, I added a new option for the jsMath filter that allows you to make double-dollars operate as single-dollars (i.e., they produce in-line math rather than display math), which I understand was the behavior for the mimetex-based filter.

You should get both the new version of filter.php and version 2.3e of jsMath from the Moodle CVS repository.

Hope this takes care of your problem.

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Stéphane Goussault -
Ok, Davide, it works perfectly now.
Thank very much

I will advice you if I find another problem
Jsmath is a fantastic script

Stéphane
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Sjaak Kamerling -

Thanks Davide. I get now the math-text onscreen.

Still one question about this: the math-text is always placed in the middle of a new line. For example, when I type:

given $$f(x)=x^2$$ and $$f(x)=3x-1$$, I get four lines:

one line with 'given' (at the left)

one line with the right formula: the word displaystyle etc can be read at the left, but the formula is placed in the middle

one line with the next formula: the word displaystyle etc can be read at the left, but the formula is placed in the middle

one line with 'and'

Can the placing be manipulated?

At this time I am happy that math is possible for me!

Sjaak

In reply to Sjaak Kamerling

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -

Can you tell me what you ahve used to indicate mathematics in the example above (the mimetexc filter has removed it, so I can't tell what you used).  Is it dollars, double-dollars, 'tex' tag, or what?

Davide

In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Sjaak Kamerling -

I placed the mathtext between doubledollarsigns.

Sjaak

In reply to Sjaak Kamerling

Re: JsMath/JsTex instead of mimetex

by Sjaak Kamerling -

an addendum to my earlier mail describing the misplacement of the math-text:

the word displaystyle etc can be read for a very short time at the left, but then the correct formula itself is placed in the middle.

Sjaak

In reply to Sjaak Kamerling

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
Yes, that is going to happen. The way the jsMath filter works is that it really doesn't modify the text of the message but rather lets jsMath's tex2math plugin handle the conversion of double-dollars and so on to the HTML that jsMath needs in order to recognize the mathematics. Because the tex2math plugin (and jsMath itself) run in the page's onLoad handler, the page is displayed before they run, so the TeX code will show up briefly before tex2math and jsMath process it.

It would be possible to do the work of tex2math in the jsMath filter itself, so that the math will already be placed in the SPAN and DIV tags that jsMath needs, but the processing that tex2math does is fairly sophisticated, and the patterns are sufficiently complicated that I didn't want to try to convert it to php (I've never programmed in php before this filter, and didn't want to take time to figure out how to do in php what I already have working in JavaScript). And even if you did this, it would not really help, since jsMath still has to go over the page to convert the TeX to typeset math.

Since jsMath is rather slow about processing the mathematics, it does so asynchronously, meaning that it lets the page be displayed and then goves over the page to insert the mathematics. That way, you can start reading the page before the math is all processed. On pages that have only a little bit of math, that would not be necessary, but on ones with a lot of math, it is a big help. Without it, there could be a substantial delay before the page was made visible.

JsMath does have a method of converting the mathematics before the page is displayed, but it can't be used from within the onLoad hander, since some browsers (like MSIE) display the bage before running the onLoad hander. The call to jsMath would have to be made within the body of the page, and that would require a change to the moodle page-building code to put a single call to jsMath at the bottom of the page. (The filter runs on a per-message basis, not a per-page basis, so when the filter runs, it doesn't know if it is the last piece of math on the page, so can't tell if the jsMath call should be inserted or not.) It would be possible to call jsMath for each message as the page is being built, but that would slow things down ever further.

A compromise could be to do the tex2math conversion in the filter and set the style to 'display: none' so that the tex code would not appear until jsMath processed it. The drawback here is that if someone views the page with a browser that doesn't handle javascript, they will never see any math. With the current set up, they at least get to see the TeX code, which often is readable enough to get the idea across.

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Sjaak Kamerling -

That's an impressive and for me an interesting explanation. BTW: for me it's not a problem that displaystyle etc will show up first; I only thought that my problem about the centering of the text maybe had to do with this behaviour. But as you told me in your next mail, it has to do with use of \(...\); and that is working.

Thanks, Sjaak

In reply to Sjaak Kamerling

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
That's what I thought, and that would account for it. The jsMath filter uses double-dollars to introduce display math mode (just as TeX does). It uses the LaTeX \(...\) or single dollars (when activated) to enclose in-line math, (and \[...\] for display math as well).

Apparently the mimeTeX filter used double-dollars for in-line math (a misfeature in my opinion). I'll see if I can add a flag to the jsMath filter that allows it to treat double-dollars as single ones.

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Sjaak Kamerling -

Inline math in MSIE is possible with \(..\).

As often, every solution gives new problems. On different computers the inline-placing is not always correct. In MSIE it sometimes goes wrong with , for example,

Given $$f(x)=x^2$$ and $$g(x)=\frac{x}{x-1}$$.

The first math-text is placed correct, but math-text with fractions, like the second, is on some computers placed too low; g(x) is placed at the level of about a subscript and x is placed at about the height of the 'normal' sentence.

Until now, in Opera it seems no problem.

Sjaak

In reply to Sjaak Kamerling

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
This doesn't surprise me. The box model used in MSIE is so badly broken that new situations keep popping up where it produces problems for jsMath. These can be affected by the surrounding markup and the CSS styles that are in play, so it can be difficult to isolate the problem. It often has nothing to do with the actual mathematics being typeset, but rather the context in which it is displayed.

That being said, I am not able to reproduce the behavior you describe. Can you set up a page in a public forum where I can see the problem? I'll see what I can do. Thanks.

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Sjaak Kamerling -

Here's an example of what can be seen on some computers.

tex

But on other computers it's no problem. That makes it difficult to detect the problem.

Sjaak

In reply to Sjaak Kamerling

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
It is a help to see the image, but what I really need is to be able to see the CSS and the surrounding HTML so that I can try changing them one by one until I locate the culprit that it causing the problem. I need to be able to get my hands on the actual HTML file for that. Is there any way you can give me access to a forum where this can be seen?

In the meantime, do I understand you to say that IE on some machines works OK and on others it doesn't? If so, can you determine what might be a common factor? (Different versions of Windows, or of IE itself; different monitor settings or resolutions?)

One thing to try is change the font size for the page (in the view menu) and reload the page, or change the scaling factor in the jsMath control panel. Do you get different results with different settings?

Finally, if you change the size of the window (make it smaller so the lines wrap differently) does that make a difference? For example, if you can get the two pieces of mathematics to be on different lines, does that change anything?

It does look like this might be a difficult one to figure out.

Davide
In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Sjaak Kamerling -

I made a forum within a course within my moodle-environment. I'll sent you the address and the enrolment key by mail.

Sjaak

In reply to Sjaak Kamerling

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
OK, I am able to reproduce the problem. It appears to occur only when the TeX fonts are used. I'll see what I can do about it and get back to you.

Davide
In reply to Sjaak Kamerling

Re: JsMath/JsTex instead of mimetex

by Davide Cervone -
I located the problem and I think I have fixed it. The latest version of jsMath (2.4a) should clear that up for you. It also fixes a few minor problems with dragging the TeX source window that I added in v2.4.

I also updated the filter to allow a bit more control over what gets processed by jsMath. You can now mark sections so that they will NOT be processed for mathematics (so they can include the math delimiters without them being turned into mathematics). You do this by using a <DIV CLASS="tex2math_ignore"> around the text that you don't want to be processed. (You can also nest within it additional tags that are CLASS="tex2math_process" to turn processing on again.)

It is also possible to turn off tex2math entirely for the complete page by including a tag with ID="tex2math_off" anywhere on the page. The idea is that when you start a forum or a discussion, you can include <SPAN ID="tex2math_off"></SPAN> in your message and that will disable tex2math completely.

Note that it is possible for anyone to enter such a tag in their message (perhaps meliciously) and it will turn off math on the entire page. Of course, you will be able to tell who did it, since it will be within a specific message, and most students will not know you can do this.

If you don't want to risk that, you can set the allowDisableTag to zero at the top of the filter.php. That will prevent the ID="tex2math_off" from being processed.

Hope this helps. Davide

In reply to Davide Cervone

Re: JsMath/JsTex instead of mimetex

by Sjaak Kamerling -
Great, Davide. I think you fixed it. I tried several formula's and they show up correct.
Thanks
Sjaak
In reply to Martin Dougiamas

New version of the jsMath filter released

by Davide Cervone -
Folks:

I have just updated the jsMath filter stored at the Moodle CVS repository. This brings jsMath up to version 2.4. This version includes a new feature where you can double-click on an equation to get a display of the TeX code used to create the equation. (You can drag the resulting window around by the drag bar at the top, and can close it using the small box at the upper left, or by ALT-clicking anywhere in the window.)

Another new feature is that the filter will not process mathematics that is within a PRE block, so for code listings, for example, you can use these to prevent the dollar signs and so on from being processed within the code listing.

One more addition is the ability to set the strings to be used for indicating in-line and display mode mathematics. You can edit the data at the top of the filter.php file to set your own strings for these if you don't like the TeX/LaTeX ones. Read the comments in the filter.php file, and follow the instructions there.

Finally, there is a new checkbox on the jsMath control panel that allows you to turn off the tex2math processing entirely, so if there is a page where the mathematics is being incorrectly processed, you can turn off the tex2math conversion and see the unmodified page. This last feature is the result of a request from an administrator who was having students enter code fragments that included \(...\) and \[...\] and so on, and these were being turned into mathematics by jsMath.

If you have pages where the discussion will NOT include mathematics, it would be possible to make jsMath ignore these pages entirely. One idea I have for this would be to allow you to mark a page by entering a special hidden tag that jsMath could look for to see if it needs to skip the page. If this sort of feature would be useful to you, please let me know.

Hope this helps some of you out.

Davide
In reply to Davide Cervone

Re: New version of the jsMath filter released

by venkatesan iyengar -
Thanks for the update. I stopped using jsmath for sometime due to it poor rendering in IE6. However, lately, i found it is much better in my localhost (windows machine) and I decided to implement in my production server (linux, webhost). But, when I updated all the files including the 7MB font folder etc, I could not get the jsMath filter working. I do not even see the jsmath control button at the lower right corner. What could be the problem? I chmoded all the files to 755 also.

thanks for your continued to support to moodle family
In reply to venkatesan iyengar

Re: New version of the jsMath filter released

by Davide Cervone -
I stopped using jsmath for sometime due to it poor rendering in IE6.

One of the main problems with jsMath in IE was when the text that contains the mathematics is scaled, as it is with most Moodle pages. The rendering was poor in that situation, but that is now fixed. The baseline alignement problems, while not quite so serious, were also annoying, but I think those are taken care of as well. So I think you will have better luck with it now.

when I updated all the files including the 7MB font folder etc, I could not get the jsMath filter working. I do not even see the jsmath control button at the lower right corner.

That probably means that jsMath.js has not been loaded by your browser. The reason is most likely a naming problem with the directories on the server. The jsMath directory in moodle/filter should be called "jsmath" not "jsMath" as it was originally called in my earlier messages. (This is because of how the directory is named in the Moodle/contrib directory of the CVS repository.) If it is not named correctly, the filter will not be able to locate the jsMath.js file correctly.

Also, the directory that contains jsMath.js should still be named jsMath. So you should have:

    moodle/filter/jsmath
    moodle/filter/jsmath/filter.php
    moodle/filter/jsmath/jsMath
and the moodle/filter/jsmath/jsMath directory should contain all the jsMath javascript files, plus the Plugins directory and the fonts directory. If your filter/jsmath directory was named filter/jsMath, you will need to change it (but first turn off that filter in the Moodle administration menu, and after you change the name, activate the filter again).

If that doesn't take care of the problem, let me know.

Davide

In reply to Davide Cervone

Re: New version of the jsMath filter released

by venkatesan iyengar -
Thanks David. Now it is working fine and I think IE problems are nearly solved mixed. However, I found few things:
1. the native Tex font radio button option is disabled. Why it is so? I already downloaded the Tex fonts and put them in \filter\jsmath\jsMath\fonts\.
2. Using image fonts to render math equations destroys the colour highlighting etc and it is quite slow also. I understand that creating coloured font images for all symbols and all sizes is nearly impossible. My suggestion is to improve the native unicode font resolution and keep as default. this will also avoid uploading 7MB of image fonts to the webserver and updating it quite frequently.
3. I could not render LaTex syntax like \align etc. I think these syntax have not been implemented.
4. Quite often my collegues use Mathtype and export either with AMS-TEX translation or LaTex syntax translation. However, I found that, one has to manually edit the exported math equation to clear any line breaks and bring it one continuous line. Is it not possible to simply ignore white spaces and render the images?.

This syntax does not render at all:
\left( {\begin{array}{*{20}c}
{a_{11} } & {a_{12} } & {a_{13} } \\
{a_{21} } & {a_{22} } & {a_{23} } \\
{a_{31} } & {a_{32} } & {a_{33} } \\

\end{array} } \right)

This syntax renders the matrix as a single row matrix: (the line breaks are manually removed here)
\[\left( {\begin{array}{*{20}c} {a_{11} } & {a_{12} } & {a_{13} } \\ {a_{21} } & {a_{22} } & {a_{23} } \\ {a_{31} } & {a_{32} } & {a_{33} } \\ \end{array} } \right)\]

This syntax renders the correct matrixsad\cr is used instead of\\|)
\[\left( {\begin{array}{*{20}c} {a_{11} } & {a_{12} } & {a_{13} } \cr {a_{21} } & {a_{22} } & {a_{23} } \cr {a_{31} } & {a_{32} } & {a_{33} } \cr \end{array} } \right)\]

Is it possible to rectify these minor problems?

Thanks for your continued interest in moodle family
In reply to venkatesan iyengar

Re: New version of the jsMath filter released

by Davide Cervone -
  • the native Tex font radio button option is disabled. Why it is so? I already downloaded the Tex fonts and put them in \filter\jsmath\jsMath\fonts\.

That is not where they go. Those TeX fonts need to go on the user's machine (i.e., on the machine that is running the browser), not on the server.

  • Using image fonts to render math equations destroys the colour highlighting etc and it is quite slow also. I understand that creating coloured font images for all symbols and all sizes is nearly impossible.

Yes, you are correct that in image mode the mathematics can't be colored. This is a known (and documented) limitation, and I can see no way around it. It's one of the reasons that images-for-symbols-only is the default rather than full image fonts. At least then the variables and numbers will be colored.

  • My suggestion is to improve the native unicode font resolution and keep as default. this will also avoid uploading 7MB of image fonts to the webserver and updating it quite frequently.

You should not need to update 7MB of image fonts frequently. I do not anticipate that these fonts will change at all in the future. I understand your desire to have the unicode fallback work better, but it is what we call in programming a "fragile" mechanism, meaning that it is not very reliable. It depends in a fundamental way on the fonts installed on the user's system, and I have no control over that, and they vary widely from system to system. I can not rely on the needed characters being available, and when they are, I can't rely on them being taken from the font I expect, and so can't be sure of the size of the characters or whether they fit in well with the rest of the font, etc. And while most of the characters can be found from fonts on the Mac and the PC, this is far less effective on most Unix installations.

Because I use a Mac myself, I have tuned the fallback pretty well to work with a default font installation on OS X, but I have a lot less experience with the PC, and the results there are not so satifactory (I don't really even know what a default font installation is). I've also noticed that what worked well a year ago when I developed jsMath no longer works as well on the PC (some characters are now mispositioned). I assume this is due either to font changes or system updates on the machine where I test jsMath (which I don't control myself). I plan to go through the fallbacks again to update them, but this is one indication of why the unicode approach is less reliable than the image mode.

Under most circumstances, the image mode does a much better job than the unicode fallback. The three exceptions are colored text, changing the font size, and printing. The first I can't really do anything about; the second, you need to reload the page after changing the text size (or select the "scalable" checkbox on the options panel); and for the third, there is the "his-res fonts for printing" button on the control panel.

If you really want to make unicode the default fallback, you can do that (it will take a small edit to the filter.php file). If that's what you want, let me know and I'll tell you how to do it. As I said, I'll go back over the fallback fonts when I get a chance, but I don't expect a substantial improvement.

  • I could not render LaTex syntax like \align etc. I think these syntax have not been implemented.

You are right, there are lots of LaTeX environments that are not implemented. Nore are all the commands for labels and references, or for line numbers. There is far too much to LaTeX to make it practical to implement it all, and jsMath is already huge as it is. Every new feature adds to its download time, so there is s trade-off to adding more to it. I have plans to give jsMath a more modular structure, and the ability to load extra code on demand (i.e., only when the mathematics being typset actually requires it), but that is still in the future, and will have the drawback of causing a delay in the rendering as the new code is loaded).

I'm not all that conversant in LaTeX (I learned TeX when LaTeX was still in its infancy, and so never really took to it, so I don't know all the environments or other commands that might be desired. If there are important ones missing, make a list, and I'll see what I can do, as time permits.

  • I found that, one has to manually edit the exported math equation to clear any line breaks and bring it one continuous line. Is it not possible to simply ignore white spaces and render the images?.

JsMath does handle white-space and line breaks properly, but I expect that the Moodle text editor has added <br/> tags at the end of those lines, and that will prevent the tex2math converter from recognizing it as mathematics (the mathematics can not contain HTML tags). There is not much I can do about the fact that the editor introduces those tags. The way that tex2math locates the mathematics on the page would make it difficult to ignore these tags (though I'll think about whether that might be possible). So the only place where that could be handled is in the jsMath filter. It would be a major change to the way it works, and and would require duplicating a lot of the logic from tex2math in the filter itself, so I'm a little hesitant to do that. I'll think about whether there isn't a better solution.

The issue of the backslashes is also probably due to the editor. JsMath should handle \\ fine, but I suspect they are being converted to single slashes by the interface somewhere (I have seen discussions about this problem elsewhere). I don't think that is something I will be able to change.

Not using the fancy HTML editor interface would be one solution to both these problems, but I doubt you would want to do that.

  • Thanks for your continued interest in moodle family

You're welcome. I'm always pleased when people want to use jsMath, and do what I can to make it work for them.

Davide

In reply to Davide Cervone

Re: New version of the jsMath filter released

by venkatesan iyengar -
Thanks for your detailed reply. I found the popup window (when we click on the equation) is better than that of the moodle tex filter. Is it possible to incoporate editing facility within the popup window and update the equation on the moodle page?. Since I am not well versed with php, I do not know how difficult or easy to do this? This could make minor corrections easier without loading the whole page again.

venkatesan
In reply to venkatesan iyengar

Re: New version of the jsMath filter released

by Davide Cervone -
I've been rewriting the tex2math plugin to jsMath, on which the jsMath filter relies, and should be able to get around the line-break problem. Still have to test it on MSIE, and there will undoubtedly be problem that I need to work out (there always are).

  • Is it possible to incoporate editing facility within the popup window and update the equation on the moodle page?

Not very likely. It would be possible to edit the TeX in the browser window, but there is no easy way to have that be saved again on the server. It would be possible to "fake" a submission of a form like the one you get when you edit a message, but the problem with that is jsMath would need access to the unfiltered original message, which it doesn't have. (It only has a modified vesion of the message; one that has passed through all the Moodle filters that are active.)

  • This could make minor corrections easier without loading the whole page again.

Making permanent changes would require reloading the page at least once. Anything else would require substantial rewrites to Moodle itself.

There was a group that was working on integrating jsMath with the HTML editor at one point so that the math could be more easily previewed. I'm not sure what the status of that project is.

Davide

In reply to Davide Cervone

Re: New version of the jsMath filter released

by Eric Fisch -

Hi David,

Is there a library of syntax used when wrtiting text to generate images with jsMath?

Thanks,

Eric

In reply to Eric Fisch

Re: New version of the jsMath filter released

by Davide Cervone -
Sorry, Eric, I'm a bit confused by the question. For one thing, jsMath doesn't produce images. It uses your computer's native fonts (when it can or predefined images of the characters in the fonts) to lay out the mathematics it displays.

If you are asking "How do you enter mathematics so that jsMath can typeset it?" then the answer is that you use the typsetting language called TeX. This has been around since the late 1970's, and there are many introductions to TeX on line.

A glossary for the mimeTeX filter that is part of Moodle is available at
http://moodle.hughesmark.com/mod/glossary/view.php?id=268, and jsMath handles most of what it listed there, so that is one place you can start.

You can also find a list of most of the TeX symbol names at the jsMath home page.

Hope that helps.

Davide
In reply to Davide Cervone

Re: New version of the jsMath filter released

by Eric Fisch -

David,

Thank you very much for your reply. That was exactly the information I was looking for. I apologize for such an amatour question. I am very new to Moodle and the concept of online education, and I am still trying to get my hands around all the features.

Eric

In reply to Martin Dougiamas

Version 2.4b released

by Davide Cervone -
I have spent the last day and a half rewriting the tex2math plugin so that it can process mathematics that has <br> tags within it. This fixes the problem that Venkatesan Iyengar reported with cutting and pasting multi-line equations into the Moodle message editor. There are also a couple of new flags at the top of the filter.php file that let you have slightly finer control over what math delimiters to look for (you can now control each of them individually, and you can include both the standard TeX delimiters AND your own if you want).

I think this should work well for you, but since it is brand new code, there may still be some bugs lurking in there. If you see anything that doesn't seem right, let me know. You need to get both the filter.php file and the jsMath.zip file from the CVS archive. (You don't need to download the fonts again; they aren't changing).

I also checked on the \\ issue, and it looks like you can use these in the Moodle editor without trouble. I cut and pasted the example array that Venkatesan included in his message above, and it worked fine. Note, however, that if you DON'T use the WYSIWIG editor, but instead use the standard browser type-in area, when you edit a post, double backslashes are converted to single backslashes in the text that appears in the type-in box initially, so that might have been the source of the problem.

Finally, I think it may be time to start a new discussion. This one has gotten pretty long, and it takes quite a while for Moodle to render it now.

Davide
In reply to Davide Cervone

Re: Version 2.4b released

by venkatesan iyengar -
This is great David. You are putting lot of effort. I think I'm troubling you once again. I have few difficulties still:

1. The syntax is not rendering eventhough the filter.php is correctly set. I would like to use this instead of \( \) syntax due to its compatability with the moodle tex filter.

2. Since I'm a chemist many times myself and my collegues lot of chemical reactions and we write many things above and below the right and left arrows. I think the following LaTex synatax can be included also.

\xrightarrow[y]{x}
\xleftarrow[y]{x}
\underset{y}{\overset{x}{\longleftrightarrow}}
\underset{y}{\overset{x}{\longleftrightarrow}}
similarly for left and right harpoon

These will be quite useful for us in writing all our chemical equations.

I think you can start a fresh thread with updated version.
In reply to venkatesan iyengar

Re: Version 2.4b released

by Davide Cervone -
  • The <tex> syntax is not rendering eventhough the filter.php is correctly set. I would like to use this instead of \( \) syntax due to its compatability with the moodle tex filter.

Can you send me the configuration section of your filter.php file? It is hard to determine the problem without knowing the settings you have in place. I suspect that you have turned off processing of the other math delimiters, but unfortunately, that won't work. The way the filter works is that it changes the <tex> tags into whatever the filter is using for in-line math delimiters. If you have turned them all off, there is nothing for it to use. (It will default to single dollars, but these will not be processed by jsMath, since you have turned them off.) JsMath can't look for the <tex> tags itself, because they are not "real" HTML tags, and most browsers will discard them before jsMath gets to see the page, so they won't be there for jsMath to find.

While writing this, I realized that it would probably be better just to convert these to the <SPAN CLASS="math"> tags that jsMath looks for, rather than making tex2math handle them. I'll have to make that change in the next version. In the meantime, if you don't want to process the dollars or \(...\) notation, you need to enable cutsom delimiters (so the filter has SOMETHING to use for marking mathematics). You can make them as complicated as you want, since no one is going to be typing them directly, and they should be something that won't appear naturally. For example [%%MaTh%%]...[/%%MaTh%%] and [%%DiSpLaY%%]..[/%%DiSpLaY%%].

As for the arrows, I will see about making them available; it should not be hard. For the moment, you can get \overset{x}{y} as \buildrel{x}\over{y}, but the others are not easily handled at the moment.

Davide

In reply to venkatesan iyengar

Arrow macros

by Davide Cervone -
OK, I've worked out the arrows for you. I haven't added them into jsMath yet, but the attached file will add them in for you. Put this file (moreArrows.js) into your moodle/filter/jsmath folder (where the filter.php file is). Then edit the filter.php file and near the bottom, change
        . '<script language="JavaScript" type="text/javascript">'."\n"
        . '  jsMath.Setup.Script("plugins/tex2math.js");'."\n"
to
        . '<script language="JavaScript" type="text/javascript">'."\n"
        . '  jsMath.Setup.Script("../moreArrows.js");'."\n"
        . '  jsMath.Setup.Script("plugins/tex2math.js");'."\n"
(i.e., insert the middle line). The "X" in front of "language" isn't supposed to be there, but something in the Moodle censoring mechanism is working hard to make sure I'm not submitting JavaScript code to this forum. Be sure you don't insert the X when you edit the filter.php file.

That should make \xrightarrow, \overset, etc. work for you. I wasn't quite sure what the harpoon commands were supposed to be, so I did \xuprightharpoon, \xupleftharpoon, \xdownrightharpoon and \xdownleftharpoon. Not sure if that's what you had in mind or not. Let me know if these should be changed.

Davide

In reply to Davide Cervone

Re: Version 2.4b released--MATH FILTER --HELP

by Bhupinder Singh -

Hi Davide,

I am going through the forum and I am a littlr confused as to which is the final filter / function for math functions.

I shall be grateful if you could point me in the right direction for download and installation.

I apologise for this botheration.

Regards

Garry