2
2
## Beautiful math in all browsers
3
3
4
4
![ 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 )
5
6
![ GitHub release version (v2)] ( https://img.shields.io/github/package-json/v/mathjax/MathJax/legacy-v2.svg?label=release-v2 )
6
7
![ 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 >
8
8
![ jsdelivr rank] ( https://flat.badgen.net/jsdelivr/rank/npm/mathjax?color=green )
9
9
![ jsDelivr hits (npm)] ( https://img.shields.io/jsdelivr/npm/hm/mathjax )
10
10
![ npm monthly downloads (full)] ( https://img.shields.io/npm/dm/mathjax?label=npm )
11
11
![ npm total downloads] ( https://img.shields.io/npm/dt/mathjax.svg?style=flat&label=npm%20total )
12
12
13
13
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.
23
24
24
25
Some of the main features of MathJax include:
25
26
@@ -40,7 +41,7 @@ and <https://docs.mathjax.org> for the MathJax documentation.
40
41
41
42
## MathJax Components
42
43
43
- MathJax version 3 uses files called * components* that contain the
44
+ MathJax uses files called * components* that contain the
44
45
various MathJax modules that you can include in your web pages or
45
46
access on a server through NodeJS. Some components combine all the
46
47
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
66
67
source repository] ( https://github.com/mathjax/MathJax-src/ ) ). These
67
68
component files are the ones served by the CDNs that offer MathJax to
68
69
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.
71
72
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.
75
74
76
75
## Installation and Use
77
76
@@ -82,42 +81,38 @@ need to install anything. Simply use a `script` tag that loads
82
81
MathJax from the CDN. E.g.,
83
82
84
83
``` 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 >
86
85
```
87
86
88
87
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.
93
92
94
93
### Hosting your own copy of the MathJax Components
95
94
96
95
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:
99
98
100
- ``` bash
101
- npm install mathjax@3
102
- mv node_modules/mathjax/es5 < path-to-server-location> /mathjax
103
99
```
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
+ ```
108
103
109
104
Alternatively, you can get the files via GitHub:
110
105
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
115
110
```
116
111
117
112
Then (in either case) you can use a script tag like the following:
118
113
119
114
``` 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 >
121
116
```
122
117
123
118
where ` <url-to-your-site> ` is replaced by the URL to the location
@@ -129,39 +124,58 @@ for details.
129
124
130
125
### Using MathJax components in a node application
131
126
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:
133
129
134
130
``` bash
135
- npm install mathjax@3
131
+ npm install mathjax@4
136
132
```
137
133
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
+ ```
140
151
141
- Then require ` mathjax ` within your application:
152
+
153
+ Alternatively, in an ES5 node application, you can use
142
154
143
155
``` js
144
- require (' mathjax' ).init ({ ... }).then ((MathJax ) => { ... });
156
+ const MathJax = require (' mathjax' );
157
+ MathJax .init ({ ... }).then (() => { ... });
145
158
```
146
159
147
160
where the first ` { ... } ` is a MathJax configuration, and the second
148
161
` { ... } ` is the code to run after MathJax has been loaded. E.g.
149
162
150
163
``` js
151
- require (' mathjax' ).init ({
164
+ const MathJax = require (' mathjax' );
165
+ MathJax .init ({
152
166
loader: {load: [' input/tex' , ' output/svg' ]}
153
- }).then ((MathJax ) => {
167
+ }).then (() => {
154
168
const svg = MathJax .tex2svg (' \\ frac{1}{x^2-1}' , {display: true });
155
169
console .log (MathJax .startup .adaptor .outerHTML (svg));
156
170
}).catch ((err ) => console .log (err .message ));
157
171
```
158
172
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 .
165
179
166
180
See the
167
181
[ 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.
170
184
171
185
## Reducing the Size of the Components Directory
172
186
173
- Since the ` es5 ` directory contains * all* the component files, so if
187
+ Since the MathJax package contains * all* the component files, so if
174
188
you are only planning one use one configuration, you can reduce the
175
189
size of the MathJax directory by removing unused components. For
176
190
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
194
197
rather than TeX (e.g., ` mml-chtml.js ` rather than ` tex-chtml.js ` ),
195
198
then you can remove ` input/tex/extensions ` as well.
196
199
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.,
203
203
204
204
``` 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
+ };
206
221
```
207
222
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
212
232
repository] ( https://github.com/mathjax/MathJax-src ) .
213
233
214
234
## MathJax Community
0 commit comments