Revision [9928]

This is an old revision of JSMathIntegration made by DarTar on 2005-07-10 10:36:15.

 

JSMath Integration


 


JSMath is an easy-to-use script that allows one to display complex mathematics in web pages using JavaScript. The way the script is structured should make it simple to integrate into Wikka. Integration into Wikka would allow users to display complex mathematics using LaTeX markup, making Wikka useful for mathematical resources.

JSMath has a homepage here. A more thorough explanation of the way in which JSMath works is here.




Here's a quick hack to integrate JSMath in Wikka

The code

Version 0.1

1. Download and save the package
Get the package, unzip it and upload the files in the following folder in your Wikka directory:

3rdparty/plugins/jsmath/


2. Modify wikka.config.php
Add the JSMath options to the configuration file:

original
  1.     "geshi_path" => "3rdparty/plugins/geshi",
  2.     "geshi_languages_path" => "3rdparty/plugins/geshi/geshi",


modified
  1.     "geshi_path" => "3rdparty/plugins/geshi",
  2.     "geshi_languages_path" => "3rdparty/plugins/geshi/geshi",
  3.     "enable_jsmath" => "1",
  4.     "jsmath_path" => "3rdparty/plugins/jsmath",


3. Modify actions/header.php

Insert the JSMath call in actions/header.php:

original
  1. <body <?php echo $message ? "onLoad=\"alert('".$message."');\" " : "" ?> >
  2. <div class="header">


modified
  1. <body <?php echo $message ? "onLoad=\"alert('".$message."');\" " : "" ?> >
  2. <?php
  3.     if (($this->GetMethod() == 'show') && ($this->GetConfigValue('enable_jsmath') == 1) && file_exists($this->config['jsmath_path'].'/jsMath.js')) {
  4.         echo '<script src="'.$this->config['jsmath_path'].'/jsMath.js"></script>';
  5.     }
  6. ?>
  7. <div class="header">


4. Modify actions/footer.php

Insert the call to the JSMath formatter function at the end of actions/footer.php:

<?php
    if (($this->GetMethod() == 'show') && ($this->GetConfigValue('enable_jsmath') == 1) && file_exists($this->config['jsmath_path'].'/jsMath.js')) {
        echo '<script>jsMath.Process()</script>';
    }
?>


5. Test it

To add math in a Wikka page just use the math class with embedded HTML:

For inline math, use: <span class="math">Here goes LaTeX code</span>
For math blocks, use: <div class="math">Here goes LaTeX code</div>

Try for example:

""If <span class="math"> f(x) = x+2 </span> then <span class="math"> f(4) = 6 </span>. ""

""<div class="math"> \sum_{i=1}^{n} i = {n(n+1)\over 2} </div> ""


if the JSMath engine works correctly the code above should be rendered as:

JSMath sample output
JSMath sample output

(the above examples are pictures taken from a local installation; JSMath outputs math as formatted text)

To do



CategoryDevelopmentArchitecture CategoryDevelopmentFormatters CategoryDevelopment3rdParty
There are 9 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki