Index: trunk/extensions/Math/Math.php |
— | — | @@ -81,7 +81,23 @@ |
82 | 82 | */ |
83 | 83 | $wgMathDirectory = false; |
84 | 84 | |
| 85 | +/** |
| 86 | + * Experimental option to use MathJax library to do client-side math rendering |
| 87 | + * when JavaScript is available. In supporting browsers this makes nice output |
| 88 | + * that's scalable for zooming, printing, and high-resolution displays. |
| 89 | + * |
| 90 | + * Not guaranteed to be stable at this time. |
| 91 | + */ |
| 92 | +$wgMathUseMathJax = false; |
85 | 93 | |
| 94 | +/** |
| 95 | + * Use of MathJax's CDN is governed by terms of service |
| 96 | + * <http://www.mathjax.org/download/mathjax-cdn-terms-of-service/> |
| 97 | + * |
| 98 | + * If you don't like them, install your own copy to load. |
| 99 | + */ |
| 100 | +$wgMathJaxUrl = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML'; |
| 101 | + |
86 | 102 | ////////// end of config settings. |
87 | 103 | |
88 | 104 | $wgDefaultUserOptions['math'] = MW_MATH_PNG; |
Index: trunk/extensions/Math/Math.hooks.php |
— | — | @@ -42,11 +42,20 @@ |
43 | 43 | * @return |
44 | 44 | */ |
45 | 45 | static function mathTagHook( $content, $attributes, $parser ) { |
46 | | - global $wgContLang; |
| 46 | + global $wgContLang, $wgUseMathJax; |
47 | 47 | $renderedMath = MathRenderer::renderMath( |
48 | 48 | $content, $attributes, $parser->getOptions() |
49 | 49 | ); |
50 | | - return $wgContLang->armourMath( $renderedMath ); |
| 50 | + |
| 51 | + if ( $wgUseMathJax ) { |
| 52 | + self::addMathJax( $parser ); |
| 53 | + $output = Html::rawElement('noscript', null, $renderedMath ) . |
| 54 | + Html::element( 'script', array( 'type' => 'math/tex' ), $content ); |
| 55 | + } else { |
| 56 | + $output = $renderedMath; |
| 57 | + } |
| 58 | + |
| 59 | + return $wgContLang->armourMath( $output ); |
51 | 60 | } |
52 | 61 | |
53 | 62 | /** |
— | — | @@ -146,4 +155,12 @@ |
147 | 156 | $wgMathPath = '/images/math'; |
148 | 157 | return true; |
149 | 158 | } |
| 159 | + |
| 160 | + static function addMathJax( $parser ) { |
| 161 | + global $wgMathJaxUrl; |
| 162 | + //$script = Html::element( 'script', array( 'type' => 'text/x-mathjax-config' ), $config ); |
| 163 | + $html = Html::element( 'script', array( 'src' => $wgMathJaxUrl ) ); |
| 164 | + |
| 165 | + $parser->getOutput()->addHeadItem( $html, 'mathjax' ); |
| 166 | + } |
150 | 167 | } |