Search code examples
javascriptreactjstypescriptlatexmathjax

write formula of regression in react.js


I want to write a mathematical formula along my text that includes alpha and beta values. How can I do so? If I copy paste the formula of polynomial linear regression from wikipedia to my code, I get this:

{\displaystyle y=\beta _{0}+\beta _{1}x+\beta _{2}x^{2}+\varepsilon .\,}

https://en.wikipedia.org/wiki/Polynomial_regression#:~:text=In%20statistics%2C%20polynomial%20regression%20is,nth%20degree%20polynomial%20in%20x.&text=For%20this%20reason%2C%20polynomial%20regression,case%20of%20multiple%20linear%20regression.

I read that there's a library 'react-mathjax' but I couldn't figure out how to use alpha beta symbols.


Solution

  • You can check out a new library called better-react-mathjax that I have written. It is written with the latest standards of React in mind.

    The following code accomplishes what you want:

    <MathJaxContext config={config}>
      <h2>MathJax use with Latex</h2>
      <MathJax dynamic>
        {"$$y=\\beta _{0}+\\beta _{1}x+\\beta _{2}x^{2}+\\varepsilon$$"}
      </MathJax>
    </MathJaxContext>
    

    I don't know for what you wanted to keep the last part (.\,) so I removed it but you can put it back if you want to.

    I have prepared a sandbox for you, check it out and hope you like it!

    Link: https://codesandbox.io/s/user-example-1-zu5vb