Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions upgrading/whats-new-3.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <special-keys>` documentation for details.

.. _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
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
<https://github.com/zorkow/speech-rule-engine/releases/v4.0.0>`__ as well as the
`MathJax v3.2.1 release notes
<https://github.com/mathjax/MathJax-src/releases/v3.2.1>`__ for details.

-----

.. _v3.2-other:
Expand Down
2 changes: 1 addition & 1 deletion web/typeset.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
138 changes: 74 additions & 64 deletions web/webpack.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

-----

Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -589,64 +589,74 @@ 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 || {};

//
// 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
Expand All @@ -656,7 +666,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
-------------------------

Expand Down Expand Up @@ -730,7 +740,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.
Expand Down Expand Up @@ -770,8 +780,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));
Expand Down