JSM Markup Button

Because I have used the jsMath plugin a lot, and the shorthand mark-up ($..$ or [..]) doesn't suit me because I use those symbols in my texts, I felt it would be useful to have a button (or more) in the edit form to automatically insert jsMath mark-up. It is possible to do this by adding a plugin of the “Action” family.

What to Add?

Standard Version

In the “standard version”, the LaTeX math is entered between tags, such as

  • <jsm>LaTeX math</jsm> – for “inline” style (span in html)
  • <jsmath>LaTeX math</jsmath> – for “block” style (div in html)

It would thus be appropriate to have two buttons, one to add (or surround by) <jsm> tags, and one for <jsmath> tags.

My Fork

By the time I started on this enhancement, I had already made a change to the mark-up syntax in my version of the plugin. I didn't like the prospect of having to type 'ath' a lot, so I decided that if the opening <jsm>-tag were immediately followed by a newline (before the LaTeX code) it indicated a “block” style should be applied; otherwise, “inline.” So one could use a single button to add (or surround by) <jsm> tags, and backspace to convert it to “inline” when appropriate. This is what I did, and can share today. I suppose it can be easily extended to the “standard version” needs, but do not promise to so it soon–and don't have a good idea for a second button icon!

The Button Image

Naturally, the button should show something easily recognizable as being “math” tagging. After a little thought and play, I generated this gif image using “Original Equation Editor modified by thornahawk to use mimeTeX.

The Action.php Code

I “invested” a lot of time trying to understand, master, and choose between the two ways of adding an edit button suggested in the documentation. It was not quick and easy to test things, because the caching of JavaScript doesn't check for changes to plugins' files (if I recall correctly) so each change meant deleting all cache files by ftp. Even with the excellent Firefox Extension fireftp, that is tedious. In the end, I found another plugin that did something very similar (the blockquote plugin by Tobias Deutsch tobias@strix.at and Gina Haeussge osd@foosel.net), copied it, and made the necessary changes.

 <?php
 
 /** * 
  * JSMath action plugin to add jsmath button to the edit page toolbar
  * Almost identical to the Blockquote Plugin one, just a few names and tags-to-insert
  * changed. * To change the image on the button, add the desired image (not too big --eipi.gif
  * is 24x16, for instance)
  *
  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
  * Blockquote Plugin :
  * author     Tobias Deutsch <tobias@strix.at>
  * author     Gina Haeussge <osd@foosel.net>
  * Editor who changed a couple of lines to use it for JSMath:
  * @author     Maurice Lanselle <duckedape@laposte.net> 
 */
 // must be run within Dokuwiki
 if (!defined('DOKU_INC'))	die();
 if (!defined('DOKU_PLUGIN'))	define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
 	require_once (DOKU_PLUGIN . 'action.php');
 class action_plugin_jsmath extends DokuWiki_Action_Plugin {		
 /*
  *	 
  * return some info	
  */
 	function getInfo() {
 		return array (
 			'author' => 'Maurice Lanselle',
 			'email' => 'duckedape@laposte.net',
 			'date' => '2008-12-30',
 			'name' => 'JSMath Plugin (action component)',
 			'desc' => 'Action component provides toolbar button.',
 			'url' => '',
 					);	}	
 /*
  *	
  * register the eventhandlers	
  */
 	function register(& $controller) {
 		$controller->register_hook('TOOLBAR_DEFINE', 'AFTER', $this, 'jsmath_button',    array ());	}	
 /*
  *	
  * Inserts a toolbar button	 
  */
 	function jsmath_button(& $event, $param) {
 		$event->data[] = array (
 			'type' => 'format',
 			'title' => 'LaTeX math',
 			'icon' => '../../plugins/jsmath/eipi.gif',
 			'open' => '<jsm>\n',
 			'close' => '\n</jsm>',
 					);
 		return true;
 	}
 }

 
jsm_button.txt · Dernière modification: 2009/08/25 19:36 par suitable