mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-24 07:34:22 +00:00
Experimental option $wgMathUseMathJax to have Extension:Math load things via MathJax.
If enabled, by default loads MathJax from a CDN and forces all equations through MathJax when JavaScript is available -- the image or source form gets used only as <noscript> fallback. This has a couple of problems for us: * if scripts are missing -- such as when viewed via MobileFrontend -- you end up with no math at all, as the <script type="math/tex"> bits get ignored but the <noscript> still hides the images. * while MathJax is loading things, blank spots on the page may appear and stuff jumps around * if loading new text in via ajax, it doesn't trigger there Also using some fairly default config, no idea how appropriate it is. Hoping to get some insight from Nageh who's done some of the MathJax work on Wikipedia so far - <https://en.wikipedia.org/wiki/User_talk:Nageh#MathJax_integration_into_stock_MediaWiki>
This commit is contained in:
parent
09679f2f39
commit
1042006fd4
|
@ -42,11 +42,20 @@ class MathHooks {
|
|||
* @return
|
||||
*/
|
||||
static function mathTagHook( $content, $attributes, $parser ) {
|
||||
global $wgContLang;
|
||||
global $wgContLang, $wgUseMathJax;
|
||||
$renderedMath = MathRenderer::renderMath(
|
||||
$content, $attributes, $parser->getOptions()
|
||||
);
|
||||
return $wgContLang->armourMath( $renderedMath );
|
||||
|
||||
if ( $wgUseMathJax ) {
|
||||
self::addMathJax( $parser );
|
||||
$output = Html::rawElement('noscript', null, $renderedMath ) .
|
||||
Html::element( 'script', array( 'type' => 'math/tex' ), $content );
|
||||
} else {
|
||||
$output = $renderedMath;
|
||||
}
|
||||
|
||||
return $wgContLang->armourMath( $output );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,4 +155,12 @@ class MathHooks {
|
|||
$wgMathPath = '/images/math';
|
||||
return true;
|
||||
}
|
||||
|
||||
static function addMathJax( $parser ) {
|
||||
global $wgMathJaxUrl;
|
||||
//$script = Html::element( 'script', array( 'type' => 'text/x-mathjax-config' ), $config );
|
||||
$html = Html::element( 'script', array( 'src' => $wgMathJaxUrl ) );
|
||||
|
||||
$parser->getOutput()->addHeadItem( $html, 'mathjax' );
|
||||
}
|
||||
}
|
||||
|
|
16
Math.php
16
Math.php
|
@ -81,6 +81,22 @@ $wgMathPath = false;
|
|||
*/
|
||||
$wgMathDirectory = false;
|
||||
|
||||
/**
|
||||
* Experimental option to use MathJax library to do client-side math rendering
|
||||
* when JavaScript is available. In supporting browsers this makes nice output
|
||||
* that's scalable for zooming, printing, and high-resolution displays.
|
||||
*
|
||||
* Not guaranteed to be stable at this time.
|
||||
*/
|
||||
$wgMathUseMathJax = false;
|
||||
|
||||
/**
|
||||
* Use of MathJax's CDN is governed by terms of service
|
||||
* <http://www.mathjax.org/download/mathjax-cdn-terms-of-service/>
|
||||
*
|
||||
* If you don't like them, install your own copy to load.
|
||||
*/
|
||||
$wgMathJaxUrl = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML';
|
||||
|
||||
////////// end of config settings.
|
||||
|
||||
|
|
Loading…
Reference in a new issue