@@ -15,7 +15,7 @@ component that has exactly the pieces and configuration that you
1515want. You can also use them to make a custom extension, for example a
1616TeX input extension, that takes advantage of the components already
1717loaded, but implements additional functionality.
18- These possibilities are described in :ref: `custom-component ` below.
18+ These possibilities are described in :ref: `custom-component ` below.
1919
2020It is also possible to make a completely custom build of MathJax that
2121doesn't use the MathJax components at all, but includes direct calls
@@ -66,7 +66,7 @@ to install ``webpack`` and its needed libraries. Once this is done,
6666you should be able to make the components described below. The
6767building instructions assume you used ``npm `` to aquire MathJax; if
6868you used ``git ``, then you will need to remove
69- ``node_modules/mathjax-full `` from the paths that incldue them.
69+ ``node_modules/mathjax-full `` from the paths that include them.
7070
7171-----
7272
@@ -287,7 +287,7 @@ can be found. They are in the
287287``mathjax-full/es5/output/chtml/fonts/woff-v2 `` directory, and
288288you can put them on your server, or simply point `fontURL ` to one of
289289the CDN directories for the fonts.
290-
290+
291291
292292.. _custom-extension :
293293
@@ -589,64 +589,74 @@ the following:
589589
590590.. code-block :: javascript
591591
592- //
593- // Load the desired components
594- //
595- const mathjax = require (' mathjax-full/js/mathjax.js' ).mathjax ; // MathJax core
596- const TeX = require (' mathjax-full/js/input/tex.js' ).TeX ; // TeX input
597- const MathML = require (' mathjax-full/js/input/mathml.js' ).MathML ; // MathML input
598- const browser = require (' mathjax-full/js/adaptors/browserAdaptor.js' ).browserAdaptor ; // browser DOM
599- const Enrich = require (' mathjax-full/js/a11y/semantic-enrich.js' ).EnrichHandler ; // semantic enrichment
600- const Register = require (' mathjax-full/js/handlers/html.js' ).RegisterHTMLHandler ; // the HTML handler
601- const AllPackages = require (' mathjax-full/js/input/tex/AllPackages' ).AllPackages ; // all TeX packages
602- const STATE = require (' mathjax-full/js/core/MathItem.js' ).STATE ;
603-
604- const sreReady = require (' mathjax-full/js/a11y/sre.js' ).sreReady (); // SRE promise;
605-
606- //
607- // Register the HTML handler with the browser adaptor and add the semantic enrichment
608- //
609- Enrich (Register (browser ()), new MathML ());
610-
611- //
612- // Initialize mathjax with a blank DOM.
613- //
614- const html = MathJax .document (' ' , {
615- sre: {
616- speech: ' shallow' , // add speech to the enriched MathML
617- },
618- InputJax: new TeX ({
619- packages: AllPackages .filter ((name ) => name !== ' bussproofs' ), // Bussproofs needs an output jax
620- macros: {require: [' ' , 1 ]} // Make \require a no-op since all packages are loaded
621- })
622- });
623-
624- //
625- // The user's configuration object
626- //
627- const CONFIG = window .MathJax || {};
628-
629- //
630- // The global MathJax object
631- //
632- window .MathJax = {
633- version: mathjax .version ,
634- html: html,
635- sreReady: sreReady,
636-
637- tex2speech (tex , display = true ) {
638- const math = new html.options.MathItem (tex, inputJax, display);
639- math .convert (html, STATE .CONVERT );
640- return math .root .attributes .get (' data-semantic-speech' ) || ' no speech text generated' ;
641- }
642- }
592+ //
593+ // Load the desired components
594+ //
595+ const mathjax = require (' mathjax-full/js/mathjax.js' ).mathjax ; // MathJax core
596+ const TeX = require (' mathjax-full/js/input/tex.js' ).TeX ; // TeX input
597+ const MathML = require (' mathjax-full/js/input/mathml.js' ).MathML ; // MathML input
598+ const browser = require (' mathjax-full/js/adaptors/browserAdaptor.js' ).browserAdaptor ; // browser DOM
599+ const Enrich = require (' mathjax-full/js/a11y/semantic-enrich.js' ).EnrichHandler ; // semantic enrichment
600+ const Register = require (' mathjax-full/js/handlers/html.js' ).RegisterHTMLHandler ; // the HTML handler
601+ const AllPackages = require (' mathjax-full/js/input/tex/AllPackages' ).AllPackages ; // all TeX packages
602+ const STATE = require (' mathjax-full/js/core/MathItem.js' ).STATE ;
603+
604+ const sreReady = require (' mathjax-full/js/a11y/sre.js' ).sreReady (); // SRE promise;
605+
606+ //
607+ // Register the HTML handler with the browser adaptor and add the semantic enrichment
608+ //
609+ Enrich (Register (browser ()), new MathML ());
610+
611+ //
612+ // Initialize mathjax with a blank DOM.
613+ //
614+ const html = mathjax .document (' ' , {
615+ sre: {
616+ speech: ' shallow' , // add speech to the enriched MathML
617+ },
618+ InputJax: new TeX ({
619+ packages: AllPackages .filter ((name ) => name !== ' bussproofs' ), // Bussproofs needs an output jax
620+ macros: {require: [' ' , 1 ]} // Make \require a no-op since all packages are loaded
621+ })
622+ });
623+
624+ //
625+ // The user's configuration object
626+ //
627+ const CONFIG = window .MathJax || {};
628+
629+ //
630+ // The global MathJax object
631+ //
632+ window .MathJax = {
633+ version: mathjax .version ,
634+ html: html,
635+ sreReady: sreReady,
636+
637+ tex2speech (tex , display = true ) {
638+ const math = new html.options.MathItem (tex, html .inputJax [0 ], display);
639+ return mathjax .handleRetriesFor (() => math .convert (html, STATE .CONVERT )).then (() => {
640+ let speech = ' ' ;
641+ math .root .walkTree (node => {
642+ const attributes = node .attributes .getAllAttributes ();
643+ console .log (attributes);
644+ if (! speech && attributes[' data-semantic-speech' ] &&
645+ ! attributes[' data-semantic-parent' ]) {
646+ speech = attributes[' data-semantic-speech' ];
647+ }
648+ });
649+ return speech || ' no speech text generated' ;
650+ });
651+ }
652+ };
643653
644- //
645- // Perform ready function, if there is one
646- //
647- if (CONFIG .ready ) {
648- sreReady .then (CONFIG .ready );
649- }
654+ //
655+ // Perform ready function, if there is one
656+ //
657+ if (CONFIG .ready ) {
658+ sreReady .then (CONFIG .ready );
659+ }
650660
651661 Unlike the component-based example above, this custom build calls on
652662the MathJax source files directly. The ``require `` commands at the
@@ -656,7 +666,7 @@ handling the conversions that we will be doing (using a TeX input
656666jax), and then defines a global ``MathJax `` object that has the
657667:meth: `tex2speech() ` function that our custom build offers.
658668
659-
669+
660670The Webpack Configuration
661671-------------------------
662672
730740
731741.. code-block :: javascript
732742
733- const speech = MathJax .tex2speech (' \\ sqrt{x^2+1}' , true );
743+ const speech = await MathJax .tex2speech (' \\ sqrt{x^2+1}' , true );
734744
735745 to obtain a text string that contains the speech text for the square
736746root given in the TeX string.
@@ -770,8 +780,8 @@ want to do speech generation. For example
770780.. code-block :: javascript
771781
772782 function showSpeech (tex , display = false ) {
773- MathJax .sreReady = MathJax .sreReady .then (() => {
774- const speech = MathJax .tex2speech (tex, display);
783+ MathJax .sreReady = MathJax .sreReady .then (async () => {
784+ const speech = await MathJax .tex2speech (tex, display);
775785 const output = document .getElementById (' speech' );
776786 output .innerHTML = ' ' ;
777787 output .appendChild (document .createTextNode (speech));
0 commit comments