harunurhan / react-latex-next

Render LaTeX in React apps
https://react-latex.netlify.app
91 stars 17 forks source link

Add support for multiple children #47

Closed Pezmc closed 11 months ago

Pezmc commented 1 year ago

Previously this library assumed that children was always a single text node, which mean that the following did not work:

<Latex>$1 + {2} + {1 + 2}$<Latex>

React treats this as 5 children: $1 +, 2, +, 1 + 2 - which evaluates to 3, and $

By checking if children is an array, the Latex component now has support for React evaluation, leading to all sorts of possibilities:

<Latex>${variableName} \times {otherVariableName}$</Latex>
<Latex>$3^9 = {Math.pow(3,9))$</Latex>
netlify[bot] commented 1 year ago

Deploy Preview for react-latex ready!

Name Link
Latest commit 24af671c1f05940a56fb1aef40261ab8e0946a83
Latest deploy log https://app.netlify.com/sites/react-latex/deploys/65707bda30cdc90007e40bee
Deploy Preview https://deploy-preview-47--react-latex.netlify.app/
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

harunurhan commented 12 months ago

@Pezmc while this seems like a nice addition, I guess you can still use template string incase you're blocked by this.

Pezmc commented 12 months ago

Re template strings, you can indeed use them as a workaround, but the library still throws exceptions and breaks rendering if there is ever more than one child inside a node which is quite common in react, so even if it's not documented, I think this check should be made.

Pezmc commented 12 months ago

@harunurhan Updated above!