JsMath tex display and wiki problem

JsMath tex display and wiki problem

by Petr Kalis -
Number of replies: 5
Hi
I just tried JsMath filter, but strange things happened.
First: tex formula is displaying incorrectly, for example $$\sqrt{a^2+b^2}$$ is displaying like this texproblem
Second: This text is inserted into wiki materials at the beginning:
jsMath = {
Controls: {cookie: {scale: 120}},
tex2math: {
doubleDollarsAreInLine: 0,
allowDisableTag: 1
},
Font: {Message: function () {}}
};
window.Xonload= function () {
jsMath.tex2math.Convert(null,{
fixEscapedDollars: 0,
processSingleDollars: 0,
processDoubleDollars: 1,
processSlashParens: 1,
processSlashBrackets: 1,
custom: 0
});
jsMath.Process()} jsMath.Setup.Script("plugins/tex2math.js");
jsMath.Setup.Script("plugins/mimetex.js");

and formulas are not converted to gifs. Its happening in IE and in FF too. Can somebody help me? Thanks
Average of ratings: -
In reply to Petr Kalis

Re: JsMath tex display and wiki problem

by Davide Cervone -
The text that you are seeing is supposed to be within a SCRIPT tag, so that it executes as JavaScript code. The fact that you are seeing it as text suggests that the SCRIPT tag might not be getting through to the browser. I'm wondering if you have some other filter on that is conflicting with it. Make sure you do NOT have the tex, mimetex or other filters active (only the jsmath filter). The fact that you are seeing the nearly rendered mathematics indicates that you are getting some other math rendering (like MathML). I can tell you that the image you showed is NOT from jsMath.

So my guess is that you need to check the filters that you ahve activated. Deactivate any other math filters, and see if that helps. If not, disabled EVERYTHING other than jsmath, and see if THAT works. If you can get jsmath to display properly, put back the other filters one by one until you find out which one is conflicting with it.

If you can't get the jsMath filter to work even with everything else turned off, then view the source of the page that you quoted, and see if there are SCRIPT tags around the code that you listed above. If not, let me know.

Davide

PS, jsMath does NOT convert the math to GIF's, it renders the math using native TeX fonts (when available) or using images of the individual characters that are already stored on yoru server (part of the jsMath-fonts.zip file that you should have installed as part of the jsMath filter).
In reply to Davide Cervone

Re: JsMath tex display and wiki problem

by Petr Kalis -
Thanks for quick reply.
I tried disable others filters and let jsmath be the only one. Still the same.
There isnt script tags around the text i mentioned, so its clear, why arent formulas evaluated, cause script is not running, but why the tags are omitted, dont know(it is only in wiki, i searched others sources and there are script tags present).
Tried another formulas like this $$\left(\begin{array}{rrr}1 & 2 & 3 \1 & 1 & 1 \1 & -3 & 2 \end{array}\right)$$ ( $ $\left(\begin{array}{rrr}1 & 2 & 3 \1 & 1 & 1 \1 & -3 & 2 \end{array}\right)$ $) and in place of the formula is "Unknown control sequence '\1'"
(i tried to turn off cache for filters and repeatedly delete cache in browser, so there arent some residues, i hope)
Thanks for help
EDIT:Why is mentioned formula looking like this, when i copy&paste code and there it is looking like this tex
Im not familiar with tex, so forgive me, if i missed something obvious.



In reply to Petr Kalis

Re: JsMath tex display and wiki problem

by Davide Cervone -
OK, it sounds like the wiki module may be stripping out the SCRIPT tag. I'll have to look into it. Currently I'm out of town, and so won't be able to get to it until I get back home next week. Sorry for the delay.

The reason the array isn't being shown properly is that the double backslashes have been convereted to single backslashes somewhere along the way (if you edit the message, for example, the text that you see in the typein-area can have its double slashes replaced by single ones). (Notice this is the case in the text that you have quoted above). This will mean that TeX will not notice the indication of the line ending, and so wthe whole thing shows up as a single line array.

When the double slashes are replaced by single ones, you get "\1" instead of "\\1", so this looks like a control sequence to jsMath. (That is, commands to jsMath start with a slash, so this is the command named "\1" not the number 1.) JsMath complains about this because there is no such command, but apparently mimeTeX or whatever is processing your mathematics doesn't care about that. (Indeed, it looks like \1 produces a smaller-font-sized number 1).

It looks like when you cut and pasted it in, the double-backslashes were retained, so they produced the correct array. it may be safer to use \cr rather than \\, as others have reported problems with \\ as well. This is not the fault of jsMath, because the double slashes have been changed by Moodle somewhere before jsMath runs.

Davide
In reply to Petr Kalis

Re: JsMath tex display and wiki problem

by Davide Cervone -
OK, I have been able to reproduce your problem. (I had to upgrade my installation of Moodle, which was pretty old, as the earlier version of Wiki what I was using didn't exhibit the problem.

It turns out that the Wiki code is stripping out the SCRIPT tags. I haven't yet come up with a solution to that. Unfortunately, it means that the current approach used by the jsMath filter is not going to work, and will have to be replaced by an alternative method. I have some ideas, but I won't be able to work on it right away.

The main difficulty is that there is no mechanism in Moodle for a filter to add anything at the bottom of the web page, which is what jsMath really needs. One can include JavaScript code in the HEAD of the document, but that is not sufficient (since jsMath needs to BODY to be in place when it is loaded). it would be possible to set the document's onLoad handler, but Moodle set that itself under some circumstances, and in a way that can't be overridden (which is too bad).

The theme's footer.html file is really where the loading of jsMath should go, and one could edit it in by hand, but that would be a hack. It would be nice if there were a mechanism like the filter's javascript.php file that would allow adding code at the bottom of the page. That wouldn't be hard to do, but it just isn't there at the moment, and it's probably not worth it, since the need for it is not very frequent. But what really would be a help is if Moodle didn't set the onLoad handler (or at least provided a mechanism for hooking into the onLoad sequence).

Anyway, I'll see what I can come up with.

Davide
In reply to Petr Kalis

Re: JsMath tex display and wiki problem

by Davide Cervone -
Petr,

I have released a new version of the jsMath filter that should take care of the trouble you are having. See my posting announcing the release for more details. Let me know if this doesn't work for you.

Davide