Skip to content

Commit a64ba8c

Browse files
authored
Merge pull request #308 from mathjax/v3.2.1-update
V3.2.1 update
2 parents e512b47 + 1dfdf8c commit a64ba8c

File tree

3 files changed

+89
-65
lines changed

3 files changed

+89
-65
lines changed

upgrading/whats-new-3.2.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ explorer to v3. This includes summarising expressions and navigation
186186
of tabular expressions, like matrices or equation systems. See the
187187
:ref:`keyboard command <special-keys>` documentation for details.
188188

189+
.. _v3.2-sre4:
190+
191+
As of v3.2.1 MathJax pulls in SRE v4 which supports as Catalan, Danish,
192+
Norwegian (Bokmal and Nynorsk) and Swedish as additional languages. It also
193+
integrates SRE code directly making use of its promise structure, instead of
194+
loading it as an external package. Consequently the old `sreReady` method will
195+
be deprecated and the loophole to use speech rule engine directly via the `SRE`
196+
namespace in the browser, is closed.
197+
198+
See the `SRE release notes
199+
<https://github.com/zorkow/speech-rule-engine/releases/v4.0.0>`__ as well as the
200+
`MathJax v3.2.1 release notes
201+
<https://github.com/mathjax/MathJax-src/releases/v3.2.1>`__ for details.
202+
189203
-----
190204

191205
.. _v3.2-other:

web/typeset.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ MathJax keeps track of all the math that it has typeset within your
154154
page. This is so that if you change the output renderer (using the
155155
MathJax contextual menu), it can be changed to use the new format, for
156156
example; or if you change the accessibility settings, say to enable
157-
the expression explorer, all the math can be updated to incldue the
157+
the expression explorer, all the math can be updated to include the
158158
speech strings that it uses. If you modify the page to include new
159159
mathematics and call :meth:`MathJax.typeset()` or
160160
:meth:`MathJax.typesetPromise()`, the newly typeset mathematics will be

web/webpack.rst

Lines changed: 74 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ component that has exactly the pieces and configuration that you
1515
want. You can also use them to make a custom extension, for example a
1616
TeX input extension, that takes advantage of the components already
1717
loaded, 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

2020
It is also possible to make a completely custom build of MathJax that
2121
doesn'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,
6666
you should be able to make the components described below. The
6767
building instructions assume you used ``npm`` to aquire MathJax; if
6868
you 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
288288
you can put them on your server, or simply point `fontURL` to one of
289289
the 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
652662
the 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
656666
jax), and then defines a global ``MathJax`` object that has the
657667
:meth:`tex2speech()` function that our custom build offers.
658668

659-
669+
660670
The Webpack Configuration
661671
-------------------------
662672

@@ -730,7 +740,7 @@ like
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
736746
root 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

Comments
 (0)