ShaMan123 / react-native-math-view

Math view for react native! No WebView!
https://github.com/ShaMan123/react-native-math-view
MIT License
77 stars 24 forks source link

Support for MathML input #53

Closed hypnocill closed 2 years ago

hypnocill commented 2 years ago

Is it possible to use MathML html as input instead of Latex?

I tried converting Ckeditor exported MathML to Latex with tool such as 'mathml-to-latex' package but in some scenarios the produced Latex is flawed so I can't reliably use it.

I need to render MathML html in react-native without webview. Is there a way to do it with this package?

I'd be so grateful if it's somehow possible in a reliable way. Thank you!

ShaMan123 commented 2 years ago

Sure. Mathjax supports it out of the box. You need to set up a mml input jax instead of the tex input jax. Follow the lead: https://github.com/ShaMan123/react-native-math-view/blob/master/src/mathjax/MathjaxAdaptor.ts#L151

ShaMan123 commented 2 years ago

mathjax mml source code: https://github.com/mathjax/MathJax-src/blob/41565a97529c8de57cb170e6a67baf311e61de13/ts/input/mathml.ts#L43

import as follows:

import {MathML} from 'mathjax-full/js/input/mathml'

Try to replace the TeX constructor with MathML and see how it works.

hypnocill commented 2 years ago

I just tried that - simply replacing the Tex constructor with MathML resulted in 'MathJax: Invalid option "formatError" ...'. I had to comment out const isError = doc.inputJax[0].parseOptions.error; and the error check below it in MathjaxAdaptor After that - my MathML input was rendered properly, it seems. And it's fantastic! But is it safe to use it like that?

hypnocill commented 2 years ago

And, with MathML constructor, I have to pass it pure mathml (no HTML). Is there a way to pass it html + mathml similar to 'react-native-mathjax'?

Thank you very much for your responses

ShaMan123 commented 2 years ago

It is as safe as the rest of this repo. I am sure formatError field has an equivalent in MathML factory, this is for UX mainly, so the user/dev can see and handle a parsing error if existing. You are more than welcome to PR and or post your effort here. Regarding your second question I have no idea. It is mathjax internals, a guessing game unfortunately. I suggest you look at the html input jax and if I were you I would sniff around 'react-native-mathjax' to see how they've implemented what you want.

hypnocill commented 2 years ago

I didn't find a proper way to use html that contains mathml as input. I tried extracting mathml from html which sort of works but not satisfactory. I'll keep looking. Another issue I found was that mathml new lines are not rendered. It seems to be a problem of mathjax v3+.

Anyway, thank you so much for your responses. They were very helpful and I appreciate them. Marking this as closed