Skip to content

Instantly share code, notes, and snippets.

@sjorsvanheuveln
Last active February 14, 2018 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjorsvanheuveln/59b9a94f8a10b35fd8f19912efed6acf to your computer and use it in GitHub Desktop.
Save sjorsvanheuveln/59b9a94f8a10b35fd8f19912efed6acf to your computer and use it in GitHub Desktop.
Display Math or Formulae in ReactJS using ES6.
import React from 'react';
import { Fraction, toTex } from 'algebra.js';
import { Node, Context } from 'react-mathjax';
function Formula(props) {
return (
<Context input="tex">
<Node inline>{props.tex}</Node>
</Context>
);
}
export default function FractionDisplay() {
const a = new Fraction(1, 5);
const b = new Fraction(2, 7);
const answer = a.multiply(b);
const question = <Formula tex={`${toTex(a)} × ${toTex(b)} = ${toTex(answer)}`} />;
return (
<div>
{question}
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment