|
1 | 1 | # Development repository for MathJax v3 # |
2 | 2 |
|
3 | | -MathJax v3 is now in beta release; see the [beta branch](https://github.com/mathjax/mathjax-v3/tree/beta) for details. See the [https://github.com/mathjax/mj3-demos](https://github.com/mathjax/mj3-demos) for examples and webpacked files for the beta release. |
| 3 | +MathJax v3 is now in beta release. The `master` branch is not the beta release; it is the current development copy, set up for development testing. |
4 | 4 |
|
5 | | -The `master` branch is not the beta release. It is the current development copy, set up for development testing, as described below. |
| 5 | +The [https://github.com/mathjax/mj3-demos](https://github.com/mathjax/mj3-demos) repository includes examples and webpacked files for the beta release. See the instructions there for how to use them. |
6 | 6 |
|
7 | | ---- |
| 7 | +The [https://github.com/mathjax/mj3-demos-node](https://github.com/mathjax/mj3-demos-node) repository includes examples for how to use MathJax version 3 with NodeJS. |
8 | 8 |
|
9 | | -There are two bootstrap files for running the code: |
| 9 | +## What's Included |
10 | 10 |
|
11 | | -* `load.js` for running in node (`node load`), and |
12 | | -* `load.html` for running in a browser. |
| 11 | +This beta version includes two input processors (TeX and MathML) and one output processor (CommonHTML). Other input and output processors (e.g., AsciiMath input and SVG output) will be added in the future. |
13 | 12 |
|
14 | | -These allow you to specify a test file to run. For example, |
| 13 | +The current TeX input processor has all the core functionality of the MathJax v2 TeX input, and several of the extensions built in, but some extensions are still to come. For example, `\unicode`, `\bbox`, and the `color` extension are not yet available. |
15 | 14 |
|
16 | | - node load samples/filename.js |
| 15 | +The CommonHTML output implements all the MathML elements that v2 does, but does not yet include support for line breaking (neither automatic nor explicit ones); this will be implemented in a later beta version. Currently, there is no support for characters that are not within the MathJax TeX fonts, but that will be included in the future. |
17 | 16 |
|
18 | | -will run the file `samples/filename.js`, while entering |
| 17 | +The MathJax contextual menu is not yet implemented. |
19 | 18 |
|
20 | | - load.html?samples/filename.js |
| 19 | +The ability to configure MathJax through a configuration object, as in v2, is limited at the moment. In version 3, this type of customization is handled through building custom packed versions of MathJax, and that is not yet fully documented. |
21 | 20 |
|
22 | | -in your browser will run the same file in your browser. If you leave off the file to load, then it defaults to `main.js`. |
| 21 | +## Overview |
23 | 22 |
|
24 | | -Additional arguments get passed to the script in the `process.argv` array. For example |
| 23 | +MathJax v3 is a complete rewrite of MathJax from the ground up, using Typescript and ES6 modules, and our experience from version 2. There is still a lot to do, but a significant portion of MathJax is now available in this beta release. |
25 | 24 |
|
26 | | - node load samples/tex2html.js 'x+1' |
| 25 | +The way that MathJax operates in version 3 is significanly different from version 2. Instead of dynamically loading extensions and other pieces based on your configuration, in version 3 you load the components you need and explicitly request the actions you wish MathJax to take. |
27 | 26 |
|
28 | | -or |
| 27 | +The `samples` directory contains some examples of how this works, but most of these are for testing purposes. The files in [https://github.com/mathjax/mj3-demos](https://github.com/mathjax/mj3-demos) are a better place to look for practical examples. |
29 | 28 |
|
30 | | - load.html?samples/tex2html.js&x+1 |
| 29 | +In particular, you can use webpack or other similar tools to create a custom single-file build of the components of MathJax that you need for your situation. Some examples are included in the mj3-demos repository linked above. |
31 | 30 |
|
32 | | -would load `tex2html.js` passing it `x+1` in `process.argv[3]`. |
| 31 | +MathJax v3 is designed to work as easily in NodeJS on a server as it is in a browser. The Typescript files can be down-compiled to ES5 (the default configuration distributed here), or you can edit `tsconfig.json` file to compile to ES6, for example. |
33 | 32 |
|
34 | | -Both `load.js` and `load.html` use `System.js` to manage the loading of version 3 files. In some browsers (e.g., Firefox), you get syntax errors for the files as they load, but that seems to be some side-effect of how `System.js` works. The code is OK and runs properly anyway. |
| 33 | +## Getting Started |
35 | 34 |
|
36 | | -There is a tiny document in the `docs` directory that gives the basic structures and some sample code, but it is woefully inadequate at the moment, and may be out of date. More to come later. |
| 35 | +Check out a copy of this repository using `git` and cd into its directory: |
| 36 | + |
| 37 | + git clone https://github.com/mathjax/mathjax-v3.git mathjax-v3 |
| 38 | + cd mathjax-v3 |
| 39 | + |
| 40 | +Install the needed components using `npm`: |
| 41 | + |
| 42 | + npm install |
| 43 | + |
| 44 | +Compile the Typescript source: |
| 45 | + |
| 46 | + npx tsc |
| 47 | + |
| 48 | +This should convert the typescript files into the `mathjax3` directory, where you can include them into your own scripts. |
| 49 | + |
| 50 | +## A Sample Script |
| 51 | + |
| 52 | +Here is a sample NodeJS script that can be used to convert TeX notation to MathML. Call it `tex2mml`. |
| 53 | + |
| 54 | + // |
| 55 | + // Load the packages needed for MathJax |
| 56 | + // |
| 57 | + const TeX = require('./mathjax3/input/tex.js').TeX; |
| 58 | + const AbstractMathItem = require('./mathjax3/core/MathItem.js').AbstractMathItem; |
| 59 | + const LiteDocument = require('./mathjax3/adaptors/lite/Document.js').LiteDocument; |
| 60 | + const MmlVisitor = require('./mathjax3/core/MmlTree/SerializedMmlVisitor.js').SerializedMmlVisitor; |
| 61 | + |
| 62 | + require('./mathjax3/input/tex/base/BaseConfiguration.js'); |
| 63 | + require('./mathjax3/input/tex/ams/AmsConfiguration.js'); |
| 64 | + require('./mathjax3/input/tex/newcommand/NewcommandConfiguration.js'); |
| 65 | + require('./mathjax3/input/tex/boldsymbol/BoldsymbolConfiguration.js'); |
| 66 | + |
| 67 | + // |
| 68 | + // A generic math item |
| 69 | + // |
| 70 | + class GenericMathItem extends AbstractMathItem {}; |
| 71 | + |
| 72 | + // |
| 73 | + // Create the input jax and document |
| 74 | + // |
| 75 | + const tex = new TeX({ |
| 76 | + packages: ['base', 'ams', 'newcommand', 'boldsymbol'] |
| 77 | + }); |
| 78 | + const document = new LiteDocument(); |
| 79 | + |
| 80 | + // |
| 81 | + // Create a MathML serializer |
| 82 | + // |
| 83 | + const visitor = new MmlVisitor(); |
| 84 | + const toMathML = (node => visitor.visitTree(node, document)); |
| 85 | + |
| 86 | + // |
| 87 | + // Typeset a TeX string and return the serialized MathML |
| 88 | + // |
| 89 | + const Typeset = (string, display) => { |
| 90 | + const math = new GenericMathItem(string, tex, display); |
| 91 | + math.compile(); |
| 92 | + return toMathML(math.root); |
| 93 | + }; |
| 94 | + |
| 95 | + // |
| 96 | + // Convert the math provided by the user |
| 97 | + // |
| 98 | + console.log(Typeset(process.argv[2] || '', true)); |
| 99 | + |
| 100 | +You can run this by using |
| 101 | + |
| 102 | + node tex2mml 'x+1' |
| 103 | + |
| 104 | +See the [mj3-demos-node](https://github.com/mathjax/mj3-demos-node) repository for additional examples. |
0 commit comments