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.
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 pluging does not supprt the Latest version of ASCIIMathML. For changes see ASCIIMath Changes.txt.
| Revision | Date | Description |
|---|---|---|
| 0.0 | 2008-08-09 | Experimental |
{dokuwiki}/lib/plugins (make sure, included subdirectories are unpacked correctly); this will create the following directories: {dokuwiki}/lib/plugins/asciimathml.{dokuwiki}/lib/plugins/asciimathml/main.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);
<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.
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.
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported