TeX filter getting a little over excited

TeX filter getting a little over excited

by Davo Smith -
Number of replies: 3
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Anyone got any idea why the TeX filter would convert the following line of embedded JavaScript (from a HotPotatoes crossword):

Temp = InputStuff.replace(/\[ClueNum\]/g, ClueNum);

into this:

Temp = InputStuff.replace(/<a target="popup" title="TeX" href="http://{college website address}/filter/tex/displaytex.php?ClueNum" onclick="return openpopup('/filter/tex/displaytex.php?ClueNum', 'popup', 'menubar=0,location=0,scrollbars,resizable,width=300,height=240', 0);"><img class="texrender" border="0" title="ClueNum"   alt="" src="http://{college website address}/filter/tex/pix.php/eeed6d5ffae6f1ca0c5eae7fad653c48.gif" style="vertical-align:middle" /></a>/g, ClueNum);

Turning off the TeX filter stops this from happening. I cannot find any $ signs in the entire HTML file, so I'm not sure why the TeX filter is jumping in anyway.

Average of ratings: -
In reply to Davo Smith

Re: TeX filter getting a little over excited

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi David,

Unfortunately the TeX filter is overzealous and will convert a number of Javascript lines in Hot Potatoes HTML files to maths images.

For instance:

Temp = InputStuff.replace(/ \ [ ClueNum\]/g, ClueNum);

---> Temp = InputStuff.replace(/<a href=".../moodle/filter/tex/texdebug.php"><img class="texrender" border="0" title="ClueNum" alt="" src=".../moodle/filter/tex/pix.php/eeed6d5...48.gif" style="vertical-align:middle" /></a>/g, ClueNum);

This unwanted conversion (which results in the HP crossword not working properly) happens in the following conditions:

  1. the TeX filter has been enabled sitewide by Admin
  2. a teacher puts a direct link to an HTML Hot Potatoes file placed in the course files

It does not happen if you use the "normal" Moodle interface to point to your HP HTML file, i.e. Add an Actitivy / Hot Potatoes Quiz.

I have identified the culprit (in Moodle 1.6.3). In file \moodle\filter\tex\filter.php line 125:

preg_match_all('/<tex>(.+?)<\/tex>|\$\$(.+?)\$\$|\\\\ \ [ (.+?)\\\\\]|\\[tex\\](.+?)\\[\/tex\\]/is', $text, $matches);

The part in red in the preg_match_all regular expression is too "greedy" and it matches the various /\[ClueNum\], /\[strParams\], etc. Javascript bits which are to be found in the Crossword HP files.

Questions for TeX filter experts (and mathematicians):

  1. Is the part in red in the preg_match_all really useful in the TeX filter? Or could it be made less greedy and more to the point?
  2. When the TeX filter is enabled sitewide, could there be a way to prevent it from operating on any uploade HTML resource file, e.g. using a <noTex></noTex> tag similar to the <nolink></nolink> used to prevent dynamic glossary linking?

Thanks,

Joseph

EDIT.- After posting my message, just realized that the overzealous TeX filter is at work on this forum too, and changes my bits of Javascript into images!!! So I have introduced a few extra spaces in my quoted Javascript to prevent this...

In reply to Joseph Rézeau

Re: TeX filter getting a little over excited

by Gordon Bateson -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers
For this particular case you could try the following modification:
  1. open "filter/tex/filter.php" with a text editor
  2. locate the following lines (around line 125):
    for ($i=0; $i<count($matches[0]); $i++) {
    $texexp = $matches[1][$i] . $matches[2][$i] . $matches[3][$i] . $matches[4][$i];
  3. change the above lines to the following:
    for ($i=0; $i<count($matches[0]); $i++) {
    $texexp = $matches[1][$i] . $matches[2][$i] . $matches[3][$i] . $matches[4][$i];
    if ($texexp=='ClueNum') continue;
  4. save the modified file
You could also modify the code in "filter/tex/filter.php" for a more general check around line 90. This will skip activation of the filter on Hot Potatoes quizzes completely.
  1. locate the following lines (around line 90):
    if (!preg_match('/<tex/i',$text) and !strstr($text,'$$') and !strstr($text,'\\[') and !preg_match('/\[tex/i',$text)) { //added one more tag (dlnsk)
    return $text;
    }
  2. change the above lines to the following:
    if (!preg_match('/<tex/i',$text) and !strstr($text,'$$') and !strstr($text,'\\[') and !preg_match('/\[tex/i',$text)) {
    return $text;
    }
    if (preg_match('/Created with (Mac )?Hot Potatoes/i', $text)) {
    return $text;
    }

    FYI the 'Created with Hot Potatoes' string appears near the top of all HP5 and HP6 quizzes
I haven't tested the above modifications, so handle with due caution smile

regards
Gordon
In reply to Gordon Bateson

Re: TeX filter getting a little over excited

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Hi Gordon,
Thanks for your prompt reply. However, not being admin on my Moodle site I cannot envisage hacking the core Moodle file. What is really needed is for the TeX filter to come up with a working solution and commit it to CVS so that the correction gets into standard Moodle distributions. I have posted bug report MDL-7849 to this effect.
Thanks again,
Joseph