Extension:PhpMathPublisher alternative

From MediaWiki.org

Jump to: navigation, search

PhpMathPublisher is an alternative which needs only PHP with the GD library and some fonts. No need for LaTeX or CGI, the latter is needed for the Mimetex alternative. (Also the graphical output looks better.)

PhpMathPublisher can be found at [1].


[edit] How to install PhpMathPublisher as an extension

MediaWiki and PhpMathPublisher need to be installed of course. (This has been tested with MediaWiki 1.6.10 and PhpMathPublisher 0.3.) Save the text below, which is an adaption of the Mimetex extension, in a file called phpmathpublisher.php and put the file into your extension folder.

<?php
 
$wgExtensionFunctions[] = "PhpMathPublisherExtension";
 
function PhpMathPublisherExtension() {
    global $wgParser;
    # register the extension with the WikiText parser
    # the first parameter is the name of the new tag.
    # In this case it defines the tag <example> ... </example>
    # the second parameter is the callback function for
    # processing the text between the tags
    $wgParser->setHook( "m", "render_PhpMathPublisher" );
}
 
/**
* Renders $text in PhpMathPublisher
*/
 
function render_PhpMathPublisher($input, $argv, $parser = null) {
 
  if (!$parser) $parser =& $GLOBALS['wgParser'];
  // $img_url is the url the PhpMathPublisher will be sent to.
  // IMPORTANT!! The URL below should be the link to YOUR PhpMathPublisher directory
  $img_url = "http://urltowhereyouputthephpmathpublisherfiles/rendermaths.php?message=<m>".$input."</m>";
 
  // Sets the output of the tex tag using the url from above.
  $output = "<script type=\"text/javascript\" src=\"$img_url\"></script>";
 
  return $output;
}
?>

and add the line:

require("extensions/phpmathpublisher.php");

to the end of your LocalSettings.php file in your MediaWiki root directory.

Now you can output PhpMathPublisher syntax with <m>...</m> tags. To put those tags into your Edit Toolbar, edit Editpage.php in your /includes/ directory. (You should make a backup of this file first just in case.)

Search for the following lines:

array(	'image'	=>'button_math.png',
	'open'	=>	"\\<math\\>",
	'close'	=>	"<\\/math\\>",
	'sample'=>	wfMsg('math_sample'),
	'tip'	=>	wfMsg('math_tip'),
	'key'	=>	'C'

And replace them with:

array(	'image'	=>'button_math.png',
	'open'	=>	"\\<m\\>",
	'close'	=>	"\\</m\\>",
	'sample'=>	wfMsg('math_sample'),
	'tip'	=>	wfMsg('math_tip'),
	'key'	=>	'C'

Since this is an adaption of the Mimetex extension the code is also licensed under the GNU General Public License.

This solution does not appear to work on version 1.13.x of MediaWiki.