jsmath plugin by Stephen Gould
Plugin for displaying latex equations using jsMath
Last updated on 2008-12-05. Provides Syntax.
No compatibility info given!
Similar to asciimathml, format, latex, math, math2.
jsmath under lib/pluginssyntax.php and script.js to the new directoryjsMathURL variable in script.js to contain the correct path to jsMath.jsJSMATH_USE_DOLLAR variable to 1 in syntax.phpNOTE: When trying to display latex formulas for the first time, make sure to clear the browser cache! Otherwise you'll get frustrated thinking the install didn't go through; alternatively add somewhere in your latex test page this:
~~NOCACHE~~
syntax.php
<?php /** * jsMath Plugin - see http://www.math.union.edu/~dpvc/jsmath/ * * Syntax: <jsm> ...latex... </jsm> * <jsmath> ...latex... </jsmath> * (optional) $ ...latex... $ * * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @author Stephen Gould <sgould@cs.stanford.edu> */ /* set this to 1 if you want to use $\sum_i i$ to use math mode */ /* Works precisely as <jsm>\sum_i i</jsm> */ if(!defined('JSMATH_USE_DOLLAR')) define('JSMATH_USE_DOLLAR',0); 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_jsmath extends DokuWiki_Syntax_Plugin { /** * Get an associative array with plugin info. */ function getInfo(){ return array( 'author' => 'Stephen Gould', 'email' => 'sgould@cs.stanford.edu', 'date' => '2008-07-12', 'name' => 'jsMath Plugin', 'desc' => 'Plugin for displaying latex equations using jsMath See http://www.math.union.edu/~dpvc/jsmath/ Syntax: <jsm(ath)?>math formulae</jsm(ath)?>', 'url' => 'http://www.dokuwiki.org/wiki:plugins', ); } function getType(){ return 'formatting'; } function getAllowedTypes() { return array('substition','formatting','disabled'); } function getPType(){ return 'normal'; } function getSort(){ return 222; } /** * Connect pattern to lexer */ function connectTo($mode) { $this->Lexer->addEntryPattern('<jsm>(?=.*?</jsm>)',$mode,'plugin_jsmath'); $this->Lexer->addEntryPattern('<jsmath>(?=.*?</jsmath>)',$mode,'plugin_jsmath'); if(JSMATH_USE_DOLLAR) { $this->Lexer->addEntryPattern('\$(?=.*?\$)',$mode,'plugin_jsmath'); } } function postConnect() { $this->Lexer->addExitPattern('</jsm>','plugin_jsmath'); $this->Lexer->addExitPattern('</jsmath>','plugin_jsmath'); if(JSMATH_USE_DOLLAR) { $this->Lexer->addExitPattern('\$','plugin_jsmath'); } } /** * Handler to prepare matched data for the rendering process. */ function handle($match, $state, $pos, &$handler){ switch ($state) { case DOKU_LEXER_ENTER : if(JSMATH_USE_DOLLAR) { return array($state, preg_match("/^(\\\$|<jsm>)/", $match)); } else { return array($state, preg_match("/^<jsm>/", $match)); } break; case DOKU_LEXER_MATCHED : break; case DOKU_LEXER_UNMATCHED : return array($state, $match); break; case DOKU_LEXER_EXIT : if(JSMATH_USE_DOLLAR) { return array($state, preg_match("/^(\\\$|<\/jsm>)/", $match)); } else { return array($state, preg_match("/^<\/jsm>/", $match)); } 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="math">'; } else { $renderer->doc .= '<div class="math">'; } 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
// full url to jsMath installation var jsMathURL = ''; document.write('<SCRIPT>jsMath = {Controls: {cookie: {scale: 120}}}</SCRIPT>'); document.write('<SCRIPT SRC="' + jsMathURL + '/jsMath.js"></SCRIPT>'); function installJsMath() { jsMath.Process(document); } addInitEvent(installJsMath);
On DokuWiki 2008-05-05. jsMath returns warnings. It seems it has some conflicts with DokuWiki. See following:
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in C:\DokuWikiStick\dokuwiki\lib\plugins\syntax.php on line 134 Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\DokuWikiStick\dokuwiki\lib\plugins\syntax.php on line 134 Warning: array_merge() [function.array-merge]: Argument #1 is not an array in C:\DokuWikiStick\dokuwiki\lib\plugins\syntax.php on line 134
I think this was an error in getAllowedTypes(), now fixed.
It works now. Thank you.
I added support to use dollar notation instead of the <jsm> tags. So you can now conveniently do both
<jsm>\sum_i i</jsm> $\sum_i i$
For this to work, you have to change the line near the beginning of the file.
define('JSMATH_USE_DOLLAR',1)
Is the original author ok with that change? We could make this an option accessible through the admin interface.
Then trying to clear cache, dokuWiki return this error message:
“It looks like jsMath failed to set up properly (error code -7). I will try to keep going, but it could get ugly.”
What could be an error?
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported