From 3e4178c1e1cf847653b433e5c68ff7d964584595 Mon Sep 17 00:00:00 2001 From: zorkow Date: Fri, 20 May 2022 20:22:52 +0200 Subject: [PATCH 1/4] Updates the custom example with speech. --- web/webpack.rst | 138 ++++++++++++++++++++++++++---------------------- 1 file changed, 75 insertions(+), 63 deletions(-) diff --git a/web/webpack.rst b/web/webpack.rst index 499945f9..32b0d4d9 100644 --- a/web/webpack.rst +++ b/web/webpack.rst @@ -15,7 +15,7 @@ component that has exactly the pieces and configuration that you want. You can also use them to make a custom extension, for example a TeX input extension, that takes advantage of the components already loaded, but implements additional functionality. -These possibilities are described in :ref:`custom-component` below. +These possibilities are described in :ref:`custom-component` below. It is also possible to make a completely custom build of MathJax that doesn't use the MathJax components at all, but includes direct calls @@ -287,7 +287,7 @@ can be found. They are in the ``mathjax-full/es5/output/chtml/fonts/woff-v2`` directory, and you can put them on your server, or simply point `fontURL` to one of the CDN directories for the fonts. - + .. _custom-extension: @@ -589,64 +589,76 @@ the following: .. code-block:: javascript - // - // Load the desired components - // - const mathjax = require('mathjax-full/js/mathjax.js').mathjax; // MathJax core - const TeX = require('mathjax-full/js/input/tex.js').TeX; // TeX input - const MathML = require('mathjax-full/js/input/mathml.js').MathML; // MathML input - const browser = require('mathjax-full/js/adaptors/browserAdaptor.js').browserAdaptor; // browser DOM - const Enrich = require('mathjax-full/js/a11y/semantic-enrich.js').EnrichHandler; // semantic enrichment - const Register = require('mathjax-full/js/handlers/html.js').RegisterHTMLHandler; // the HTML handler - const AllPackages = require('mathjax-full/js/input/tex/AllPackages').AllPackages; // all TeX packages - const STATE = require('mathjax-full/js/core/MathItem.js').STATE; - - const sreReady = require('mathjax-full/js/a11y/sre.js').sreReady(); // SRE promise; - - // - // Register the HTML handler with the browser adaptor and add the semantic enrichment - // - Enrich(Register(browser()), new MathML()); - - // - // Initialize mathjax with a blank DOM. - // - const html = MathJax.document('', { - sre: { - speech: 'shallow', // add speech to the enriched MathML - }, - InputJax: new TeX({ - packages: AllPackages.filter((name) => name !== 'bussproofs'), // Bussproofs needs an output jax - macros: {require: ['', 1]} // Make \require a no-op since all packages are loaded - }) - }); - - // - // The user's configuration object - // - const CONFIG = window.MathJax || {}; - - // - // The global MathJax object - // - window.MathJax = { - version: mathjax.version, - html: html, - sreReady: sreReady, - - tex2speech(tex, display = true) { - const math = new html.options.MathItem(tex, inputJax, display); - math.convert(html, STATE.CONVERT); - return math.root.attributes.get('data-semantic-speech') || 'no speech text generated'; - } - } + // + // Load the desired components + // + const mathjax = require('mathjax-full/js/mathjax.js').mathjax; // MathJax core + const TeX = require('mathjax-full/js/input/tex.js').TeX; // TeX input + const MathML = require('mathjax-full/js/input/mathml.js').MathML; // MathML input + const browser = require('mathjax-full/js/adaptors/browserAdaptor.js').browserAdaptor; // browser DOM + const Enrich = require('mathjax-full/js/a11y/semantic-enrich.js').EnrichHandler; // semantic enrichment + const Register = require('mathjax-full/js/handlers/html.js').RegisterHTMLHandler; // the HTML handler + const AllPackages = require('mathjax-full/js/input/tex/AllPackages').AllPackages; // all TeX packages + const STATE = require('mathjax-full/js/core/MathItem.js').STATE; + + const sreReady = require('mathjax-full/js/a11y/sre.js').sreReady(); // SRE promise; + + // + // Register the HTML handler with the browser adaptor and add the semantic enrichment + // + Enrich(Register(browser()), new MathML()); + + // + // Initialize mathjax with a blank DOM. + // + const html = mathjax.document('', { + sre: { + speech: 'shallow', // add speech to the enriched MathML + }, + InputJax: new TeX({ + packages: AllPackages.filter((name) => name !== 'bussproofs'), // Bussproofs needs an output jax + macros: {require: ['', 1]} // Make \require a no-op since all packages are loaded + }) + }); + + // + // The user's configuration object + // + const CONFIG = window.MathJax || {}; + console.log(CONFIG); + + + // + // The global MathJax object + // + window.MathJax = { + version: mathjax.version, + html: html, + sreReady: sreReady, + + tex2speech(tex, display = true) { + const math = new html.options.MathItem(tex, html.inputJax[0], display); + return mathjax.handleRetriesFor(() => math.convert(html, STATE.CONVERT)).then(() => { + let speech = ''; + math.root.walkTree(node => { + const attributes = node.attributes.getAllAttributes(); + console.log(attributes); + if (!speech && attributes['data-semantic-speech'] && + !attributes['data-semantic-parent']) { + speech = attributes['data-semantic-speech']; + } + }); + return speech || 'no speech text generated'; + }); + } + }; - // - // Perform ready function, if there is one - // - if (CONFIG.ready) { - sreReady.then(CONFIG.ready); - } + // + // Perform ready function, if there is one + // + if (CONFIG.ready) { + sreReady.then(CONFIG.ready); + } Unlike the component-based example above, this custom build calls on the MathJax source files directly. The ``require`` commands at the @@ -656,7 +668,7 @@ handling the conversions that we will be doing (using a TeX input jax), and then defines a global ``MathJax`` object that has the :meth:`tex2speech()` function that our custom build offers. - + The Webpack Configuration ------------------------- @@ -730,7 +742,7 @@ like .. code-block:: javascript - const speech = MathJax.tex2speech('\\sqrt{x^2+1}', true); + const speech = await MathJax.tex2speech('\\sqrt{x^2+1}', true); to obtain a text string that contains the speech text for the square root given in the TeX string. @@ -770,8 +782,8 @@ want to do speech generation. For example .. code-block:: javascript function showSpeech(tex, display = false) { - MathJax.sreReady = MathJax.sreReady.then(() => { - const speech = MathJax.tex2speech(tex, display); + MathJax.sreReady = MathJax.sreReady.then(async () => { + const speech = await MathJax.tex2speech(tex, display); const output = document.getElementById('speech'); output.innerHTML = ''; output.appendChild(document.createTextNode(speech)); From 3bebfd027e11fe423e1efa65e005a92b7096d0d5 Mon Sep 17 00:00:00 2001 From: zorkow Date: Sun, 29 May 2022 14:42:40 +0200 Subject: [PATCH 2/4] Typos. --- web/typeset.rst | 2 +- web/webpack.rst | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/web/typeset.rst b/web/typeset.rst index 47a42116..0b947a57 100644 --- a/web/typeset.rst +++ b/web/typeset.rst @@ -154,7 +154,7 @@ MathJax keeps track of all the math that it has typeset within your page. This is so that if you change the output renderer (using the MathJax contextual menu), it can be changed to use the new format, for example; or if you change the accessibility settings, say to enable -the expression explorer, all the math can be updated to incldue the +the expression explorer, all the math can be updated to include the speech strings that it uses. If you modify the page to include new mathematics and call :meth:`MathJax.typeset()` or :meth:`MathJax.typesetPromise()`, the newly typeset mathematics will be diff --git a/web/webpack.rst b/web/webpack.rst index 32b0d4d9..6a76892d 100644 --- a/web/webpack.rst +++ b/web/webpack.rst @@ -66,7 +66,7 @@ to install ``webpack`` and its needed libraries. Once this is done, you should be able to make the components described below. The building instructions assume you used ``npm`` to aquire MathJax; if you used ``git``, then you will need to remove -``node_modules/mathjax-full`` from the paths that incldue them. +``node_modules/mathjax-full`` from the paths that include them. ----- @@ -625,8 +625,6 @@ the following: // The user's configuration object // const CONFIG = window.MathJax || {}; - console.log(CONFIG); - // // The global MathJax object From a7a781309a3473dbf58756378e3b8678ad151361 Mon Sep 17 00:00:00 2001 From: zorkow Date: Sun, 29 May 2022 15:03:40 +0200 Subject: [PATCH 3/4] SRE changes for 3.2.1. --- upgrading/whats-new-3.2.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/upgrading/whats-new-3.2.rst b/upgrading/whats-new-3.2.rst index 49707b51..4362ec7e 100644 --- a/upgrading/whats-new-3.2.rst +++ b/upgrading/whats-new-3.2.rst @@ -186,6 +186,20 @@ explorer to v3. This includes summarising expressions and navigation of tabular expressions, like matrices or equation systems. See the :ref:`keyboard command ` documentation for details. +.. _v3.2.1-sre: + +As of v3.2.1 MathJax pulls in SRE v4 which supports as Catalan, Danish, +Norwegian (Bokmal and Nynorsk) and Swedish as additional languages. It also +integrates SRE code directly making use of its promise structure, instead of +loading it as an external package. Consequently the old `sreReady` method will +be deprecated and the loophole to use speech rule engine directly via the `SRE` +namespace in the browser, is closed. + +See the `SRE release notes +`__ as well as the +`MathJax v3.2.1 release notes + Date: Sun, 29 May 2022 15:05:36 +0200 Subject: [PATCH 4/4] Fixing link issue. --- upgrading/whats-new-3.2.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/upgrading/whats-new-3.2.rst b/upgrading/whats-new-3.2.rst index 4362ec7e..5d241ef9 100644 --- a/upgrading/whats-new-3.2.rst +++ b/upgrading/whats-new-3.2.rst @@ -186,7 +186,7 @@ explorer to v3. This includes summarising expressions and navigation of tabular expressions, like matrices or equation systems. See the :ref:`keyboard command ` documentation for details. -.. _v3.2.1-sre: +.. _v3.2-sre4: As of v3.2.1 MathJax pulls in SRE v4 which supports as Catalan, Danish, Norwegian (Bokmal and Nynorsk) and Swedish as additional languages. It also @@ -198,7 +198,7 @@ namespace in the browser, is closed. See the `SRE release notes `__ as well as the `MathJax v3.2.1 release notes -`__ for details. -----