Git Product home page Git Product logo

mathjax-node-cli's Introduction

MathJax

Beautiful math in all browsers

GitHub release version GitHub release version (v2) NPM version powered by NumFOCUS
jsdelivr rank jsDelivr hits (npm) npm monthly downloads (full) npm total downloads

MathJax is an open-source JavaScript display engine for LaTeX, MathML, and AsciiMath notation that works in all modern browsers. It was designed with the goal of consolidating the recent advances in web technologies into a single, definitive, math-on-the-web platform supporting the major browsers and operating systems. It requires no setup on the part of the user (no plugins to download or software to install), so the page author can write web documents that include mathematics and be confident that users will be able to view it naturally and easily. Simply include MathJax and some mathematics in a web page, and MathJax does the rest.

Some of the main features of MathJax include:

  • High-quality display of LaTeX, MathML, and AsciiMath notation in HTML pages

  • Supported in most browsers with no plug-ins, extra fonts, or special setup for the reader

  • Easy for authors, flexible for publishers, extensible for developers

  • Supports math accessibility, cut-and-paste interoperability, and other advanced functionality

  • Powerful API for integration with other web applications

See http://www.mathjax.org/ for additional details about MathJax, and https://docs.mathjax.org for the MathJax documentation.

MathJax Components

MathJax version 3 uses files called components that contain the various MathJax modules that you can include in your web pages or access on a server through NodeJS. Some components combine all the pieces you need to run MathJax with one or more input formats and a particular output format, while other components are pieces that can be loaded on demand when needed, or by a configuration that specifies the pieces you want to combine in a custom way. For usage instructions, see the MathJax documentation.

Components provide a convenient packaging of MathJax's modules, but it is possible for you to form your own custom components, or to use MathJax's modules directly in a node application on a server. There are web examples showing how to use MathJax in web pages and how to build your own components, and node examples illustrating how to use components in node applications or call MathJax modules directly.

What's in this Repository

This repository contains only the component files for MathJax, not the source code for MathJax (which are available in a separate MathJax source repository). These component files are the ones served by the CDNs that offer MathJax to the web. In version 2, the files used on the web were also the source files for MathJax, but in version 3, the source files are no longer on the CDN, as they are not what are run in the browser.

The components are stored in the es5 directory, and are in ES5 format for the widest possible compatibility. In the future, we may make an es6 directory containing ES6 versions of the components.

Installation and Use

Using MathJax components from a CDN on the web

If you are loading MathJax from a CDN into a web page, there is no need to install anything. Simply use a script tag that loads MathJax from the CDN. E.g.,

<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

See the MathJax documentation, the MathJax Web Demos, and the MathJax Component Repository for more information.

Hosting your own copy of the MathJax Components

If you want to host MathJax from your own server, you can do so by installing the mathjax package using npm and moving the es5 directory to an appropriate location on your server:

npm install mathjax@3
mv node_modules/mathjax/es5 <path-to-server-location>/mathjax

Note that we are still making updates to version 2, so include @3 when you install, since the latest chronological version may not be version 3.

Alternatively, you can get the files via GitHub:

git clone https://github.com/mathjax/MathJax.git mj-tmp
mv mj-tmp/es5 <path-to-server-location>/mathjax
rm -rf mj-tmp

Then (in either case) you can use a script tag like the following:

<script id="MathJax-script" async src="<url-to-your-site>/mathjax/tex-chtml.js"></script>

where <url-to-your-site> is replaced by the URL to the location where you moved the MathJax files above.

See the documentation for details.

Using MathJax components in a node application

To use MathJax components in a node application, install the mathjax package:

npm install mathjax@3

(we are still making updates to version 2, so you should include @3 since the latest chronological version may not be version 3).

Then require mathjax within your application:

require('mathjax').init({ ... }).then((MathJax) => { ... });

where the first { ... } is a MathJax configuration, and the second { ... } is the code to run after MathJax has been loaded. E.g.

require('mathjax').init({
  loader: {load: ['input/tex', 'output/svg']}
}).then((MathJax) => {
  const svg = MathJax.tex2svg('\\frac{1}{x^2-1}', {display: true});
  console.log(MathJax.startup.adaptor.outerHTML(svg));
}).catch((err) => console.log(err.message));

Note: this technique is for node-based application only, not for browser applications. This method sets up an alternative DOM implementation, which you don't need in the browser, and tells MathJax to use node's require() command to load external modules. This setup will not work properly in the browser, even if you webpack it or bundle it in other ways.

See the documentation and the MathJax Node Repository for more details.

Reducing the Size of the Components Directory

Since the es5 directory contains all the component files, so if you are only planning one use one configuration, you can reduce the size of the MathJax directory by removing unused components. For example, if you are using the tex-chtml.js component, then you can remove the tex-mml-chtml.js, tex-svg.js, tex-mml-svg.js, tex-chtml-full.js, and tex-svg-full.js configurations, which will save considerable space. Indeed, you should be able to remove everything other than tex-chtml.js, and the input/tex/extensions, output/chtml/fonts/woff-v2, adaptors, a11y, and sre directories. If you are using the results only on the web, you can remove adaptors as well.

If you are not using A11Y support (e.g., speech generation, or semantic enrichment), then you can remove a11y and sre as well (though in this case you may need to disable the assistive tools in the MathJax contextual menu in order to avoid MathJax trying to load them when they aren't there).

If you are using SVG rather than CommonHTML output (e.g., tex-svg.js rather than tex-chtml.js), you can remove the output/chtml/fonts/woff-v2 directory. If you are using MathML input rather than TeX (e.g., mml-chtml.js rather than tex-chtml.js), then you can remove input/tex/extensions as well.

The Component Files and Pull Requests

The es5 directory is generated automatically from the contents of the MathJax source repository. You can rebuild the components using the command

npm run make-es5 --silent

Note that since the contents of this repository are generated automatically, you should not submit pull requests that modify the contents of the es5 directory. If you wish to submit a modification to MathJax, you should make a pull request in the MathJax source repository.

MathJax Community

The main MathJax website is http://www.mathjax.org, and it includes announcements and other important information. A MathJax user forum for asking questions and getting assistance is hosted at Google, and the MathJax bug tracker is hosted at GitHub.

Before reporting a bug, please check that it has not already been reported. Also, please use the bug tracker (rather than the help forum) for reporting bugs, and use the user's forum (rather than the bug tracker) for questions about how to use MathJax.

MathJax Resources

mathjax-node-cli's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mathjax-node-cli's Issues

tex2svg: Remove non-unique title ID

I have been using tex2svg provided by mathjax-node for years to render multiple SVG formulae for use in a single XHTML document. Recently, I was forced to move to tex2svg provided by mathjax-node-cli.

What has changed now, is the inclusion of a title ID as in:
<title id="MathJax-SVG-1-Title">upper E equals m c squared</title>

As the "MathJax-SVG-1-Title" title ID is the same for every converted formula, the XHTML document becomes invalid because of several non-unique IDs.

Has this generic title ID any use? If not, remove it.
If on the other hand a title ID is somehow required, then render it unique by concatenating it with a millisecond level Unix time serialization. Using the actual title for serialization is not sufficient because the same formula may appear more than once in a single XHTML document.

missing package-lock.json

would you consider committing the package-lock.json file to the repo? npm docs suggest to do this and it eases the burden for downstream consumers by publishing a known-good dependency configuration.

i understand this project is considered "legacy" at this point, but in a way that makes having a lockfile even more useful since breakages caused by new dependency releases are more liable to go unnoticed here.

Question: Can I use mathjaxcli to convert html -> html

Hello,

Not an issue, just a question.
MathJax is awesome very good work.
This CLI is what I was looking for. I want a one file standalone html output.

I love the output of the CLI. But the input seems to be a well formatted string ML.
I wonder how I can dirtily give all my html in input, maybe making a script in my Makefile to exctract the $texts$. I don't even know how MathJax.js is doing it.

I am a pure nooby in JS, really not comfortable but I like to use your tool because it is a one liner to get all LaTeX power.
Thanks for the great job and feel free to close at anytime.

Error to parse when the latex formula starts with -

Hello,
Using [email protected], I'm trying to transform the following LaTeX formula: -519^\circ + 360^\circ = -159^\circ to svg using tex2svg.

tex2svg --inline --extensions='TeX/cancel,TeX/AMSmath,TeX/AMSsymbols' '-519^\circ + 360^\circ = -159^\circ'

Shell returns the following message (translated from spanish):

Non-optional arguments are needed: Number received 0, need at least 1

The same formula without the first - works.

Using [email protected] (if my issue has been resolved) then any formula (well, any tex2svg execution) throws the following error:

/usr/local/lib/node_modules/mathjax-node-cli/node_modules/jsdom/lib/api.js:10
const { URL } = require("whatwg-url");
SyntaxError: Unexpected token {

Could someone give me some tip about this?
Thanks in advance,
Israel

Issue mml3 extension not working even though it is loaded correctly

I am trying to execute the following:
./bin/mml2svg "<m:math><m:mstack><m:mn>101</m:mn><m:msrow><m:mo>-</m:mo><m:mn>63</m:mn></m:msrow><m:msline/></m:mstack></m:math>" --extensions "TeX/noErrors,TeX/noUndefined,MathML/mml3"

I have done a little bit of debugging and I've been able to determine the extension did load by setting messages to print:

Loading [MathJax]/jax/input/TeX/config.js
Loading [MathJax]/jax/input/MathML/config.js
Loading [MathJax]/jax/input/AsciiMath/config.js
Loading [MathJax]/jax/output/SVG/config.js
Loading [MathJax]/jax/output/CommonHTML/config.js
Loading [MathJax]/extensions/toMathML.js
Loading [MathJax]/extensions/TeX/noErrors.js
Loading [MathJax]/extensions/TeX/noUndefined.js
Loading [MathJax]/extensions/MathML/mml3.js
Loading [MathJax]/jax/element/mml/jax.js
Loading [MathJax]/jax/input/TeX/jax.js
Loading [MathJax]/jax/output/SVG/jax.js
Loading [MathJax]/extensions/TeX/AMSmath.js
Loading [MathJax]/extensions/TeX/AMSsymbols.js
Loading [MathJax]/extensions/TeX/autoload-all.js
Loading [MathJax]/jax/output/SVG/fonts/TeX/fontdata.js
Loading [MathJax]/jax/input/AsciiMath/jax.js
Loading [MathJax]/jax/input/MathML/jax.js
MathML - Unknown node type: mstack

I've tested the exact same MathML using a simple example.html and it rendered to svg using MathJax.js?config=TeX-MML-AM_SVG so I know everything is valid.

publish to NPM [was: Unable to install with npm install -g mathjax-node-cli]

$ npm install -g mathjax-node-cli
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/Cellar/node/7.9.0/bin/node" "/usr/local/bin/npm" "install" "-g" "mathjax-node-cli"
npm ERR! node v7.9.0
npm ERR! npm  v4.2.0

npm ERR! Cannot read property 'path' of null
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/greedo/.npm/_logs/2017-04-19T11_34_12_526Z-debug.log

When inspecting the debug log, I see https://registry.npmjs.org/mathjax-node-cli returns a 404 error

Fix tests

The test does not pass on Node < 6.

Error using golang exec.Command in linux system

I made a bot using golang and wanted it to run on a Linux server, but when I deployed it, there were some errors.

  • Environment
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 5.4.51-v8+ #1333 SMP PREEMPT Mon Aug 10 16:58:35 BST 2020 aarch64 GNU/Linux
  • Test Code
package main

import (
	"os"
	"fmt"
	"log"
	"os/exec"
)

func main() {
	svgPath := "/home/pi/bot/Test/test.svg"
	cmd := exec.Command("/home/pi/node_modules/bin/tex2svg", "e^x", ">", svgPath)
	out, err := cmd.Output()
	if err != nil {
		log.Println(err)
	} else {
		log.Println(string(out))
	}
}
  • Details
    The above code should have generated a test.svg file in the Test folder, but in fact, it did not do so, but returned the svg code to the out variable, as follows:
<svg xmlns:xlink="http://www.w3.org/1999/xlink" width="2.256ex" height="2.343ex" style="vertical-align: -0.338ex;" viewBox="0 -863.1 971.3 1008.6" role="img" focusable="false" xmlns="http://www.w3.org/2000/svg" aria-labelledby="MathJax-SVG-1-Title">
<title id="MathJax-SVG-1-Title">e Superscript x</title>
<defs aria-hidden="true">
<path stroke-width="1" id="E1-MJMATHI-65" d="M39 168Q39 225 58 272T107 350T174 402T244 433T307 442H310Q355 442 388 420T421 355Q421 265 310 237Q261 224 176 223Q139 223 138 221Q138 219 132 186T125 128Q125 81 146 54T209 26T302 45T394 111Q403 121 406 121Q410 121 419 112T429 98T420 82T390 55T344 24T281 -1T205 -11Q126 -11 83 42T39 168ZM373 353Q367 405 305 405Q272 405 244 391T199 357T170 316T154 280T149 261Q149 260 169 260Q282 260 327 284T373 353Z"></path>
<path stroke-width="1" id="E1-MJMATHI-78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path>
</defs>
<g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)" aria-hidden="true">
 <use xlink:href="#E1-MJMATHI-65" x="0" y="0"></use>
 <use transform="scale(0.707)" xlink:href="#E1-MJMATHI-78" x="659" y="583"></use>
</g>
</svg>

I don’t know what’s going on in this, can you fix this

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.