{"id":13526957,"url":"https://github.com/mathjax/MathJax-node","last_synced_at":"2025-04-01T09:30:54.544Z","repository":{"id":8947088,"uuid":"10682579","full_name":"mathjax/MathJax-node","owner":"mathjax","description":"MathJax for Node","archived":false,"fork":false,"pushed_at":"2022-12-07T17:35:08.000Z","size":534,"stargazers_count":620,"open_issues_count":30,"forks_count":100,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-03-28T21:39:53.157Z","etag":null,"topics":["javascript","mathjax","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathjax.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-14T05:38:07.000Z","updated_at":"2025-03-28T16:52:01.000Z","dependencies_parsed_at":"2023-01-13T15:15:22.056Z","dependency_job_id":null,"html_url":"https://github.com/mathjax/MathJax-node","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathjax%2FMathJax-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathjax%2FMathJax-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathjax%2FMathJax-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathjax%2FMathJax-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathjax","download_url":"https://codeload.github.com/mathjax/MathJax-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246506132,"owners_count":20788595,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","mathjax","nodejs"],"created_at":"2024-08-01T06:01:38.348Z","updated_at":"2025-04-01T09:30:54.508Z","avatar_url":"https://github.com/mathjax.png","language":"JavaScript","readme":"# mathjax-node [![Build Status](https://travis-ci.org/mathjax/MathJax-node.svg?branch=develop)](https://travis-ci.org/mathjax/MathJax-node)\n\nThis 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.\n\nUse\n\n```\nnpm install mathjax-node\n```\n\nto install mathjax-node and its dependencies.\n\n**Note:**\nThe current version of mathjax-node requires Node.js v6 or later, and uses jsdom version 11.\n\n## Getting started\n\nmathjax-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.\n\n```javascript\n// a simple TeX-input example\nvar mjAPI = require(\"mathjax-node\");\nmjAPI.config({\n  MathJax: {\n    // traditional MathJax configuration\n  }\n});\nmjAPI.start();\n\nvar yourMath = 'E = mc^2';\n\nmjAPI.typeset({\n  math: yourMath,\n  format: \"TeX\", // or \"inline-TeX\", \"MathML\"\n  mml:true,      // or svg:true, or html:true\n}, function (data) {\n  if (!data.errors) {console.log(data.mml)}\n  // will produce:\n  // \u003cmath xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"\u003e\n  //   \u003cmi\u003eE\u003c/mi\u003e\n  //   \u003cmo\u003e=\u003c/mo\u003e\n  //   \u003cmi\u003em\u003c/mi\u003e\n  //   \u003cmsup\u003e\n  //     \u003cmi\u003ec\u003c/mi\u003e\n  //     \u003cmn\u003e2\u003c/mn\u003e\n  //   \u003c/msup\u003e\n  // \u003c/math\u003e\n});\n```\n\n## Documentation\n\nmathjax-node exports three methods, `config`, `start`, `typeset`.\n\n### `config(options)`\n\nThe `config` method is used to set _global_ configuration options. Its default options are\n\n```javascript\n{\n  displayMessages: false,    // determines whether Message.Set() calls are logged\n  displayErrors:   true,     // determines whether error messages are shown on the console\n  undefinedCharError: false, // determines whether \"unknown characters\" (i.e., no glyph in the configured fonts) are saved in the error array\n  extensions: '',            // a convenience option to add MathJax extensions\n  fontURL: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/fonts/HTML-CSS', // for webfont urls in the CSS for HTML output\n  paths: {},                  // configures custom path variables (e.g., for third party extensions, cf. test/config-third-party-extensions.js)\n  MathJax: { }               // standard MathJax configuration options, see https://docs.mathjax.org for more detail.\n}\n```\n\n**Note.** Changes to these options require a restart of the API using the `start()` method (see below).\n\n### `start()`\n\nThe `start` method start (and restarts) mathjax-node. This allows reconfiguration.\n\n**Note.** This is done automatically when `typeset` is first called (see below).\n\n### `typeset(options[, callback])`\n\nThe `typeset` method is the main method of mathjax-node. It expects a configuration object `options` and optionally a callback.\n\nIf no `callback` is passed, it will return a Promise.\n\nOnce called, `typeset` can be called repeatedly and will optionally store information across calls (see `state` below).\n\nThe following are the default input options.\n\n```javascript\n{\n  ex: 6,                          // ex-size in pixels\n  width: 100,                     // width of container (in ex) for linebreaking and tags\n  useFontCache: true,             // use \u003cdefs\u003e and \u003cuse\u003e in svg output?\n  useGlobalCache: false,          // use common \u003cdefs\u003e for all equations?\n  linebreaks: false,              // automatic linebreaking\n  equationNumbers: \"none\",        // automatic equation numbering (\"none\", \"AMS\" or \"all\")\n  cjkCharWidth: 13,               // width of CJK character\n\n  math: \"\",                       // the math string to typeset\n  format: \"TeX\",                  // the input format (TeX, inline-TeX, AsciiMath, or MathML)\n  xmlns: \"mml\",                   // the namespace to use for MathML\n\n  html: false,                    // generate HTML output\n  htmlNode: false,                // generate HTML output as jsdom node\n  css: false,                     // generate CSS for HTML output\n  mml: false,                     // generate MathML output\n  mmlNode: false,                 // generate MathML output as jsdom node\n  svg: false,                     // generate SVG output\n  svgNode: false,                 // generate SVG output as jsdom node\n\n  speakText: true,                // add textual alternative (for TeX/asciimath the input string, for MathML a dummy string)\n\n  state: {},                      // an object to store information from multiple calls (e.g., \u003cdefs\u003e if useGlobalCache, counter for equation numbering if equationNumbers ar )\n  timeout: 10 * 1000,             // 10 second timeout before restarting MathJax\n}\n```\n\n### `Promise.resolve(result,options)` / `Promise.reject(errors)` / `callback(result, options)`\n\nmathjax-node returns two objects to `Promise.resolve` or `callback`: a `result` object and the original input `options`.\n\nThe `result` object will contain (at most) the following structure:\n\n```javascript\n{\n  errors:                     // an array of MathJax error messages if any errors occurred\n  mml:                        // a string of MathML markup if requested\n  mmlNode:                    // a jsdom node of MathML markup if requested\n  html:                       // a string of HTML markup if requested\n  htmlNode:                   // a jsdom node of HTML markup if requested\n  css:                        // a string of CSS if HTML was requested\n  svg:                        // a string of SVG markup if requested\n  svgNode:                    // a jsdom node of SVG markup if requested\n  style:                      // a string of CSS inline style if SVG requested\n  height:                     // a string containing the height of the SVG output if SVG was requested\n  width:                      // a string containing the width of the SVG output if SVG was requested\n  speakText:                  // a string of speech text if requested\n\n  state: {                    // the state object (if useGlobalCache or equationNumbers is set)\n           glyphs:            // a collection of glyph data\n           defs :             // a string containing SVG def elements\n           AMS: {\n                startNumber:  // the current starting equation number\n                labels:       // the set of labels\n                IDs:          // IDs used in previous equations\n             }\n         }\n}\n```\n\nIf the `errors` array is non-empty, the Promise will reject, and be passed the `errors` array.\n\nThe `options` contains the configuration object passed to `typeset`; this can be useful for passing other data along or for identifying which `typeset()` call is associated with this (`callback`) call (in case you use the same `callback` function for more than one `typeset()`).\n\n## Change History\n\n### Breaking Changes in v2.0:\n\nmathjax-node v2.0 makes breaking changes as follows:\n\n- [CHANGED] mathjax-node now requires version 6 of Node.js (the minimum used to be Node.js version 4).\n- [CHANGED] mathjax-node now uses version 10 of jsdom.  Since the jsdom API changed from 9 to 10, that means if you used jsdom in your code that calls mathjax-node, you may need to update how you call jsdom.\n\n\n### Breaking Changes in v1.0:\n\nmathjax-node v1.0 makes breaking changes to the following features from the pre-releases.\n\n- [CHANGED] `lib/mj-single.js` has been renamed to `lib/main.js` (and set as `main` in `package.json`, i.e., `require('mathjax-node')` will load it.\n- [REMOVED] `lib/mj-page.js` (API for processing HTML-fragments) and related CLI tools\n- [REMOVED] speech-rule-engine integration\n- [REMOVED] PNG generation\n- [REMOVED] CLI tools in `bin/`\n\nThese features can easily be recreated in separate modules for greater flexibility. For examples, see\n\n- [mathjax-node-cli](https://github.com/mathjax/mathjax-node-cli/)\n- [mathjax-node-page](https://github.com/pkra/mathjax-node-page/)\n- [mathjax-node-sre](https://github.com/pkra/mathjax-node-sre)\n- [mathjax-node-svg2png](https://github.com/pkra/mathjax-node-svg2png)\n\n---\n\nBe sure to also check out other [projects on NPM that depend on mathjax-node](https://www.npmjs.com/browse/depended/mathjax-node).\n\n","funding_links":[],"categories":["Repository","JavaScript"],"sub_categories":["Parsing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathjax%2FMathJax-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathjax%2FMathJax-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathjax%2FMathJax-node/lists"}