-
In the app I'm working on I need to be able to insert dynamic values into Katex math blocks in MDX, for example: export const a = Math.floor(Math.random() * 10)
What is the derivative of ${a}x^2$? Obviously this doesn't work out of the box because a) curlies are part of Katex syntax, and b) anything inside of dollar sign delimiters is parsed by remark-math as Katex instead of as JSX or MDX. Unless there is some fancy interpolation trick I'm missing here, it seems like I have two choices:
import Katex from '../components/Katex'
export const a = Math.floor(Math.random() * 10);
What is the derivative of <Katex>{`${a}x^2`}</Katex>?
export const a = Math.floor(Math.random() * 10)
What is the derivative of $[[a]]x²$? The first option does currently work, but adds a lot of extra visual noise to my content which tends to have a lot of math blocks per page so is very much not ideal. So I guess that's my question: is there a fancy trick I'm missing to accomplish this JS expressions inside of math blocks out of the box? If not, any advice on the best way to go about accomplishing option 2? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Interesting!
|
Beta Was this translation helpful? Give feedback.
-
For anyone who lands here: I've released a package that handles this case: remark-mdx-math-enhanced |
Beta Was this translation helpful? Give feedback.
For anyone who lands here: I've released a package that handles this case: remark-mdx-math-enhanced