-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gatsby-plugin-mdx doesn't render "complex" Katex formulas #28031
Comments
In the discussion with the MDX team @wooorm mentions that several dependencies are out of date by several years. That might have something to do with it, though I can't say anything for certain.
|
Can this issue get the |
Marked "not stale". Yeah, we need to do soon a major release for the whole suite of plugins with updated dependencies. |
@KyleAMathews That's great to hear! I'm doing a lot of work with MDX at the moment and am willing to help test out any changes. |
Just to add another edge case:
|
@nikbelikov How were you able to get the |
please, mention @nikoladev instead :) |
@tnorlund If you look at my minimal reproducible example I describe the workaround there. I basically pass the formula as a string to a custom component and then use I think it's best if you clone that repo and play with it. |
Ok. Will do. I got everything working inside a math block in an MDX file. I just learned that Katex uses 'aligned' rather than 'align*'. Is this still an issue? |
👋 hey we're working on updating the gatsby remark ecosystem to the latest versions of things which should help out with this issue. If you'll want to try testing things out to see if katex works better, that'd be really helpful! #30385 |
I can't really say. I'm not the Latex person in our team, I just set up Gatsby for the Latex person 🤷♀️ Questions like this would probably be better for the actual Katex team. |
@KyleAMathews Thanks! At the moment I don't have the time. So it would be great if anyone else can clone my repo and try out the updated plugins to see if it fixes the bugs. |
Update: as mentioned by @vladar in this discussion, |
@nikoladev - I tried your complex math formula on a gatsby site that I am working on and it seems to render properly. the complex math formula:
screenshot of rendered complex formula (in dark mode): However, I am using the latest npm packages (except for remark-math which needs to be on v3 until So in your {
resolve: 'gatsby-plugin-mdx',
options: {
defaultLayouts: {
default: require.resolve(path.resolve(__dirname, 'src', 'templates', 'Page.jsx')),
},
remarkPlugins: [
require('remark-math'),
require('remark-html-katex'),
],
},
}, to: {
resolve: 'gatsby-plugin-mdx',
options: {
defaultLayouts: {
default: require.resolve(path.resolve(__dirname, 'src', 'templates', 'Page.jsx')),
},
remarkPlugins: [require('remark-math')],
rehypePlugins: [require('rehype-katex')],
},
}, And make sure to install |
@kimbaudi, why |
@tnorlund according to the README in |
the reason why I commented on this issue is because the "complex" katex formula rendered correctly for me using
I'm assuming you mean not being able to upgrade |
@kimbaudi Thanks for looking into it :) I tried your fix, and it doesn't seem to work. You can try it out in this branch to see if I did something wrong. Are you sure you removed the 3 backticks around the broken examples in |
I looked into your repo and I see 2 issues in your
if you change your package.json from
to
then complex katex formulas work |
i think your issue is that you are trying to use v2next versions of mdx, which isn't currently supported in |
Yeah, the Gatsby team is still waiting for a stable release of MDX and then they'll update Thanks for thinking along :) |
Switches from gatsby-remark-katex to remark-math + rehype-katex See gatsbyjs/gatsby#28031 (comment)
Hi, this comment is just to provide another example of a formula that I couldn't get to work and to provide a workaround (for this specific case), in case someone is struggling with a similar problem. My specific (but imo quite general case) is to get some LaTeX formula into a subscript block. While simple things such as indices (e.g., but which suffers from the same problem as the one described in the original post, i.e.,
One quite annoying way to make this work is to use a sequence of empty
which I used to produce the image shown above. Maybe thhis helps someone until the update with MDX v2 is out :) |
@janmaltel - i tried BTW, I am using Here is the relevant snippet from my const remarkMath = require(`remark-math`);
const rehypeKatex = require(`rehype-katex`);
// ...
{
resolve: `gatsby-plugin-mdx`,
options: {
defaultLayouts: {
default: path.resolve(__dirname, `src/templates/mdx-template.jsx`),
},
remarkPlugins: [remarkMath],
rehypePlugins: [rehypeKatex],
},
},
// ... Out of curiosity, are you using mdx v2? Because I've only encountered the error On a side note, there is a major overhaul in how mdx is parsed in v2 (see mdx-js/mdx#1039) and that could affect the way math equations are rendered. Also, there will be breaking changes mdx v2 so some things that worked in markdown or mdx v1 no longer will work in mdx v2 (i.e., html comments will no longer be supported in mdx v2. see mdx-js/mdx#1042). As already mentioned by the author of mdx, MD !== MDX. I want to add that MDXv1 !== MDXv2 |
Thank you for the info and your time @kimbaudi !
I tried to adapt my @nikoladev you wrote this earlier:
Do you know of an issue / thread that tracks progress on this? |
Woooooow, I only now saw your |
You're welcome :) Thanks for letting me know it was hard to find, I've updated the intro post for anyone who is looking for a quickfix.
Not really. Here's a response from a Gatsby employee on them waiting for a stable version 2 of MDX. Only thing I can think of is subscribing to MDX releases (you can click on |
MDX v2 was out in February. But we still need to wait Gatsby for its MDX v2 support. #34421 |
Hi! We merged #35650 which means that a new major version of With this you can use MDX v2. Please open an issue with a minimal reproduction if this is still not solved yet. Thanks! |
Description
I don't know the exact terms to describe it, but "complex" Katex formulas prevent MDX from rendering. (Feel free to change the title into something more specific)
I've figured out a workaround by passing the formula as a string to a custom component that runs the string through
katex.renderToString
and then passes the output todangerouslySetInnerHTML
. That might help in pinpointing where the problem occurs.(⚠️ Note for anyone looking for a QUICKFIX: use this component to render Katex formulas that break rendering)
I have already talked to the MDX team about this, and they managed to get it working by removing gatsby-plugin-mdx from the equation (see the link for codesandboxes with examples).
Steps to reproduce
There is a minimal reproducible example here with instructions on how to make it fail as well as the workaround in action.
This is the formula in question:
Expected result
The formula should render.
Actual result
I get this error:
The text was updated successfully, but these errors were encountered: