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
|
9 | Install `react-mathjax-preview` as a dependency:
|
10 |
|
11 | ```
|
12 | npm install react-mathjax-preview
|
13 | ```
|
14 |
|
15 | ## Usage
|
16 | Import 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
|
19 | import React, {Component} from 'react'
|
20 | import {render} from 'react-dom'
|
21 | import MathJax from 'react-mathjax-preview'
|
22 |
|
23 | const asciimath = '`sum_(i=1)^n i^3=((n(n+1))/2)^2`' # Because of the backtick
|
24 | const 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 |
|
35 | class 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 |
|
47 | See [demo](./demo/src/index.js) for a complete example. You can also play with the demo:
|
48 |
|
49 | ```
|
50 | git clone https://github.com/mehdisadeghi/react-mathjax-preview && cd react-mathjax-preview
|
51 | npm install
|
52 | npm run start
|
53 | ```
|
54 |
|
55 | And browse to [localhost:3000](http://localhost:3000).
|
56 |
|
57 | # License
|
58 | MIT
|
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
|