Skip to content

jmnote/SimpleMathJax

Repository files navigation

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
  • LocalSettings.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
$wgSmjDirectMathJax which ones can be written directly "full" "none"
$wgSmjEnableMenu MathJax.options.enableMenu true false
$wgSmjDisplayMath MathJax.tex.displayMath [] [['$$','$$'],['\[','\]']]
$wgSmjExtraInlineMath MathJax.tex.inlineMath [] [['\(', '\)']]
$wgSmjIgnoreHtmlClass MathJax.options.ignoreHtmlClass "mathjax_ignore|comment|
diff-(context|
addedline|deletedline)"
"mathjax_ignore"
$wgSmjScale MathJax.chtml.scale 1 1.5
$wgSmjDisplayAlign MathJax.chtml.displayAlign "center" "left"
$wgSmjWrapDisplaystyle wrap with displaystyle on <math> true false
$wgSmjEnableHtmlAttributes process attributes of math tag false true
$wgSmjConfigByRevision switch the configuration according to the article's revision [] [['upto'=>1048576,
'wgSmjDisplayAlign'
=>'left']]

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. Pairs of [math][/math] are always in-line math delimiters. (And independently of this setting, you can use $ ... $ to switch to math mode within chemical formulas in the mhchem extension.)

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

Since version 0.8.7, inlineMath and blockMath and environments are ignored in edit summaries and diffs. To restore the previous behavior (especially if you are using maths in edit summaries), set $wgSmjIgnoreHtmlClass.

wfLoadExtension( 'SimpleMathJax' );
$wgSmjIgnoreHtmlClass = "mathjax_ignore";

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

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

Since version 0.8.8, by enabling $wgSmjEnableHtmlAttributes, the display attribute of the <math> tag will work, and the class, id and title attributes of the <math> tag will be carried over to the <span> tag.

wfLoadExtension( 'SimpleMathJax' );
$wgSmjEnableHtmlAttributes = true;

In version 0.8.9, an option was added to make it completely dedicated to <math> and <chem>. Setting $wgSmjDirectMathJax to env disables \ref{} and escaping of $, while setting it to none disables all delimiters, including [math], making it mandatory to enclose all TeX expressions in <math> or <chem> (and $wgSmjDisplayMath, $wgSmjExtraInlineMath, $wgSmjIgnoreHtmlClass, etc. will become meaningless).

wfLoadExtension( 'SimpleMathJax' );
$wgSmjDirectMathJax = "none";

By using $wgSmjConfigByRevision, you can apply different settings to an article's revisions up to a certain point and to revisions after that. This allows past revisions to be displayed with the settings that were in place at the time. Only the keys written inside the [] are overwritten. Preview, History and SpecialPages are treated as base cases that do not apply this setting.

wfLoadExtension( 'SimpleMathJax' );
$wgSmjDirectMathJax = "none";    #To match the preview with the actual rendering, write the latest settings in the base case
$wgSmjConfigByRevision = [
	["upto"=>50000, "wgSmjDirectMathJax"=>"full"],
	["since"=>50001, "upto"=>60000, "wgSmjDirectMathJax"=>"env"]
];

Hooks

The hook SimpleMathJaxAttributes is available to add attributes to the span around the math. (Note that this process is performed only for <math> elements, and other delimiters are handled directly by MathJax.) 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:

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

Contributors

jmnote
jmnote
jamesmontalvo3
James Montalvo
hexmode
Mark A. Hershberger
dummy-index
dummy-index
lakejason0
lakejason0
badshah400
Atri Bhattacharya
Nikerabbit
Niklas Laxström
cubercsl
cubercsl
liberaldev
Liberal Dev
Adnn
Adnn
dexgs
Dexter Gaon-Shatford
pastakhov
Pavel Astakhov
v-gar
Viktor Garske
rickselby
Rick Selby
guyru
guyru
poiega
poiega
vedmaka
Vedmaka
yardenac
Yardena Cohen

About

MediaWiki Extension SimpleMathJax

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 19