Extension:DollarSign

MediaWiki extensions manual
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

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
  • Copy the code into a file and place the file(s) in a directory called DollarSign in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    require_once "$IP/extensions/DollarSign/DollarSign.php";
    
  •   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['ParserBeforeInternalParse'][] = '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;
}