Skip to content

Commit 3a2cecc

Browse files
committed
Add what's new in v4 sections
1 parent 9a38480 commit 3a2cecc

File tree

17 files changed

+2797
-1
lines changed

17 files changed

+2797
-1
lines changed

upgrading/whats-new-4.0.rst

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,44 @@
44
What's New in MathJax v4.0
55
##########################
66

7-
Lots and lots.
7+
MathJax v4 is the culmination of several years of work, and includes
8+
significant new features, as well as improvements on existing
9+
features. There are some potentially breaking changes, and in order
10+
to not have these changes affect existing web sites, this release
11+
increments the major version number so that sites using the
12+
``mathjax@3`` URLs will be protected from these until they update to
13+
version 4 explicitly. That is, this new release is an opt-in update.
14+
15+
-----
16+
17+
.. _toc-v4-new-features:
18+
.. toctree::
19+
:caption: Major New Features
20+
:maxdepth: 2
21+
22+
whats-new-4.0/fonts
23+
whats-new-4.0/linebreaking
24+
whats-new-4.0/explorer
25+
whats-new-4.0/embedded-html
26+
whats-new-4.0/es6-modules
27+
whats-new-4.0/accessing
28+
29+
.. _toc-v4-other-changes:
30+
.. toctree::
31+
:caption: Other Significant Changes
32+
:maxdepth: 2
33+
34+
whats-new-4.0/input
35+
whats-new-4.0/output
36+
whats-new-4.0/promises
37+
whats-new-4.0/ui
38+
whats-new-4.0/api
39+
whats-new-4.0/build-tools
40+
whats-new-4.0/breaking
41+
42+
-----
43+
44+
See also the MathJax v4.0 release notes for a list of the commits and
45+
bug fixes in this release.
846

947
|-----|
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
.. _v4-accessing:
2+
3+
====================
4+
Accessing MathJax v4
5+
====================
6+
7+
MathJax version 4.0 can be accessed via CDN as
8+
9+
.. code-block::
10+
11+
https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js
12+
13+
using any one of the :ref:`combined components <combined-components>`:
14+
15+
* ``tex-html.js``
16+
* ``tex-svg.js``
17+
* ``tex-mml-chtml.js``
18+
* ``tex-mml-svg.js``
19+
* ``mml-html.js``
20+
* ``mml-svg.js``
21+
22+
Note that the ``/es5`` directory is no longer needed in the URL. See
23+
the :ref:`v4-es6-modules` section for more details on this change.
24+
25+
Each of the combined component files includes the ``mathjax-newcm``
26+
font, but also comes in a version ending in ``-nofont.js`` (e.g.,
27+
``tex-mml-chtml-nofont.js``) that does not include it, where you are
28+
expected to specify the font using the ``output.font`` configuration
29+
option. This saves your readers from having to download the
30+
``mathjax-newcm`` font that is not going to be used. See the section
31+
:ref:`v4-fonts` for details about the available fonts and how to
32+
access them.
33+
34+
The other combined configurations from v3 have been removed, as they
35+
were either redundant (now that the explorer is already included in
36+
all combined components), or where the ones that included
37+
``tex-full``. The latter have been removed because you will need to
38+
use the promise-based calls anyway, and that will handle the
39+
autoloading of extensions as well, and since the ``all-packages``
40+
extension doesn't include the newer packages, so isn't really "all"
41+
packages anyway, it has also been removed. See the section on
42+
:ref:`v4-all-packages` for more information, and for an example of how
43+
to implement an ``all-packages`` work-wround.
44+
45+
46+
.. _v4-scoped-packages:
47+
48+
MathJax Scoped NPM Packages
49+
===========================
50+
51+
With version 4, MathJax has moved to scoped packages for the source
52+
and font npm packages. The ``mathjax-full`` package is now
53+
``@mathjax/scr``, and the font packages are
54+
``@mathjax/mathjax-stix2-font``, ``@mathjax/mathjax-fira-font``, and
55+
so on. Future extensions and other packages will be in the
56+
``@mathjax`` scope as well. The only exception is that the
57+
``mathjax`` package remains un-scoped. Since the use of MathJax in
58+
browsers is primarily through the ``mathjax`` package, that means the
59+
URL for loading MathJax will remain the same, with only the version
60+
number needing to be changed and the ``/es5`` directory removed. That
61+
is, you can use
62+
63+
.. code-block:: shell
64+
65+
https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js
66+
67+
to load the latest version 4 of MathJax. To obtain the source version
68+
to include in a node project, you would use
69+
70+
.. code-block:: shell
71+
72+
pnpm install @mathjax/src@4
73+
pnpm install @mathjax/mathjax-newcm-font
74+
75+
and if you want a different font, a command like
76+
77+
.. code-block:: shell
78+
79+
pnpm install @mathjax/mathjax-stix2-font
80+
81+
to get the latest `mathjax-stx2` font package. The other fonts can be
82+
obtained similarly.
83+
84+
85+
.. _v4-browser-fonts:
86+
87+
Combined Components with Fonts
88+
==============================
89+
90+
In a browser, when you specify the :data:`font` option in the
91+
:data:`output` (or :data:`chtml` or :data:`svg`) block of the MathJax
92+
configuration, MathJax should access the fonts from
93+
``cdn.jsdelivr.net`` automatically. But if you load a :ref:`combined
94+
component <combined-components>` like ``tex-mml-chtml.js``, it will
95+
include the ``mathjax-newcm`` font data, even if you are loading
96+
another font.
97+
98+
You can overcome this by loading the ``-nofont`` version of the
99+
combined configuration, but there is also another approach. The font
100+
packages include combined configuration files that are equivalent to
101+
``tex-mml-chtml.js`` and ``tex-mml-svg.js``, but that include that
102+
package's font rather than ``mathjax-newcm``.
103+
104+
For example, the ``mathjax-stix2-font`` package includes
105+
``tex-mml-chtml-mathjax-stix2.js`` and
106+
``tex-mml-svg-mathjax-stix2.js``, so you can use
107+
108+
.. code-block:: shell
109+
110+
https://cdn.jsdelivr.net/npm/@mathjax/mathjax-stix2-font/tex-mml-chtml-mathjax-stix2.js
111+
112+
in order to get a single-file MathJax component that includes the
113+
``mathjax-stix2`` font rather than ``mathjax-newcm``.
114+
115+
In particular, you can get the equivalent of the ``tex-mml-html.js``
116+
file with the original MathJax TeX font all in one file using
117+
118+
.. code-block:: shell
119+
120+
https://cdn.jsdelivr.net/npm/@mathjax/mathjax-tex-font/tex-mml-chtml-mathjax-tex.js
121+
122+
This font does not have dynamic ranges (all the font data is in one
123+
file), so it should operate much the same as MathJax v3 in that
124+
respect.
125+
126+
Similarly, you could use the SVG versions to get MathJax with a
127+
specific font with SVG output.
128+
129+
|-----|

upgrading/whats-new-4.0/api.rst

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
.. _v4-api-changes:
2+
3+
===================
4+
MathJax API Changes
5+
===================
6+
7+
There are several MathJax API changes in this release, though most
8+
should not be breaking changes, as described below.
9+
10+
11+
.. _v4-api-promises:
12+
13+
New Promise-Based Functions
14+
===========================
15+
16+
Some actions in MathJax require loading extra code from an extension,
17+
which is an asynchronous action, as the browser must wait for the file
18+
to be loaded before it can use it. In MathJax v3, such asynchronous
19+
actions were mostly associated with loading TeX extension packages,
20+
and that could be avoided by pre-loading the extensions that are
21+
needed, so that typesetting could be performed synchronously. In v4,
22+
with fonts that have much greater coverage than in v3, some font data
23+
may need to be loaded asynchronously as well, and that means that
24+
typesetting may be asynchronous even if all the needed TeX extensions
25+
are pre-loaded. As a result, the :js:meth:`MathJax.typesetPromise()`
26+
function is more likely to be needed, and :js:meth:`MathJax.typeset()`
27+
will only work if no font data needs to be loaded. This is discussed
28+
in more detail in the :ref:`v4-promises` section.
29+
30+
Because of this greater need to handle asynchronous file loading,
31+
several new functions have been added to the :data:`MathDocument`
32+
class to provide promise-based versions of the corresponding
33+
synchronous calls. These include
34+
:js:meth:`mathDocument.convertPromise()`,
35+
:js:meth:`mathDocument.renderPromise()`, and
36+
:js:meth:`mathDocument.rerenderPromise()`, which wrap the
37+
:js:meth:`mathDocument.convert()`, :js:meth:`mathDocument.render()`,
38+
and :js:meth:`mathDocument.rerender()` methods in the needed
39+
:js:meth:`mathjax.handleRetriesFor()` call and return its promise.
40+
This makes it easier to perform these actions when font data or TeX
41+
extensions need to be loaded than having to use
42+
:js:meth:`mathjax.handlerRetriesFor()` yourself.
43+
44+
In the past, promise-based functions, like
45+
:js:meth:`MathJax.typesetPromise()`,
46+
:js:meth:`MathJax.tex2chtmlPromise()`, etc., could not be called while
47+
another one was currently in effect. That is, you needed to wait for
48+
the promise from one such call to resolve before you could do the next
49+
call, and the documentation encouraged you to use
50+
:data:`MathJax.startup.promise` to help chain these calls together.
51+
In v4, these functions now use an internal promise (associated with
52+
the :data:`MathDocument`) to prevent more than one from running
53+
concurrently, so these calls chain automatically. In particular, you
54+
should no longer use :data:`MathJax.startup.promise` yourself to
55+
serialize your calls to these functions.
56+
57+
You may wish to use the new :data:`MathDocument` promise to
58+
synchronize other code with MathJax's typesetting operations without
59+
having to keep track of the promises returned by the various
60+
promise-based functions. For this reason, MathJax provides a new
61+
:js:meth:`mathDocument.whenReady()` method of the :data:`MathDocument`
62+
class. It takes a function as its argument, and performs that action
63+
when its internal promise is resolved; that is, when any previous
64+
promise-based typesetting or conversion actions complete. You can
65+
think of :js:meth:`mathDocument.whenReady()` as queuing your action to
66+
be performed whenever MathJax has finished anything that has been
67+
queued previously.
68+
69+
The function you pass to :js:meth:`mathDocument.whenReady()` can
70+
return a promise (if it starts any asynchronous actions of its own,
71+
for example), in which case that promise must be fulfilled before any
72+
further :js:meth:`mathDocument.whenReady()` actions will be
73+
performed. For example
74+
75+
.. code-block:: js
76+
77+
const doc = mathjax.document('', {});
78+
doc.whenReady(() => console.log('A'));
79+
doc.whenReady(() => {
80+
return new Promise((ok, fail) => {
81+
setTimeout(() => {
82+
console.log('B');
83+
ok();
84+
}, 1000);
85+
});
86+
});
87+
doc.whenReady(() => console.log('C'));
88+
89+
would print ``A`` to the developer console, then a second later print
90+
``B`` followed by ``C``.
91+
92+
93+
.. _v4-api-speech:
94+
95+
Changes to Speech Generation
96+
============================
97+
98+
In v3, the speech generation was performed within the
99+
:ref:`semantic-enrich-component` component along with the semantic
100+
enrichment of the internal MathML representation of the mathematical
101+
expressions that it processes. In v4, these two functions have been
102+
separated from each other, and the speech-generation functionality is
103+
performed in a new :ref:`speech-component` component. This is
104+
included in all the combined components, but can be loaded
105+
individually by including ``a11y/speech`` in the :data:`load` array of
106+
the :data:`loader` block of your MathJax configuration.
107+
108+
The section on :ref:`v4-explorer-details` already mentions the new
109+
:meth:`MathJax.done()` function that is used to shut down the
110+
web-worker or node worker-thread that is created for speech
111+
production. There is a corresponding new
112+
:js:meth:`mathDocument.done()` method for the :data:`MathDocument`
113+
class that can be used in applications that don't use the MathJax
114+
Component framework, but rather call on MathJax modules directly.
115+
116+
117+
.. _v4-api-input-jax:
118+
119+
Named Access to Input Jax
120+
=========================
121+
122+
A MathDocument's :data:`inputJax` array included any input jax that
123+
you have loaded. E.g., in the ``tex-mml-svg.js`` combined component,
124+
it would contain entries for both the TeX and MathML input jax.
125+
Because this is an array, it was not obvious in v3 which of the two
126+
entries was which (you would need to check each entry's :data:`name`
127+
property to see if it is the one you want). In this release, the
128+
:data:`inputJax` array also includes properties that point to the
129+
input jax by name. That is, :data:`mathDocument.inputJax.tex` will
130+
point to the TeX input jax, if any, and similarly for
131+
:data:`mathDocument.inputJax.mathml`.
132+
133+
134+
.. _v4-api-modules:
135+
136+
Change to ES6 Modules
137+
=====================
138+
139+
The fact that the webpacked components are now ES6 files (see the
140+
section on :ref:`v4-es6-modules`) means that MathJax will no longer
141+
run in IE11, so you should no longer include the ``polyfill.io``
142+
script that was recommended in the documentation for IE11 support.
143+
144+
The ``es5`` directory has been removed from the MathJax distribution,
145+
so the ``/es5`` should be removed from the URL used to access
146+
MathJax's components. In the ``mathjax`` npm package, the files from
147+
the ``es5`` directory are now in the main directory, and for
148+
``mathjax-full`` (now called ``@mathjax/src``), they are in the
149+
generic ``bundle`` directory.
150+
151+
152+
.. _v4-api-options:
153+
154+
Changes to Configuration Options
155+
================================
156+
157+
The :data:`tex.skipHtmlTags` configuration property now includes
158+
``select`` and ``option`` tags, since pop-up menu items can only
159+
contain textual content, not other HTML tags.
160+
161+
In addition to the new configuration options discussed in other
162+
sections, there are several additional options available in this
163+
release:
164+
165+
* Two new settings in the :data:`options.menuOptions.settings`
166+
configuration object: :data:`showSRE` and :data:`showLatex`, which
167+
control whether to include the data attributes generated by the
168+
speech-rule-engine or the :attr:`data-latex` attributes in MathML
169+
and SVG output in the `Show Math As` and `Copy to Clipboard` menus.
170+
171+
..
172+
173+
* :data:`mathml.verify.checkMathvariants`, which controls whether the
174+
MathML input jax will check that :attr:`mathvariant` attribute
175+
values are valid math variants and report an error if not. Invalid
176+
:attr:`mathvariant` values can cause MathJax to crash under some
177+
circumstances, so the default value of this option is ``true``, but
178+
this may cause current expressions with invalid math variant values
179+
that used to render to now show those nodes as having errors.
180+
181+
The :data:`lineWidth` property of the :data:`Metrics` object (used to
182+
store information about the font metrics of the container surrounding
183+
an expression) has been removed, as the line-breaking algorithm ended
184+
up using the :data:`containerWidth` property directly. That affects
185+
functions that accept metric data as their inputs (such as
186+
:js:meth:`mathDocument.convert()` and :js:meth:`MathJax.tex2chtml()`),
187+
as these will no longer accept :data:`lineWidth` in the options passed
188+
to them.
189+
190+
Some backward-compatibility code in v3 has been removed; e.g., when
191+
the :data:`tex.multlineWidth` configuration option was moved to
192+
:data:`tex.ams.multlineWidth` in an earlier version, there was code to move
193+
the old value to the new location, but that code has been removed in
194+
v4.
195+
196+
197+
.. _v4-api-code:
198+
199+
Changes to the Code Base
200+
========================
201+
202+
The MathJax code base has undergone a major cleanup effort for this
203+
release, using ``eslint`` and ``prettier`` to format the code
204+
consistently, and new life-cycle scripts to perform these actions have
205+
been added to the ``package.json`` file. Other modernizations, like
206+
moving from :meth:`String.substr()` to :meth:`String.substring()` were
207+
also performed.
208+
209+
A number of object name changes are listed in the
210+
:ref:`v4-breaking-changes` section.
211+
212+
Finally, MathJax's test suite has been expanded to include more than
213+
3,000 tests. We have full coverage for the TeX input jax and the
214+
``ts/util`` directories, but more tests need to be written for other
215+
sections of the code base. This is an ongoing project that will take
216+
time to complete.
217+
218+
|-----|

0 commit comments

Comments
 (0)