React component wrapper for Mathquill
Link to an example
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() })
}}
/>
)
}
}
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>
}
}
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
Wrapper for Mathquill MathField
- 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
Wrapper for Mathquill StaticField
- 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