# MathJax-node
**Repository Path**: ma_chundi/MathJax-node
## Basic Information
- **Project Name**: MathJax-node
- **Description**: 公式转换
- **Primary Language**: NodeJS
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2024-06-13
- **Last Updated**: 2024-06-13
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# mathjax-node [](https://travis-ci.org/mathjax/MathJax-node)
This repository contains a library that provides an API to call [MathJax](https://github.com/mathjax/mathjax) from Node.js programs. The API converts individual math expressions (in any of MathJax's input formats) into HTML (with CSS), SVG, or MathML code.
Use
```
npm install mathjax-node
```
to install mathjax-node and its dependencies.
**Note:**
The current version of mathjax-node requires Node.js v6 or later, and uses jsdom version 11.
## Getting started
mathjax-node provides a library, `./lib/main.js`. Below is a very minimal example for using it - the tests and the examples mentioned above provide more advanced examples.
```javascript
// a simple TeX-input example
var mjAPI = require("mathjax-node");
mjAPI.config({
MathJax: {
// traditional MathJax configuration
}
});
mjAPI.start();
var yourMath = 'E = mc^2';
mjAPI.typeset({
math: yourMath,
format: "TeX", // or "inline-TeX", "MathML"
mml:true, // or svg:true, or html:true
}, function (data) {
if (!data.errors) {console.log(data.mml)}
// will produce:
//
});
```
## Documentation
mathjax-node exports three methods, `config`, `start`, `typeset`.
### `config(options)`
The `config` method is used to set _global_ configuration options. Its default options are
```javascript
{
displayMessages: false, // determines whether Message.Set() calls are logged
displayErrors: true, // determines whether error messages are shown on the console
undefinedCharError: false, // determines whether "unknown characters" (i.e., no glyph in the configured fonts) are saved in the error array
extensions: '', // a convenience option to add MathJax extensions
fontURL: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/fonts/HTML-CSS', // for webfont urls in the CSS for HTML output
paths: {}, // configures custom path variables (e.g., for third party extensions, cf. test/config-third-party-extensions.js)
MathJax: { } // standard MathJax configuration options, see https://docs.mathjax.org for more detail.
}
```
**Note.** Changes to these options require a restart of the API using the `start()` method (see below).
### `start()`
The `start` method start (and restarts) mathjax-node. This allows reconfiguration.
**Note.** This is done automatically when `typeset` is first called (see below).
### `typeset(options[, callback])`
The `typeset` method is the main method of mathjax-node. It expects a configuration object `options` and optionally a callback.
If no `callback` is passed, it will return a Promise.
Once called, `typeset` can be called repeatedly and will optionally store information across calls (see `state` below).
The following are the default input options.
```javascript
{
ex: 6, // ex-size in pixels
width: 100, // width of container (in ex) for linebreaking and tags
useFontCache: true, // use and