ShaMan123 / react-native-math-view

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

Some LaTeX symbols not rendering #56

Closed hypnocill closed 3 years ago

hypnocill commented 3 years ago

I'm using MathView to render LaTeX exported from https://cortexjs.io/mathlive/demo/. It works well for the most part but some symbols are not rendering (see screenshot). They appear in the same way in the www.mathjax.org/#demo - red, without proper rendering. Example troublesome latex would be: \exponentialE\imaginaryI\pi - it renders well in cortexjs but doesn't in react-native-math-view

Is there a way to render those symbols properly? Or to add them to the library myself and instruct the library how to render them, if needed?

Also, a latex with coloring exported from cortejx like so: \colorbox{#fff1c2}{[ \textcolor{#63b215}{x+42\operatorname{sign}(\placeholder{⬚})} ]} It results in an error - '[' is only supported in math mode. If I wrap the whole latex with '$' for math mode - it results in another error - '#' macro is not supported in math mode.

Currently I do: replaceAll(String.raw\[, '$') and for the other symbols that don't render like \exponentialE -> e before passing the latex to the mathview which works but seems like a bad workaround.

In conclusion - is there a good way to safely and reliably render the output from https://cortexjs.io/mathlive/demo/ in react-native-math-view without using workarounds like find and replace?

Screenshot 2021-09-24 at 12 03 59 .

ShaMan123 commented 3 years ago

Hi, you should define macros so mathjax knows what to do. Also it is likely you need to escape backslashes (\\). Refer to this commit: https://github.com/ShaMan123/react-native-math-view/commit/65565985aebc70a6d11de8aba355cc419e8765c0

ShaMan123 commented 3 years ago

for example

<MathView
   config={{ macros: {
                'placeholder': ''
            }}
/>
hypnocill commented 3 years ago

The macros work but they are virtually the same as 'find and replace'. And the issue remains - we can't be sure we've caught all unknown tags that come from the https://cortexjs.io/mathlive/demo/ library. We searched for 'exponentialE' in the mathjax's react native lib source code and it seems to be present in a few places yet it doesn't render. Our issue is that with macros we can't be sure that we'll render all tags that could possibly come from cortexjs and it's very important for us to be sure that we can render the latex properly.

pkra commented 3 years ago

Random bystander here. Both mathlive and mathjax are completely separate systems, even if both use TeX-like syntax (and TeX itself is different still). If you use one tool for authoring and another for rendering, you're bound to run into such issues.

The relevant docs are http://docs.mathjax.org/en/latest/input/tex/macros/index.html and https://cortexjs.io/mathlive/reference/commands/. You can diff them and create all missing macros -- or do the community a favor and create a proper MathJax extension.

ShaMan123 commented 3 years ago

Thanks @pkra for the clear and accurate comment. Rendering math is tough, lots of workarounds are used getting this lib working.

hypnocill commented 3 years ago

Thank you very much for the answers!