DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:asciimathml

ASCIIMathML plugin

Compatible with DokuWiki

version 2010-11-07|version 2011-05-25|version 2011-05-25a(also compatible with older version 2009-05-08)

plugin Plugin for translating ASCII math notation to MathML on wiki pages

Last updated on
2011-06-25
Provides
Syntax

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to jsmath, math, math2

Tagged with formula, math, mathml

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.202011-06-16Experimental
0.212011-06-23stable

Installation

  1. Download the source archive (~14k)from ASCIIMathML - Plugin
  2. Unpack it in your Doku­Wiki plugins directory {dokuwiki}/lib/plugins; this will create the following folder:
  • {dokuwiki}/lib/plugins/asciimathml.

The folder shall contain the following files

  • ASCIIMathML148.js
  • plugin.info.txt
  • README
  • script.js
  • syntax.php

That's it!

See here an image ofasciimathml in use

plugin codes

syntax.php

<?php
/**
 * DokuWiki Plugin asciimathml (Syntax Component)
 *
 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
 * @author  Mohammad Rahmani <m [dot] rahmani [at] aut [dot] ac [dot] ir>
 
 *  Rev. 0.20: Some bugs fixed
 *  Date: Thursday, June 16, 2011
 
 *  Rev. 0.21: Some bugs fixed, support for the latest version of Dokuwiki (2011-05-25a)
 *  Date: Thursday, June 23, 2011
 *  -Note use <acm> tag for inline formatting
 *        use <acmath> tag for block formatting
 
 */
 
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
 
if (!defined('DOKU_LF')) define('DOKU_LF', "\n");
if (!defined('DOKU_TAB')) define('DOKU_TAB', "\t");
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
 
require_once DOKU_PLUGIN.'syntax.php';
 
class syntax_plugin_asciimathml extends DokuWiki_Syntax_Plugin {
    public function getType(){ return 'formatting'; }
    public function getPType(){ return 'normal'; }
    public function getSort(){ return 450; }
 
     /**
     * Connect pattern to lexer
     */
    public 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.
     */
    public 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.
     */
    public function render($mode, &$renderer, $data) {
        if($mode != 'xhtml') return false;
        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;
        }
    }
}
 
?>

script.js

/*
 This script installs the ASCIIMathML JavaScript
 to be used through "asciimath" plugin in DokuWiki
  Mohammad Rahmani
  Rev. 0: Trial
  Date: Friday, 25 Jul. 2008  10:14:40
 
  Rev. 0.20: Some bugs fixed
  Date: Thursday, June 16, 2011
 
  Rev. 0.21: Some bugs fixed
  Date: Thursday, June 23, 2011
   - all function in the previos script.js was deleted!
   - support for the latest version of Dokuwiki (2011-5-25a)
 
 
 
    * 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 address to ASCIIMathML installation
 
 
document.write('<script type="text/javascript" src="' + DOKU_BASE + 'lib/plugins/asciimathml/ASCIIMathML148.js' + '"></script>');

Usage/Syntax

  • For inline formula and when you don't want to start a div!
 <acm> ASCII Math Notation goes here </acm>
  • Formula rendered as a new paragraph
 <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>
(df(x))/dx=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. Nothing reported by now!

Discussion

This is a very nice plugin, when you can have it running…

  • You can decide to patch the asciimathml/ASCIIMathML148.js file to support Opera and other recent browsers, like this:
function AMisMathMLavailable() {
  if (navigator.appName.slice(0,8)=="Netscape")
    if (navigator.appVersion.slice(0,1)>="5") return null;
    else return AMnoMathMLNote();
  else if (navigator.appName.slice(0,9)=="Microsoft")
    try {
        var ActiveX = new ActiveXObject("MathPlayer.Factory.1");
        return null;
    } catch (e) {
        return AMnoMathMLNote();
    }
// Opera support for MathML
  else if (navigator.appName=="Opera")
    return null;
  else return AMnoMathMLNote();
}

Alexander Mihailov 2010-10-14

plugin/asciimathml.txt · Last modified: 2017-05-03 20:00 by Klap-in