DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:masciimath

This is an old revision of the document!


MAsciiMath Plugin

Compatible with DokuWiki

Tested with 2011-05-25a “Rincewind”

plugin Implementation of ASCIIMathPHP for Dokuwiki

Last updated on
2011-08-03
Provides
Syntax

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

Tagged with formula, math

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. Math code must be enclosed by backticks (`e=mc^2`).

Installation and Plugin Code

Create a plugin directory named masciimath and put these files in it:

  1. syntax.php from below
  2. ASCIIMathPHP.class.php from the ASCIIMathPHP download
  3. ASCIIMathPHP.cfg.php from the ASCIIMathPHP download, or use my alternative expanded and bugfixed edition here.
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'   => '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;
    }
}
?>
plugin/masciimath.1312338818.txt.gz · Last modified: 2011-08-03 04:33 by 87.73.100.138

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki