Compatible with DokuWiki
Similar to asciimath, asciimathml, jsmath, math, math2, mathpublish
This is an implementation of ASCIIMathPHP for DokuWiki. ASCIIMathPHP is a PHP port of the brilliant ASCIIMathML standard for easy encoding of math.
It's similar to asciimathml but doesn't rely on JavaScript. Math code must be enclosed by backticks (`e=mc^2`).
Create a plugin directory named masciimath and put these files in it:
syntax.php from belowASCIIMathPHP.class.php from the ASCIIMathPHP downloadASCIIMathPHP.cfg.php from the ASCIIMathPHP download, or use my alternative expanded and bugfixed edition here.<?php /** * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Morten Nielsen <mortenb@gmail.com> */ if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_PLUGIN.'syntax.php'); include_once(dirname(__FILE__).'/ASCIIMathPHP.class.php'); class syntax_plugin_masciimath extends DokuWiki_Syntax_Plugin { function getInfo(){ return array( 'author' => 'Morten Nielsen', 'email' => 'mortenb@gmail.com', 'date' => '2011-06-22', 'name' => 'MAsciiMath', 'desc' => 'Implementation of AsciiMathPHP for DokuWiki', 'url' => 'http://www.dokuwiki.org/wiki:plugins', ); } function getType(){ return 'substition'; } function getSort(){ return 300; } function connectTo($mode) { $this->Lexer->addSpecialPattern('`.*?`',$mode,'plugin_masciimath');} function handle($match, $state, $pos, &$handler){ $txt = $match; $txt = str_replace('`', '', $txt); $txt = preg_replace ('/"(.*?)"/', '"$1" ', $txt); # corrects a bug in ASCIIMathPHP 2.0 that requires a symbol delimited by quotes to be followed by a space include(dirname(__FILE__).'/ASCIIMathPHP.cfg.php'); $math_object = new ASCIIMathPHP($symbol_arr); $math_object->setExpr($txt); $math_object->genMathML(); $txt = $math_object->getMathML(); $txt = preg_replace ('/(<math.*?>)(.*?)(<\/math>)/is', '$1<mstyle fontfamily="sans-serif" displaystyle="true">$2</mstyle>$3', $txt); # beautifies the output; uncomment if you prefer $raw = $match; $raw = str_replace ('"', "''", $raw); # compromise .. a double quote sign is rendered as a single quote sign in the hover-title return array($txt, $raw); } function render($mode, &$renderer, $data) { if ($mode!='xhtml') return false; list($txt, $raw) = $data; $renderer->doc .= '<span class="acmath" title="'.$raw.'">'.$txt.'</span>'; return true; } } ?>