Extension:DollarSign

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
DollarSign

Release status: stable

Implementation Tag
Description Recognize the LaTeX-style inline math mode with dollar signs. To print the dollar sign, type the dollar sign preceded by one backslash.
Author(s) Sori Lee (SoriTalk)
Last version 1.0 (October 18th 2008)
MediaWiki 1.5 or newer
License GPL
Download (Code available in the article.)
Hooks used
ParserBeforeStrip

Check usage (experimental)

[edit] How to install

[edit] Installing the extension

Make the file 'DollarSign.php' containing the following code, and place it in the 'extensions' directory.

<?php
/**
 * @author Sori Lee <sori24 (at) gmail (dot) com>
 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 */
 
if(!defined('MEDIAWIKI'))
    die("This is an extension to the MediaWiki package and cannot be run standalone.");
 
// Register as an extention
$wgExtensionCredits['parserhook'][] = array(
        'name' => 'DollarSign',
        'version' => '1.0',
        'url' => 'http://www.mediawiki.org/wiki/Extension:DollarSign',
        'author' => 'Sori Lee',
        'description' => 'Recognize the LaTeX-style inline math mode with dollar signs. To print the dollar sign, type the dollar sign preceded by one backslash.',
);
 
// Register hooks
$wgHooks['ParserBeforeStrip'][] = 'dsParse';
 
// Parse function
function dsParse( &$parser, &$text, &$stripState ) {
        // We replace '$...$' by '<math>...</math>' and '\$' by '$'.
        $pattern = array('/([^\\\\]|^)\$([^\$]*)\$/', '/\\\\\$/');
        $replace = array('$1<math>$2</math>', '\$');
 
        // Perform the substitution.
        $text = preg_replace($pattern, $replace, $text);
 
        return true;
}

[edit] Loading the extension

At the end of LocalSettings.php, add the following.

require_once("$IP/extensions/DollarSign.php");
Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox