This is an old revision of the document!
MAsciiMath Plugin
Compatible with DokuWiki
Tested with 2011-05-25a “Rincewind”
The missing download url means that this extension cannot be installed via the Extension Manager. Please see Publishing a Plugin on dokuwiki.org. Recommended are public repository hosts like GitHub, GitLab or Bitbucket.
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 asciimath, asciimathml, jsmath, math, math2, mathpublish
Description
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.
Installation and Plugin Code
Create a plugin directory named masciimath
and put these files in it:
syntax.php
from belowASCIIMathPHP.cfg.php
andASCIIMathPHP.class.php
from the ASCIIMathPHP download (you may have to rename them)
- syntax.php
<?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' => 'M-AsciiMath', '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); 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(.*)>/i', '<math$1><mstyle fontfamily="sans-serif" displaystyle="true">', $txt); #$txt = preg_replace ('/<\/math>/i', '</mstyle></math>', $txt); $raw = $match; $raw = str_replace ('"', "''", $raw); # compromise .. 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; } } ?>
Discussion
The two commented lines beautify the output IMHO, uncomment them if you prefer.