Extension:DollarSign

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
DollarSign
Release status: unmaintained
Implementation Tag
Description Allows to recognize the LaTeX-style inline math mode with dollar signs.
Author(s) Sori Lee (Soritalk)
Latest version 1.0 (2008-10-18)
MediaWiki 1.5+
Database changes No
License GNU General Public License 2.0 or later
Download See the code section
Translate the DollarSign extension if it is available at translatewiki.net
Check usage and version matrix.

The DollarSign extension allows to recognize the LaTeX-style inline math mode with dollar signs. To print the dollar sign, type the dollar sign preceded by one backslash.

Installing[edit]

  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/DollarSign/DollarSign.php";
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Code[edit]

DollarSign.php
<?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' => 'https://www.mediawiki.org/wiki/Extension:DollarSign',
	'author' => 'Sori Lee',
	'description' => 'Allows to recognize the LaTeX-style inline math mode with dollar signs',
);

// 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;
}