<?PHP
/////////////////////////////////////////////////////////////////////////////
//                                                                         //
// NOTICE OF COPYRIGHT                                                     //
//                                                                         //
// Moodle - Filter for converting TeX notation to typeset mathematics      //
// using jsMath                                                            //
//                                                                         //
// Copyright (C) 2005 by Davide P. Cervone                                 //
// This program is free software; you can redistribute it and/or modify    //
// it under the terms of the GNU General Public License as published by    //
// the Free Software Foundation; either version 2 of the License, or       //
// (at your option) any later version.                                     //
//                                                                         //
// This program is distributed in the hope that it will be useful,         //
// but WITHOUT ANY WARRANTY; without even the implied warranty of          //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           //
// GNU General Public License for more details:                            //
//                                                                         //
//          http://www.gnu.org/copyleft/gpl.html                           //
//                                                                         //
/////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------
// NOTE: This Moodle text filter uses jsMath to process TeX commands
// embedded in the text.  In-line math should be surrounded by \(...\)
// and display math should be enclosed in \[...\].  You can optionally
// have it look for $...$, $$...$$, and <tex>...</tex> tags as well.
// By default, the filter will look for $$...$$ and <tex>...</tex>
// but not $...$, since these could too easily clash with people
// actually wanting dollar signs in tehir text.  (Note that the user
// can enter \$ to get a dollar sign that does not indicate math mode.)
//
// The filter loads jsMath's tex2math plugin to do most of the work.  We
// have to do the conversion of <tex>...</tex> here, since they would
// confuse the browser otherwise.  We call on jsMath's autload plugin to
// decide if jsMath needs to be loaded.  The javascript.php files does most
// of the work.
//
// You can request that the filter use jsMath's mimeTeX plugin if you
// want to make jsMath more compatible with Moodle's traditional
// mimetex-based TeX processing.
//
// You need to get a copy of jsMath (v3.0 or later) from 
//
//    http://www.math.union.edu/locate/jsMath
//
// and put the jsMath directory in this filter directory.  Be sure to
// download and unpack the fonts folder into the jsMath directory
// as well.
//-------------------------------------------------------------------------

//
//  Configure the filter here, and also in the javascript.php file.
//
$CFG->jsMath = (object)array(
  'version' => 1.9,                      // version of this file
  'processTEXtags' => 1,                 // set to 0 to prevent converting <tex> tags
  'startMath' => '<span class="math">',  // <tex> gets converted to this
  'endMath'   => '</span>'               // </tex> gets converted to this
);

//------------------------------------------------------------------------

/// These lines are important - the variable must match the name
/// of the actual function below

$textfilter_function='jsmath_filter';
if (function_exists($textfilter_function)) {return;}

function jsmath_filter ($courseid, $text) {
  global $CFG;

  //
  //  Convert <tex>...</tex> to \(...\)
  //
  if ($CFG->jsMath->processTEXtags) {
    $text = str_replace(array('<tex>','</tex>'),
                        array($CFG->jsMath->startMath,$CFG->jsMath->endMath),
                        $text);
  }
  $text = '<span id="Process_jsMath"></span>' . $text;
  return $text;
}

?>
