... tags to gif images using // mimetex.cgi obtained from http://www.forkosh.com/mimetex.html authored by // John Forkosh john@forkosh.com. Several binaries of this areincluded with // this distribution. // Note that there may be patent restrictions on the production of gif images // in Canada and some parts of Western Europe and Japan until July 2004. //------------------------------------------------------------------------- ///////////////////////////////////////////////////////////////////////////// // To activate this filter, add a line like this to your // // list of filters in your Filter configuration: // // // // filter/tex/filter.php // ///////////////////////////////////////////////////////////////////////////// $CFG->texfilterdir = "filter/tex"; function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $align="middle") { // Given the path to a picture file in a course, or a URL, // this function includes the picture in the page. global $CFG; $output = ""; $origtex = $tex; $style = 'style="border:0px; vertical-align:'.$align.';'; if ($tex) { $tex = str_replace('&','&',$tex); $tex = str_replace('<','<',$tex); $tex = str_replace('>','>',$tex); $tex = str_replace('"','"',$tex); $tex = str_replace("\'",''',$tex); $title = "title=\"$tex\""; } if ($height) { $style .= " height:{$height}px;"; } if ($width) { $style .= " width:{$width}px;"; } $style .= '"'; if ($imagefile) { if (!file_exists("$CFG->dataroot/$CFG->texfilterdir/$imagefile") && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) { $output .= "wwwroot/$CFG->texfilterdir/texdebug.php\">"; } else { $output .= "wwwroot/$CFG->texfilterdir/displaytex.php?"; $output .= urlencode($tex) . "\" onclick=\"return openpopup('/$CFG->texfilterdir/displaytex.php?"; $output .= urlencode($tex) . "', 'popup', 'menubar=0,location=0,scrollbars,"; $output .= "resizable,width=300,height=240', 0);\">"; } $output .= "\"".s($origtex)."\"slasharguments) { // Use this method if possible for better caching $output .= "$CFG->wwwroot/$CFG->texfilterdir/pix.php/$imagefile"; } else { $output .= "$CFG->wwwroot/$CFG->texfilterdir/pix.php?file=$imagefile"; } $output .= "\" $style />"; $output .= ""; } else { $output .= "Error: must pass URL or course"; } return $output; } function tex_filter ($courseid, $text) { global $CFG; /// Do a quick check using stripos to avoid unnecessary work if (!preg_match('/discussion); # } else if (strstr($scriptname,'discuss.php')) { # $discussion = get_record("forum_discussions","id",$_GET['d'] ); # } else { # return $text; # } # if ($discussion->forum != 130) { # return $text; # } $text .= ' '; preg_match_all('/\$(\$\$+?)([^\$])/s',$text,$matches); for ($i=0;$i TeX expression // or $$ TeX expression $$ // or \[ TeX expression \] // original tag of MathType and TeXaide (dlnsk) // or [tex] TeX expression [/tex] // somtime it's more comfortable than (dlnsk) preg_match_all('/(.+?)<\/tex>|\$\$(.+?)\$\$|\\\\\[(.+?)\\\\\]|\\[tex\\](.+?)\\[\/tex\\]/is', $text, $matches); for ($i=0; $i','',$texexp); $texexp = str_replace('','',$texexp); $texexp = str_replace('','',$texexp); $texexp = str_replace('','',$texexp); $texexp = eregi_replace("", '', $texexp); //dlnsk $align = "middle"; if (preg_match('/^align=bottom /',$texexp)) { $align = "text-bottom"; $texexp = preg_replace('/^align=bottom /','',$texexp); } else if (preg_match('/^align=top /',$texexp)) { $align = "text-top"; $texexp = preg_replace('/^align=top /','',$texexp); } $md5 = md5($texexp); if (! $texcache = get_record("cache_filters","filter","tex", "md5key", $md5)) { $texcache->filter = 'tex'; $texcache->version = 1; $texcache->md5key = $md5; $texcache->rawtext = addslashes($texexp); $texcache->timemodified = time(); insert_record("cache_filters",$texcache, false); } $filename = $md5 . ".gif"; $text = str_replace( $matches[0][$i], string_file_picture_tex($filename, $texexp, '', '', $align), $text); } return $text; } ?>