Debian Codegraph @

extensions/Math/modules/ext.math.mathjax.js

raw symbols SCIP
1 ( function () {
2 'use strict';
3 const extensionAssetsPath = mw.config.get( 'wgExtensionAssetsPath' );
4 window.MathJax = {
5 loader: {
6 // see https://docs.mathjax.org/en/latest/input/mathml.html
7 load: [ '[mml]/mml3' ],
8 // see https://docs.mathjax.org/en/latest/options/startup/loader.html
9 paths: {
10 mathjax: extensionAssetsPath + '/Math/modules/mathjax/es5'
11 }
12 },
13 // helper function for https://phabricator.wikimedia.org/T375932
14 /* eslint-disable no-return-assign */
15 remapChars( v1, v2, base, map, font ) {
16 const c1 = v1.chars;
17 const c2 = v2.chars;
18 for ( let i = 0; i < 26; i++ ) {
19 const data1 = c1[ map[ i ] || base + i ] || [];
20 const data2 = c2[ 0x41 + i ];
21 if ( data1.length === 0 ) {
22 c1[ base + i ] = data1;
23 }
24 [ 0, 1, 2 ].forEach( ( j ) => data1[ j ] = data2[ j ] );
25 data1[ 3 ] = Object.assign( {}, data2[ 3 ], { f: font, c: String.fromCharCode( 0x41 + i ) } );
26 }
27 },
28
29 startup: {
30 ready() {
31 window.MathJax.startup.defaultReady();
32 // See https://phabricator.wikimedia.org/T375932 and the suggested fix from
33 // https://github.com/mathjax/MathJax/issues/3292#issuecomment-2383760829
34 // Makes rendering of \matcal look similar to the browsers MathML rendering
35 // and the old image rendering.
36 // Note that \mathsrc (which is unsupported by texvc) would map to the
37 // same unicode chars and thus should not be activated.
38 const variant = window.MathJax.startup.document.outputJax.font.variant;
39 const map = { 1: 0x212C, 4: 0x2130, 5: 0x2131, 7: 0x210B, 8: 0x2110, 11: 0x2112, 12: 0x2133, 17: 0x211B };
40 window.MathJax.config.remapChars( variant.normal, variant[ '-tex-calligraphic' ], 0x1D49C, map, 'C' );
41 window.MathJax.config.remapChars( variant.normal, variant[ '-tex-bold-calligraphic' ], 0x1D4D0, {}, 'CB' );
42 // See https://phabricator.wikimedia.org/T375241 and the suggested startup function from
43 // https://github.com/mathjax/MathJax/issues/3030#issuecomment-1490520850
44 // This workaround will be included in the MathJax 4 release and no longer be
45 // required when we upgrade to MathJax 4.
46 const { Mml3 } = window.MathJax._.input.mathml.mml3.mml3;
47 const mml3 = new Mml3( window.MathJax.startup.document );
48 const adaptor = window.MathJax.startup.document.adaptor;
49 const processor = new XSLTProcessor();
50 const parsed = adaptor.parse( Mml3.XSLT, 'text/xml' );
51 processor.importStylesheet( parsed );
52 mml3.transform = ( node ) => {
53 const div = adaptor.node( 'div', {}, [ adaptor.clone( node ) ] );
54 const dom = adaptor.parse( adaptor.serializeXML( div ), 'text/xml' );
55 const mml = processor.transformToDocument( dom );
56 return ( mml ? adaptor.tags( mml, 'math' )[ 0 ] : node );
57 };
58 // inputJax[0] did not work as per https://github.com/mathjax/MathJax/issues/3287#issuecomment-2363843017
59 const MML = window.MathJax.startup.document.inputJax[ 1 ];
60 MML.mmlFilters.items.pop(); // remove old filter
61 MML.mmlFilters.add( mml3.mmlFilter.bind( mml3 ) );
62 }
63 }
64 };
65 }() );