Skip to content

pa4080/mw-SimpleMathJax

 
 

Repository files navigation

Purpose of this fork

In this version of Extension:SimpleMathJax is added an integration with Extension:VisualEditor. The current master branch is tested with MediaWiki 1.35 and the skins: Vector, Minerva Neue, Timeless.

For this purpose on the base of the original file ext.SimpleMathJax.js is created the file ext.SimpleMathJax.VE.js where along with mw.hook('wikipage.categories') is used also mw.hook('ve.activationComplete'). Within this hook the method MathJax.typesetPromise() is engaged. In this way the math expressions will be rendered within VisualEditor.

Within extension.json the resource module target is set to: mobile and desktop. Thus ext.SimpleMathJax.VE.js become available on booth.

When you are making some changes in the math expressions they will be rendered automatically after a short while (on last key-up, also on mouse move or click).

There are two variants of usage (note Ctrl+Shift is not longer needed):

  1. SimpleMathJax stand alone usage.

    In this case just add wfLoadExtension( 'SimpleMathJax' ); in your LocalSettings.php as it is described in the original installation guide. Here is a demo:

    MediaWiki:InternalWhitelist Example

  2. SimpleMathJax along with Extension:Math. In this scenario you need to load Extension:Math before Extension:SimpleMathJax in your LocalSettings.php. Here is a sample code from my wiki:

    wfLoadExtension( 'Math' );
    wfLoadExtension( 'SimpleMathJax' );
    
    // not mandatory option: 
    // add `class="mwe-math-element"` to the SimpleMathJax's output
    // in order to apply the same CSS code as of extension Math
    function SimpleMathJaxAddClass( array &$attributes, $tex ) {
        $attributes['class'] = 'mwe-math-element'; 
    }
    $wgHooks['SimpleMathJaxAttributes'][] = 'SimpleMathJaxAddClass';

    In this case we will use Extension:Math's features but the formulas will be rendered by Extension:SimpleMathJax. Here is a demo:

    MediaWiki:InternalWhitelist Example

THE ORIGINAL README.md

The SimpleMathJax extension enables MathJax, a Javascript library, for typesetting TeX formula in MediaWiki inside math environments.

https://www.mediawiki.org/wiki/Extension:SimpleMathJax

Installation

  • git clone in extensions directory
  • Using CDN is recommended. Because it's much faster than using local resources in most cases. ("the benefits of using a CDN")
$ git clone https://github.com/jmnote/SimpleMathJax.git
  • (Optional) If you want to use not CDN but local mathjax scripts, you can use git clone recursive.
$ git clone --recursive https://github.com/jmnote/SimpleMathJax.git
  • LocalSetting.php
wfLoadExtension( 'SimpleMathJax' );

Optional Settings

Setting name Description default value custom value example
$wgSmjUseCdn use CDN or local scripts true false
$wgSmjUseChem enable chem tag true false
$wgSmjEnableMenu MathJax.options.enableMenu true false
$wgSmjDisplayMath MathJax.tex.displayMath [] [['$$','$$'],['\[','\]']]
$wgSmjExtraInlineMath MathJax.tex.inlineMath [] [['\(', '\)']]
$wgSmjScale MathJax.chtml.scale 1 1.5
$wgSmjDisplayAlign MathJax.chtml.displayAlign center left
$wgSmjWrapDisplaystyle wrap with displaystyle true false

If you want to change font size, set $wgSmjScale.

wfLoadExtension( 'SimpleMathJax' );
$wgSmjScale = 1.5;

If you want to use local module, set $wgSmjUseCdn.

wfLoadExtension( 'SimpleMathJax' );
$wgSmjUseCdn = false;

If you want to enable some extra inlineMath symbol pairs, set $wgSmjExtraInlineMath.

wfLoadExtension( 'SimpleMathJax' );
$wgSmjExtraInlineMath = [["$","$"],["\\(","\\)"]];

If you want to disable MathJax context menu, set $wgSmjEnableMenu.

wfLoadExtension( 'SimpleMathJax' );
$wgSmjEnableMenu = false;

Hooks

The hook SimpleMathJaxAttributes is available to add attributes to the span around the math. This hook provides you with the opportunity to ensure that your own code does not interfere with MathJax's rendering of math.

For instance, if Lingo's JS functions are called before MathJax is invoked, then it is possible that Lingo will change the text so that MathJax could no longer render the math.

Lingo understands that it should not touch anything inside an element with the class noglossary so the following code can be used to keep Lingo from ruining math:

$wfHook['SimpleMathJaxAttributes']
	= function ( array &attributes, string $tex ) {
		$attributes['class'] = 'noglossary';
	}

Packages

No packages published

Languages

  • JavaScript 83.8%
  • PHP 16.2%