Extension:DollarSign
Jump to navigation
Jump to search
Template:Extension code in wiki Template:Extension
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
Code
- 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;
}