fast-reflexes / better-react-mathjax

MIT License
124 stars 16 forks source link

Does \color work? #49

Closed MarkZamoyta closed 8 months ago

MarkZamoyta commented 8 months ago

It works fine in MathJax, ( \color{red}{x} )

But it doesn't work in this repo: {"\(\color{red}{x}\)"}

It turns the literal string "\color" red, which makes it seem like an unknown command.

fast-reflexes commented 8 months ago

Hi there!

It works great... you probably just forgot that you have to make two backslashes in a string to create one backslash in the output since backslash is also a special character in strings (escape).

https://codesandbox.io/p/sandbox/better-react-mathjax-49-r24rxc

Close if you feel happy with the answer plz :)

fast-reflexes commented 8 months ago

Closing this since I believe it answers your question and it hasn't received any input from you. Feel free to open if you need.

MarkZamoyta commented 7 months ago

I see that your example works, but I still couldn't get mine to work. Then I discovered I needed to load the Tex extension for color, then it worked fine in my app. I have no idea why your example works without loading the tex extension!

fast-reflexes commented 7 months ago

Hmm interesting ... are you using the default config as I do? No properties added to the MathJaxContext? If so you should get the exact same behaviour ... I think the Tex package is imported automatically then but maybe I'm wrong :)

MarkZamoyta commented 7 months ago

I see in the docs that if \color is encountered, the extension will be downloaded automatically, so that's why your example works. My app probably isn't downloading the extension, or maybe it's rendering before the download. Either way, I like packaging it manually since I know I need it. Thanks for helping out.