UNPKG

1.99 kBMarkdownView Raw
1# react-mathjax-preview
2
3[![Travis][build-badge]][build]
4[![npm package][npm-badge]][npm]
5
6`react-mathjax-preview` provides one React component to render MathML, TeX or ASCIImath formulas. See [demo](http://mehdisadeghi.github.io/react-mathjax-preview/demo/dist/index.html).
7
8## Installation
9Install `react-mathjax-preview` as a dependency:
10
11```
12npm install react-mathjax-preview
13```
14
15## Usage
16Import the package and fill the `math` property with some text containing your formals. Wrap TeX in `$` or `$$` and ASCIImath in \`. Paste MathML as is.
17
18```js
19import React, {Component} from 'react'
20import {render} from 'react-dom'
21import MathJax from 'react-mathjax-preview'
22
23const asciimath = '`sum_(i=1)^n i^3=((n(n+1))/2)^2`' # Because of the backtick
24const math = String.raw`
25 <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
26 <menclose notation="circle box">
27 <mi> x </mi><mo> + </mo><mi> y </mi>
28 </menclose>
29 </math>
30
31 $$\lim_{x \to \infty} \exp(-x) = 0$$
32
33 ${asciimath}`
34
35class Demo extends Component {
36 constructor(props) {
37 super(props);
38 this.state = {
39 math: tex
40 }
41 render() {
42 return <MathJax math={this.state.math} />
43 }
44}
45```
46
47See [demo](./demo/src/index.js) for a complete example. You can also play with the demo:
48
49```
50git clone https://github.com/mehdisadeghi/react-mathjax-preview && cd react-mathjax-preview
51npm install
52npm run start
53```
54
55And browse to [localhost:3000](http://localhost:3000).
56
57# License
58MIT
59
60[build-badge]: https://img.shields.io/travis/mehdisadeghi/react-mathjax-preview/master.png?style=flat-square
61[build]: https://travis-ci.org/mehdisadeghi/react-mathjax-preview
62
63[npm-badge]: https://img.shields.io/npm/v/react-mathjax-preview.png?style=flat-square
64[npm]: https://www.npmjs.org/package/react-mathjax-preview
65
66[coveralls-badge]: https://img.shields.io/coveralls/mehdisadeghi/react-mathjax-preview/master.png?style=flat-square
67[coveralls]: https://coveralls.io/github/mehdisadeghi/react-mathjax-preview