Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate with jsx MathML #6

Closed
ryanehlers opened this issue Feb 13, 2018 · 2 comments
Closed

Integrate with jsx MathML #6

ryanehlers opened this issue Feb 13, 2018 · 2 comments

Comments

@ryanehlers
Copy link

In React it's possible to return MathML from a jsx function like:

import React from 'react';

function oneThird() {
  return (
    <math>
      <mfrac>
        <mn>1</mn>
        <mn>3</mn>
      </mfrac>
    </math>
  );
}

Is it possible to integrate this with the <MathJax /> component?

My current work-around is to convert the MathML to a string with ReactDOMServer.renderToString():

render() {
  <MathJax math={ReactDOMServer.renderToString(oneThird())} />;
}
@mehdisadeghi
Copy link
Owner

@ryanehlers if you put raw MathML inside a react component, react will render it, however for MathJax to function properly we need to pass String to the underlying MathJax library.

I thought perhaps one could do something like this:

<MathJax>
    <math>
      <mfrac>
        <mn>1</mn>
        <mn>3</mn>
      </mfrac>
    </math>
<MathJax>

For this to work we need to extract children as string. With a quick search I found jsx-to-string but I was unable to extract the MathML.

If you can fix it, send me a PR. I'd be happy to merge it!

@mehdisadeghi
Copy link
Owner

I'll close this as a wontfix since the component (and MathJax) needs a string for typesetting. Moreover, your workaround looks perfectly fine to me. There is also Algolia's react-element-to-jsx-string which might be interesting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants