Skip to content

Commit 26a40ce

Browse files
committed
Update the README for v4
1 parent cfcb216 commit 26a40ce

File tree

1 file changed

+98
-78
lines changed

1 file changed

+98
-78
lines changed

README.md

Lines changed: 98 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
## Beautiful math in all browsers
33

44
![GitHub release version](https://img.shields.io/github/v/release/mathjax/MathJax-src.svg?sort=semver)
5+
![GitHub release version (v3)](https://img.shields.io/github/package-json/v/mathjax/MathJax/legacy-v3.svg?label=release-v3)
56
![GitHub release version (v2)](https://img.shields.io/github/package-json/v/mathjax/MathJax/legacy-v2.svg?label=release-v2)
67
![NPM version](https://img.shields.io/npm/v/mathjax.svg?style=flat)
7-
<a href="http://www.numfocus.org">![powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat)</a>
88
![jsdelivr rank](https://flat.badgen.net/jsdelivr/rank/npm/mathjax?color=green)
99
![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hm/mathjax)
1010
![npm monthly downloads (full)](https://img.shields.io/npm/dm/mathjax?label=npm)
1111
![npm total downloads](https://img.shields.io/npm/dt/mathjax.svg?style=flat&label=npm%20total)
1212

1313
MathJax is an open-source JavaScript display engine for LaTeX, MathML,
14-
and AsciiMath notation that works in all modern browsers. It was
15-
designed with the goal of consolidating the recent advances in web
16-
technologies into a single, definitive, math-on-the-web platform
17-
supporting the major browsers and operating systems. It requires no
18-
setup on the part of the user (no plugins to download or software to
19-
install), so the page author can write web documents that include
20-
mathematics and be confident that users will be able to view it
21-
naturally and easily. Simply include MathJax and some mathematics in
22-
a web page, and MathJax does the rest.
14+
and AsciiMath notation that works in all modern browsers, with
15+
built-in support for assistive technology like screen readers,
16+
including automatic speech generation and an expression explorer that
17+
can be used to investigate typeset mathematics on a more granular
18+
level than the complete expression. It requires no setup on the part
19+
of the user (no plugins to download or software to install), so the
20+
page author can write web documents that include mathematics and be
21+
confident that users will be able to view it naturally and easily.
22+
Simply include MathJax and some mathematics in a web page, and MathJax
23+
does the rest.
2324

2425
Some of the main features of MathJax include:
2526

@@ -40,7 +41,7 @@ and <https://docs.mathjax.org> for the MathJax documentation.
4041

4142
## MathJax Components
4243

43-
MathJax version 3 uses files called *components* that contain the
44+
MathJax uses files called *components* that contain the
4445
various MathJax modules that you can include in your web pages or
4546
access on a server through NodeJS. Some components combine all the
4647
pieces you need to run MathJax with one or more input formats and a
@@ -66,12 +67,10 @@ source code for MathJax (which are available in a separate [MathJax
6667
source repository](https://github.com/mathjax/MathJax-src/)). These
6768
component files are the ones served by the CDNs that offer MathJax to
6869
the web. In version 2, the files used on the web were also the source
69-
files for MathJax, but in version 3, the source files are no longer on
70-
the CDN, as they are not what are run in the browser.
70+
files for MathJax, but in version 3 and above, the source files are no
71+
longer on the CDN, as they are not what are run in the browser.
7172

72-
The components are stored in the `es5` directory, and are in ES5 format
73-
for the widest possible compatibility. In the future, we may make an
74-
`es6` directory containing ES6 versions of the components.
73+
The components are ES6 format as CommonJS modules.
7574

7675
## Installation and Use
7776

@@ -82,42 +81,38 @@ need to install anything. Simply use a `script` tag that loads
8281
MathJax from the CDN. E.g.,
8382

8483
``` html
85-
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
84+
<script src="https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-chtml.js" defer></script>
8685
```
8786

8887
See the [MathJax
89-
documentation](https://docs.mathjax.org/en/latest/index.html#browser-components),
90-
the [MathJax Web Demos](https://github.com/mathjax/MathJax-demos-web),
91-
and the [MathJax Component
92-
Repository](https://github.com/mathjax/MathJax-demos-web) for more information.
88+
documentation](https://docs.mathjax.org/en/latest/index.html#browser-components)
89+
and the [MathJax Web Demos](https://github.com/mathjax/MathJax-demos-web), and the [MathJax
90+
Node Demos](https://github.com/mathjax/MathJax-demos-node) for more
91+
information.
9392

9493
### Hosting your own copy of the MathJax Components
9594

9695
If you want to host MathJax from your own server, you can do so by
97-
installing the `mathjax` package using `npm` and moving the `es5`
98-
directory to an appropriate location on your server:
96+
installing the `mathjax` package using `npm` and moving the contents
97+
to an appropriate location on your server:
9998

100-
``` bash
101-
npm install mathjax@3
102-
mv node_modules/mathjax/es5 <path-to-server-location>/mathjax
10399
```
104-
105-
Note that we are still making updates to version 2, so include `@3`
106-
when you install, since the latest chronological version may not be
107-
version 3.
100+
npm install mathjax@4
101+
mv node_modules/mathjax <path-to-server-location>/mathjax
102+
```
108103

109104
Alternatively, you can get the files via GitHub:
110105

111-
``` bash
112-
git clone https://github.com/mathjax/MathJax.git mj-tmp
113-
mv mj-tmp/es5 <path-to-server-location>/mathjax
114-
rm -rf mj-tmp
106+
```
107+
git clone https://github.com/mathjax/MathJax.git mathjax
108+
mv mathjax <path-to-server-location>/mathjax
109+
rm -rf mathjax
115110
```
116111

117112
Then (in either case) you can use a script tag like the following:
118113

119114
``` html
120-
<script id="MathJax-script" async src="<url-to-your-site>/mathjax/tex-chtml.js"></script>
115+
<script src="<url-to-your-site>/mathjax/tex-chtml.js" defer></script>
121116
```
122117

123118
where `<url-to-your-site>` is replaced by the URL to the location
@@ -129,39 +124,58 @@ for details.
129124

130125
### Using MathJax components in a node application
131126

132-
To use MathJax components in a node application, install the `mathjax` package:
127+
To use MathJax components in a node application, install the `mathjax`
128+
package:
133129

134130
``` bash
135-
npm install mathjax@3
131+
npm install mathjax@4
136132
```
137133

138-
(we are still making updates to version 2, so you should include `@3`
139-
since the latest chronological version may not be version 3).
134+
Then import `mathjax` within your application and initialize it:
135+
136+
``` js
137+
import MathJax from 'mathjax';
138+
await MathJax.init({ ... });
139+
```
140+
141+
where `{ ... }` is the MathJax configuration you want to use. E.g.,
142+
143+
``` js
144+
import MathJax from 'mathjax';
145+
await MathJax.init({
146+
loader: {load: ['input/tex', 'output/svg']}
147+
});
148+
const svg = await MathJax.tex2svgPromise('\\frac{1}{x^2-1}', {display: true});
149+
console.log(MathJax.startup.adaptor.outerHTML(svg));
150+
```
140151

141-
Then require `mathjax` within your application:
152+
153+
Alternatively, in an ES5 node application, you can use
142154

143155
```js
144-
require('mathjax').init({ ... }).then((MathJax) => { ... });
156+
const MathJax = require('mathjax');
157+
MathJax.init({ ... }).then(() => { ... });
145158
```
146159

147160
where the first `{ ... }` is a MathJax configuration, and the second
148161
`{ ... }` is the code to run after MathJax has been loaded. E.g.
149162

150163
```js
151-
require('mathjax').init({
164+
const MathJax = require('mathjax');
165+
MathJax.init({
152166
loader: {load: ['input/tex', 'output/svg']}
153-
}).then((MathJax) => {
167+
}).then(() => {
154168
const svg = MathJax.tex2svg('\\frac{1}{x^2-1}', {display: true});
155169
console.log(MathJax.startup.adaptor.outerHTML(svg));
156170
}).catch((err) => console.log(err.message));
157171
```
158172

159-
**Note:** this technique is for node-based application only, not for
160-
browser applications. This method sets up an alternative DOM
161-
implementation, which you don't need in the browser, and tells MathJax
162-
to use node's `require()` command to load external modules. This
163-
setup will not work properly in the browser, even if you webpack it or
164-
bundle it in other ways.
173+
**Note:** the technique in the two examples above is for node-based
174+
application only, not for browser applications. This method sets up
175+
an alternative DOM implementation, which you don't need in the
176+
browser, and it depends on node and the local file system in other
177+
ways. This setup will not work properly in the browser, even if you
178+
webpack it or use some other bundler.
165179

166180
See the
167181
[documentation](https://docs.mathjax.org/en/latest/index.html#server-nodejs)
@@ -170,45 +184,51 @@ Repository](https://github.com/mathjax/MathJax-demos-node) for more details.
170184

171185
## Reducing the Size of the Components Directory
172186

173-
Since the `es5` directory contains *all* the component files, so if
187+
Since the MathJax package contains *all* the component files, so if
174188
you are only planning one use one configuration, you can reduce the
175189
size of the MathJax directory by removing unused components. For
176190
example, if you are using the `tex-chtml.js` component, then you can
177-
remove the `tex-mml-chtml.js`, `tex-svg.js`, `tex-mml-svg.js`,
178-
`tex-chtml-full.js`, and `tex-svg-full.js` configurations, which will
179-
save considerable space. Indeed, you should be able to remove
180-
everything other than `tex-chtml.js`, and the `input/tex/extensions`,
181-
`output/chtml/fonts/woff-v2`, `adaptors`, `a11y`, and `sre`
182-
directories. If you are using the results only on the web, you can
183-
remove `adaptors` as well.
184-
185-
If you are not using A11Y support (e.g., speech generation, or
186-
semantic enrichment), then you can remove `a11y` and `sre` as well
187-
(though in this case you may need to disable the assistive tools in
188-
the MathJax contextual menu in order to avoid MathJax trying to load
189-
them when they aren't there).
190-
191-
If you are using SVG rather than CommonHTML output (e.g., `tex-svg.js`
192-
rather than `tex-chtml.js`), you can remove the
193-
`output/chtml/fonts/woff-v2` directory. If you are using MathML input
191+
remove the `tex-mml-chtml.js`, `tex-svg.js`, `tex-mml-svg.js`, and the
192+
files ending in `-nofont.js`, which will save considerable space.
193+
Indeed, you should be able to remove everything other than
194+
`tex-chtml.js`, and the `input/tex/extensions`, `adaptors`, `a11y`,
195+
and `sre` directories. If you are using the results only on the web,
196+
you can remove `adaptors` as well. If you are using MathML input
194197
rather than TeX (e.g., `mml-chtml.js` rather than `tex-chtml.js`),
195198
then you can remove `input/tex/extensions` as well.
196199

197-
198-
## The Component Files and Pull Requests
199-
200-
The `es5` directory is generated automatically from the contents of the
201-
MathJax source repository. You can rebuild the components using the
202-
command
200+
If you are using a font other than the default `mathjax-newcm` font in
201+
a node application, then you will need to install that font as well.
202+
E.g.,
203203

204204
``` bash
205-
npm run make-es5 --silent
205+
npm install @mathjax/mathjax-stix2-font@4
206+
```
207+
208+
to install the `mathjax-stix2` font locally. On the web, MathJax will
209+
look for the font and its dynamic ranges on the `cdn.jsdelivr.net` CDN
210+
service, so if you want to use the font from your own server, you will
211+
need to configure the path to the font. For example:
212+
213+
``` js
214+
MathJax = {
215+
loader: {
216+
paths: {
217+
'mathjax-stix2': '<url-to-your-server>/mathjax-stix2-font'
218+
}
219+
}
220+
};
206221
```
207222

208-
Note that since the contents of this repository are generated
209-
automatically, you should not submit pull requests that modify the
210-
contents of the `es5` directory. If you wish to submit a modification
211-
to MathJax, you should make a pull request in the [MathJax source
223+
to set the location for the `mathjax-stix2` font to a URL on your server.
224+
225+
226+
## The Component Files and Pull Requests
227+
228+
The contents of this repository are generated automatically, so you
229+
should not submit pull requests that modify this repository. If you
230+
wish to submit a modification to MathJax, you should make a pull
231+
request in the [MathJax source
212232
repository](https://github.com/mathjax/MathJax-src).
213233

214234
## MathJax Community

0 commit comments

Comments
 (0)