ASCIIMathML plugin

asciimathml plugin by Mohammad Rahmani
Plugin for translating ASCII math notation to MathML on wiki pages

Last updated on 2008-08-08. Provides Syntax.
Compatible with DokuWiki version 2008-05-05.

Similar to jsmath, math, math2.

Tagged with formula, math, tex.

Description

ASCIIMathML is a layer of JavaScript functions to convert ASCII math notation to Presentation MathML. The conversion is done while the (X)HTML page loads, and should work with Firefox/Mozilla/Netscape 7+ and Internet Explorer 6+ (Note: IE6+ requires Mathplayer to properly render the math notations).

ASCIIMathML plugin is based on version 1.4.8 Aug 30, 2007, © ASCIIMathML. This plugin does not support the Latest version of ASCIIMathML. For changes see ASCIIMath Changes.txt.

RevisionDateDescription
0.02008-08-09Experimental

Installation

  1. Download the source archive (~14k)from ASCIIMathML - Plugin
  2. Unpack it in your Doku­Wiki plugins directory {dokuwiki}/lib/plugins (make sure, included subdirectories are un­packed correctly); this will create the following directories:
    1. {dokuwiki}/lib/plugins/asciimathml.
    2. {dokuwiki}/lib/plugins/asciimathml/main.

plugin codes

syntax.php

 
<?php
  /**
  /**
    * Plugin AsciiMathML: Use ASCIIMathML for translating ASCII math notation to MathML and graphics.
    *
    * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
    * @author     Mohammad Rahmani <m.rahmani@aut.ac.ir>
    *
    * This plugin uses ASCIIMathML.js version 1.4.8 Aug 30, 2007, (c) Peter Jipsen http://www.chapman.edu/~jipsen
    * Latest version at http://www.chapman.edu/~jipsen/mathml/ASCIIMathML.js
    * For changes see http://www.chapman.edu/~jipsen/mathml/asciimathchanges.txt
    * If you use it on a webpage, please send the URL to jipsen@chapman.edu
    * Note: This plugin ONLY SUPPORTS version 1.4.8 of ASCIIMathML.js
   */
 
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
 
/**
 * All DokuWiki plugins to extend the parser/rendering mechanism
 * need to inherit from this class
 */
class syntax_plugin_asciimathml extends DokuWiki_Syntax_Plugin {
 
    /**
     * Get an associative array with plugin info.
     */
    function getInfo(){
        return array(
            'author' => 'Mohammad Rahmani',
            'email'  => 'm.rahmani@aut.ac.ir',
            'date'   => '2008-08-09',
            'name'   => 'ASCIIMathML Plugin',
            'desc'   => 'Translating ASCII math notation to MathML and graphics',
            'url'    => 'http://www.dokuwiki.org/plugin:tutorial',
                     );
    }
 
    function getType(){ return 'formatting'; }
    function getPType(){ return 'normal'; }
    function getSort(){ return 450; }
 
     /**
     * Connect pattern to lexer
     */
    function connectTo($mode) {
        $this->Lexer->addEntryPattern('<acm>(?=.*?</acm>)',$mode,'plugin_asciimathml');
        $this->Lexer->addEntryPattern('<acmath>(?=.*?</acmath>)',$mode,'plugin_asciimathml');
    }
 
    function postConnect() {
        $this->Lexer->addExitPattern('</acm>','plugin_asciimathml');
        $this->Lexer->addExitPattern('</acmath>','plugin_asciimathml');
    }
 
    /**
     * Handler to prepare matched data for the rendering process.
     */
    function handle($match, $state, $pos, &$handler){
        switch ($state) {
        case DOKU_LEXER_ENTER :
            return array($state, preg_match($match, "/^<acm>/"));
            break;
        case DOKU_LEXER_MATCHED :
            break;
        case DOKU_LEXER_UNMATCHED :
            return array($state, $match);
            break;
        case DOKU_LEXER_EXIT :
            return array($state, preg_match($match, "/^<\/acm>/"));
            break;
        case DOKU_LEXER_SPECIAL :
            break;
        }
        return array($state, '');
    }
 
    /**
     * Handle the actual output creation.
     */
    function render($mode, &$renderer, $data) {
        if($mode == 'xhtml') {
            list($state, $match) = $data;
            switch ($state) {
            case DOKU_LEXER_ENTER :
                if ($match) {
                    $renderer->doc .= '<span class="acmath"> `';
                } else {
                    $renderer->doc .= '<div class="acmath"> `';
                }
                break;
            case DOKU_LEXER_MATCHED :
                break;
            case DOKU_LEXER_UNMATCHED :
                $renderer->doc .= $renderer->_xmlEntities($match);
                break;
            case DOKU_LEXER_EXIT :
                if ($match) {
                    $renderer->doc .= ' `</span>';
                } else {
                    $renderer->doc .= ' `</div>';
                }
                break;
            case DOKU_LEXER_SPECIAL :
                break;
            }
        }
        return false;
    }
}
 
//Setup VIM: ex: et ts=4 enc=utf-8 :
 

script.js

 
/*
 This script installs the ASCIIMathML JavaScript
 to be used through "asciimath" plugin in DokuWiki
  Mohammad Rahmani
  Date: Friday, 25 Jul. 2008  10:14:40
  Rev. 0: Trial
 
    * This plugin uses ASCIIMathML.js version 1.4.8 Aug 30, 2007, (c) Peter Jipsen http://www.chapman.edu/~jipsen
    * Latest version at http://www.chapman.edu/~jipsen/mathml/ASCIIMathML.js
    * For changes see http://www.chapman.edu/~jipsen/mathml/asciimathchanges.txt
    * If you use it on a webpage, please send the URL to jipsen@chapman.edu
    * Note: This plugin ONLY SUPPORTS version 1.4.8 of ASCIIMathML.js 
 
 
*/
// full url to ASCIIMathML installation
 
var ASCIIMathMLURL = '/lib/plugins/asciimathml/main/ASCIIMathML148.js';
 
document.write('<script type="text/javascript" src="' + ASCIIMathMLURL + '"></script>');
 
 
function installASCIIMathML()
{
    ASCIIMathML.Process(document);
}
 
addInitEvent(installASCIIMathML);
 

Usage/Syntax

 <acm> ASCII Math Notation goes here </acm>

and

 <acmath> ASCII Math Notation goes here </acmath>

This is the syntax for the tag that inserts the MathML presentation on the wiki page. For detailed discussion take a look at ASCIIMathML Syntax.

Samples

There are many examples under ASCIIMathML samples. Here are some examples tested under DokuWiki, simply copy paste them into a wiki page with installed ASCIIMathML plugin.


==== Example 1 ====
  * A simple example
<acm>
   f(x)=sum_(n=0)^oo(f^((n))(a))/(n!)(x-a)^n
</acm>

==== Example 2 ====
Matrices and column vectors are simple to type
<acmath>
 [[a ,  b ],[c,  d]]((n),(k))
</acmath>

==== Example 3 ====
Grouping brackets don't have to match
<acmath>
(a,b]={x in RR | a < x <= b}
</acmath>

==== Example 4 ====
piecewise defined function are based on matrix notation
<acmath>
x/x={(1,if x!=0),(text{undefined},if x=0):}
</acmath>

==== Example 5 ====
Complex subscripts are bracketed, displayed under lim
<acmath>
d/dxf(x)=lim_(h->0)(f(x+h)-f(x))/h
</acmath>

==== Example 6 ====
  * A multi-lines formula
<acm> int (x+1)(e^(x//2) - 1) dx = (x+1)(2e^(x//2) - x)- int (2e^(x//2)-x) dx</acm>

<acm> \ \ \ \ =(x+1)(2e^(x//2) - x) - (4e^(x//2) - x^2/2) + C</acm>

<acm> \ \ \ \ = 2xe^(x//2) -x^2 + 2e^(x//2) -x - 4e^(x//2) + x^2/2 + C</acm>

<acm> \ \ \ \ = 2e^(x//2)(x-1)-x-x^2/2 + C</acm>



==== Example 7 ====
  * Prescripts simulated by subsuperscripts
<acmath>
{::}_(\ 92)^238U
</acmath>


  * Symbols can be stacked
<acmath>
 stackrel"def"= or \stackrel{\Delta}{=}" "("or ":=)
</acmath>


  * Accents can be used on any expression 
<acmath>
 hat(ab) bar(xy) ulA vec v dotx ddot y
</acmath>




You can try ASCIIMathML online here at ASCIIMathML.js sandbox.

ToDo

  • The ASCIIMathML was implemented as a pseudo plugin here. It seems the plugin simply adds the ASCIIMathML.js into DokuWiki. There is PHP port for ASCIIMathML, it seems a PHP version of ASCIIMathML is a better solution.
  • Interested developers are invited to correct/modify the code to obey the DokuWiki rules and for better performance.
  • To support the latest version of ASCIIMathML which has graphics capability like asciisvg.

Issues

  1. It seems there is a minor conflict with indexmenu. When ASCIIMathML is active the mouse right-click on the trees does not work.

Discussion

 
plugin/asciimathml.txt · Last modified: 2009/01/03 22:57 by 67.170.0.207
 

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported

Imprint Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsDarcsXRefTranslate