1.0.5 • Published 12 months ago

react-mathquill-extenstion v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

React component wrapper for Mathquill

npm version

Examples

Link to an example

Editable Math Field

import React from 'react'
import { addStyles, EditableMathField } from 'react-mathquill'

// inserts the required css to the <head> block.
// you can skip this, if you want to do that by yourself.
addStyles()

export default class App extends React.Component {
  constructor(props) {
    super(props)

    this.state = {
      latex: '\\frac{1}{\\sqrt{2}}\\cdot 2',
    }
  }

  render() {
    return (
      <EditableMathField
        latex={this.state.latex} // latex value for the input field
        onChange={(mathField) => {
          // called everytime the input changes
          this.setState({ latex: mathField.latex() })
        }}
      />
    )
  }
}

Static Math Field

import React from 'react'
import { addStyles, StaticMathField } from 'react-mathquill'

// inserts the required css to the <head> block.
// you can skip this, if you want to do that by yourself.
addStyles()

export default class App extends React.Component {
  constructor(props) {
    super(props)

    this.state = {
      latex: '\\frac{1}{\\sqrt{2}}\\cdot 2',
    }
  }

  render() {
    return <StaticMathField>{this.state.latex}</StaticMathField>
  }
}

Documentation

addStyles (function)

This function, when called, will append a <style id="react-mathquill-styles"> tag to the <head> of the document. The style tag includes all the required styles for Mathquill to work.

This function is not necessary, provided you include the styles in another way. See Mathquill Docs - Download and Load

EditableMathField (React Element)

Wrapper for Mathquill MathField

Props

  • latex: String - Initial latex value for the input field
  • config: Object - A mathquill config object
  • onChange(mathField) - A function that is called on change events.
  • mathquillDidMount(mathField) - A function that is called when the Mathquill element is initalized.

Other props will be passed to the wrapping element, this can be useful for custom classNames or styles

StaticMathField (React Element)

Wrapper for Mathquill StaticField

Props

  • children: String - A string of latex to render statically on the page

Other props will be passed to the wrapping element, this can be useful for custom classNames or styles

1.0.2

12 months ago

1.0.1

12 months ago

1.0.5

12 months ago

1.0.0

1 year ago