|
1 | 1 | # [MathJax-demos-node](https://github.com/mathjax/MathJax-demos-node) |
2 | | -<img class="shield" alt="GitHub release version" src="https://img.shields.io/github/v/release/mathjax/MathJax-src.svg?sort=semver"> |
3 | | - |
4 | | -A repository with examples using [MathJax version 3](https://github.com/mathjax/MathJax-src) in node applications. |
5 | | - |
6 | | -See the [MathJax Web Demos](https://github.com/mathjax/MathJax-demos-web) for examples of how to use MathJax in web pages. See the [MathJax documentation](https://docs.mathjax.org/) for complete details of how to use MathJax in web browsers and node. |
| 2 | +<img class="shield" alt="GitHub release version" src="https://img.shields.io/github/v/release/mathjax/MathJax-demos-node.svg?sort=semver"> |
| 3 | + |
| 4 | +A repository with examples using [MathJax version 4](https://github.com/mathjax/MathJax-src) in node applications. |
| 5 | + |
| 6 | +See the [MathJax Web |
| 7 | +Demos](https://github.com/mathjax/MathJax-demos-web) for examples of |
| 8 | +how to use MathJax in web pages. See the [MathJax |
| 9 | +documentation](https://docs.mathjax.org/) for complete details of how |
| 10 | +to use MathJax in web browsers and node. In particular, the [Examples |
| 11 | +in Node](https://docs.mathjax.org/en/latest/server/examples.html) page |
| 12 | +contains a list of the most important examples for node applications; |
| 13 | +the [Examples in a |
| 14 | +Browser](https://docs.mathjax.org/en/latest/web/examples.html) page |
| 15 | +lists other examples that may be useful; though they target web pages, |
| 16 | +the same techniques can be employed in node. |
7 | 17 |
|
8 | 18 | ## The Example files |
9 | 19 |
|
10 | | -This repository contains examples of how to use MathJax v3 in your node projects. These are divided into three main categories: ones based on the MathJax v3 components and its loading system, ones based on the MathJax v3 components that you preload by hand (for easier synchronous use), and ones that use the base MathJax files directly without using the MathJax components. |
11 | | - |
12 | | -All three groups include examples of conversion from the various input formats to the various output formats, both for individual expressions, and for complete pages containing math. Each category includes the following executables: |
| 20 | +This repository contains a number of examples of command-line tools |
| 21 | +that exhibit the features of MathJax. The tools provide a number of |
| 22 | +command-line options, which you can discover by using the `--help` |
| 23 | +option when running them. Most of the examples include the ability to |
| 24 | +generate speech strings for the output, for example, via the |
| 25 | +`--speech` or ``--braille` options, and the language can be specified |
| 26 | +using `--sre locale de`, for example to get a German localization. |
| 27 | + |
| 28 | +The tools accept one or more mathematical expressions as their |
| 29 | +arguments, or you can use the `--file` option to specify an HTML file |
| 30 | +that will be processed in full. If you don't give a file name, then |
| 31 | +the file is taken from standard input. Similarly, if you don't give |
| 32 | +any expressions, then they are taken from standard in, with a blank |
| 33 | +line separating expressions. |
| 34 | + |
| 35 | +The tools come in two forms, one using ESM modules in the [`mjs`](mjs) |
| 36 | +directory, and one using CommonJS modules in the [`cjs`](cjs) folder, |
| 37 | +so you can see examples of both types. These directories are further |
| 38 | +subdivided into groups based on the mechanism by which MathJax is |
| 39 | +used: [`simple`](mjs/simple) uses a node-only mechanism that makes it |
| 40 | +easy to start experimenting with MathJax, but can't be used in web |
| 41 | +applications; [`component`](mjs/component) uses the MathJax Component |
| 42 | +framework to access MathJax's components via a configuration object |
| 43 | +like the one used in web browsers; [`direct`](mjs/direct) uses direct |
| 44 | +calls to the MathJax modules, without using MathJax components (so |
| 45 | +dynamic loading of TeX extensions is not supported for example); and |
| 46 | +finally, [`mixed`](mjs/mixed) combines direct calls with MathJax |
| 47 | +Components for the best of both worlds. |
| 48 | + |
| 49 | +All four groups include examples of conversion from the various input |
| 50 | +formats to the various output formats, and include the following |
| 51 | +executables: |
13 | 52 |
|
14 | 53 | * `tex2chtml` |
15 | 54 | * `tex2svg` |
16 | 55 | * `tex2mml` |
17 | 56 | * `mml2chtml` |
| 57 | +* `mml2mml` |
18 | 58 | * `mml2svg` |
19 | 59 | * `am2chtml` |
20 | 60 | * `am2mml` |
21 | | -* `tex2chtml-page` |
22 | | -* `tex2svg-page` |
23 | | -* `tex2mml-page` |
24 | | -* `mml2chtml-page` |
25 | | -* `mml2svg-page` |
26 | | -* `am2chtml-page` |
27 | | - |
28 | | -The first seven convert an expression from either a TeX, MathML, or AsciiMath string (given as its first argument) to a CommonHTML, SVG, or MathML string. The ones ending in `-page` take an HTML file and convert the math in it from the given input format to the specified output format and output the modified page. |
29 | | - |
30 | | -Use the `--help` option to get a list of all the possible options for each command. |
31 | | - |
32 | | -The three categories of commands are stored in the directories called [`component`](component), [`simple`](simple), [`preload`](preload), and [`direct`](direct). Both the `component` and `simple` directories are examples of the component-based approach, with the `component` directory containing versions that mirror the approach needed when MathJax is used in web pages, and the `simple` directory containing examples that take advantage of some simplifications available in node. Each of those directories contain additional information about the example files they contain. |
33 | | - |
34 | | -There is also a directory [`speech`](speech) that give examples of converters that add speech strings to their results, which illustrate more sophisticated operations in MathJax. This is described in more detail in that directory. |
35 | | - |
36 | | -The [`custom-tex-extension`](custom-tex-extension) directory contains an example of how to create your own custom TeX extension and load it as a component. Again, see the directory for more details. |
37 | | - |
38 | | -The [`puppeteer`](puppeteer) directory contains an example of how to use the [Puppeteer](https://developers.google.com/web/tools/puppeteer) library to use a headless Chrome instance to do server-side conversion of mathematics using MathJax. This is useful in situations where you are using characters that are not included in the main MathJax fonts, as Chrome will be able to measure the widths of these characters so that they can be displayed more reliably. |
| 61 | +* `am2svg` |
| 62 | +* `typeset` |
| 63 | + |
| 64 | +The first nine convert from the format listed before the `2` to the |
| 65 | +format listed after it, and represent all combinations of the three |
| 66 | +input formats with three output formats. The `mml2mml` example is |
| 67 | +useful for reformatting a MathML string, or for converting it to use |
| 68 | +the Mathematical Alphanumerics block of Unicode characters rather than |
| 69 | +`mathvariant` attributes with ASCII characters, as required by |
| 70 | +MathML-Core, for instance. |
| 71 | + |
| 72 | +The `typeset` tool allows you to convert from any input format to any |
| 73 | +output format, so is a "swiss army knife" example that gives you |
| 74 | +access to all the options within a common command. |
| 75 | + |
| 76 | +Use the `--help` option to get a list of all the possible options for |
| 77 | +each tool. |
| 78 | + |
| 79 | +The [`custom-tex-extension`](custom-tex-extension) directory contains |
| 80 | +an example of how to create your own custom TeX extension and load it |
| 81 | +as a component. See that directory for more details. |
| 82 | + |
| 83 | +The [`puppeteer`](puppeteer) directory contains an example of how to |
| 84 | +call the |
| 85 | +[Puppeteer](https://developers.google.com/web/tools/puppeteer) library |
| 86 | +to use a headless Chrome instance to do server-side conversion of |
| 87 | +mathematics using MathJax. This is useful in situations where you are |
| 88 | +using characters that are not included in the main MathJax fonts, or |
| 89 | +including HTML within TeX or MathML expressions, as Chrome will be |
| 90 | +able to measure the sizes of these so that they can be displayed more |
| 91 | +reliably. |
| 92 | + |
| 93 | +Finally, the [`jsdom`](jsdom) and [`linkedom`](linkedom) directories |
| 94 | +include examples of how to use those DOM libraries instead of |
| 95 | +MathJax's usual `LiteDOM` library as a replacement for the browser |
| 96 | +DOM. |
| 97 | + |
| 98 | +## The Utility Libraries |
| 99 | + |
| 100 | +The tools in the `mjs` and `cjs` directories share a lot of common |
| 101 | +code, and that shared code has been moved to separate utility files in |
| 102 | +the [`util`](mjs/util) sub-directories of those directories. There is |
| 103 | +one for each of the input and output formats (the `Mml.js` file |
| 104 | +contains the code for both input and output in MathML format), and a |
| 105 | +main `Util.js` file that holds code common to all the tools. The |
| 106 | +`Direct.js` and `Mixed.js` utilities have code specific to those |
| 107 | +mechanisms of accessing MathJax, and the `Typeset.js` file handles the |
| 108 | +special needs of the `typeset` tool. |
| 109 | + |
| 110 | +These utilities form the heart of the command-line tools, and it is in |
| 111 | +them that you will see the real details of how to work with MathJax; |
| 112 | +the individual tool files basically just load the needed libraries or |
| 113 | +MathJax modules, set up the configuration needed, and call the utility |
| 114 | +libraries to handle the details or getting the command-line arguments, |
| 115 | +setting up the needed configuration options, converting the expression |
| 116 | +or files, filtering the results according to the options given, and |
| 117 | +printing the results. |
39 | 118 |
|
40 | 119 | ## Installation |
41 | 120 |
|
42 | | -In order to try out these examples, clone this repository, enter the directory, and install the dependencies: |
| 121 | +In order to try out these examples, clone this repository, enter the |
| 122 | +directory, and install the dependencies: |
43 | 123 |
|
44 | 124 | ``` bash |
45 | 125 | git clone https://github.com/mathjax/MathJax-demos-node.git MathJax-demos-node |
46 | 126 | cd MathJax-demos-node |
47 | 127 | npm install |
48 | 128 | ``` |
49 | 129 |
|
50 | | -The examples should be executable files that you can run. On non-unix systems, you may need to call |
| 130 | +To run the tools, cd to the directory containing the tools and use |
51 | 131 |
|
52 | | -``` bash |
53 | | -node -r esm <example-name> |
| 132 | +``` |
| 133 | +node <example-name> [options] [expressions...] |
54 | 134 | ``` |
55 | 135 |
|
56 | | -where `<example-name>` is the name of the example file. Some examples take an argument (like a TeX string) that follows the `<example-name>` above. |
| 136 | +where `<example-name>` is the name of the example file, like |
| 137 | +`tex2svg`. Use the `--help` options to get more details about the |
| 138 | +options and arguments that each tool needs. |
0 commit comments