Plugin for translating ASCII math notation to MathML on wiki pages
Compatible with DokuWiki
Similar to asciimath, jsmath, masciimath, math, math2, mathpublish
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.
| Revision | Date | Description |
|---|---|---|
| 0.20 | 2011-06-16 | Experimental |
| 0.21 | 2011-06-23 | stable |
{dokuwiki}/lib/plugins; this will create the following folder: {dokuwiki}/lib/plugins/asciimathml.The folder shall contain the following files
That's it!
See here an image ofasciimathml in use
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>');
<acm> ASCII Math Notation goes here </acm>
<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>
(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.
This is a very nice plugin, when you can have it running…
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(); }
Author_mail: sunsande@gmail.com Alexander Mihailov LastUpdate_dt: 2010-10-14