-
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-remark-katex] Doesn’t work with gatsby-plugin-mdx #21866
Comments
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Hey, I'd like to take a shot at this as my first contribution to the gatsby codebase. Been looking into how plugins work in the past days. Need to invest more time over the weekend. Meanwhile, any tips anyone? |
@danedavid: Here’s what I’d start with:
module.exports.setParserPlugins = () => { console.log("PLUGIN IS BEING PICKED UP"); return [remarkMath]; }
I’d expect the problem to become evident somewhere along this process. Warning: Take what I’m saying with a grain of salt, as I’ve never contributed to the Gatsby codebase myself. |
I looked into this. It appears the plugin is picked up. It looks like the issue is with the generated {
allMdx {
edges {
node {
mdxAST
}
}
}
} the result AST has an I also put logs inside |
Could it be that gatsby-plugin-mdx isn’t using the mdxAST field, but something like the body field? |
Finally got time, and fixed it. The issue was with |
What’s the best way for me to check? I tried to clone |
@leafac The branch has been merged, so you should just need to check with the latest version of Gatsby. If you can do that, let us know if it fixes it for you. |
I tried it with the latest versions and the problem remains. Here’s my {
"dependencies": {
"@mdx-js/mdx": "^1.6.5",
"@mdx-js/react": "^1.6.5",
"gatsby": "^2.23.0",
"gatsby-plugin-mdx": "^1.2.14",
"gatsby-remark-katex": "^3.3.3",
"gatsby-source-filesystem": "^2.3.10",
"katex": "^0.11.1",
"react": "^16.13.1",
"react-dom": "^16.13.1"
}
} To try it for yourself, just use this |
The issue is with webpack |
What’s a practical way for me to test that branch? |
@leafac No easy way. Clone, build |
I’m sorry but I don’t have the time to test this right now, so I’ll just take @danedavid’s word that the issue is fixed. |
Hmm, funny. I have had this issue before and was using the workaround for a while. Not sure what has changed since then but the usual instructions work for me now In {
resolve: `gatsby-plugin-mdx`,
options: {
gatsbyRemarkPlugins: [
{
resolve: `gatsby-remark-katex`,
options: {
strict: `ignore`,
},
},
}
} and in import "katex/dist/katex.min.css" For someone who wants to inspect further, the complete source is here. |
@danedavid I will just second what @leafac already said. Sounds like you are missing the CSS. There are instructions on the plugin page for Gatsby. |
Still facing this and had to use the remark/rehype plugins directly =\ |
What ended fixing the problem for me (march/2021 - |
What's your |
@nitzanvolman @tnorlund - I'd also be interested in seeing that. Still struggling with MDX + Katex on Gatsby v3 |
@tnorlund @princefishthrower I had the same problem and here's the package versions I used and my |
Thanks for the help, but the Katex font doesn't match with the one I'm using in Latexit. Do you know how I can get this font? |
|
//gatsby-config.js
module.exports = {
...
plugins: [
{
resolve: `gatsby-plugin-mdx`,
options: {
remarkPlugins: [
...
require( `remark-math` ),
require( `remark-html-katex` ),
],
extensions: [`.md`, `.mdx`],
},
},
...
]
} // package.json
{
...
"dependencies": {
...
"@mdx-js/mdx": "^1.6.22",
"@mdx-js/react": "^1.6.22",
"gatsby": "^3.1.2",
"gatsby-plugin-mdx": "^2.1.0",
"remark-html-katex": "^3.0.0",
"remark-math": "^3.0.1",
...
},
...
} |
I'm a node n00b, but I can't resolve the packages correctly using this configuration of //gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-mdx`,
options: {
remarkPlugins: [
{
resolve: `gatsby-remark-vscode`,
},
// `gatsby-remark-vscode`, <- This no longer works
require( `remark-math` ),
require( `remark-html-katex` ),
],
extensions: [`.md`, `.mdx`],
},
}, |
Has anyone had problems with |
@ehowey Try running |
|
Just figured out that the default is |
This is what I have so far. It works, but I cannot write 'complex' equations. // gatsby-config.js
const remark_math = require( `remark-math` )
const remark_html_katex = require( `remark-html-katex` )
module.exports = {
plugins: [
{
resolve: `gatsby-plugin-mdx`,
options: {
gatsbyRemarkPlugins: [
{
resolve: `gatsby-remark-katex`,
options: {
strict: `ignore`,
}
},
],
remarkPlugins: [ remark_math, remark_html_katex ],
extensions: [`.md`, `.mdx`],
},
}, |
@tnorlund thanks for sharing the config, it also works for me except my macros in the |
It seems this is not properly documented yet and maybe the root issue is not yet resolved? When digging through this thread I also faced issues with the recommend solutions, i.e. require('remark-math'), as require is not allowed. And the different plugins (remark-math, remark-html-katex, gatsby-remark-katex, rehype-katex) also confuse me. Am I assuming correct, that what is currently documented // doesnt-work
$ npm install gatsby-transformer-remark gatsby-remark-katex katex
// gatsby-config.js
{
resolve: `gatsby-plugin-mdx`,
options: {
gatsbyRemarkPlugins: [`gatsby-remark-katex`]
}
} is the way it should work, but does not? |
Unfortunately not yet. The root issue is that However then it seems to need updating
I agree with you. It should work unless such incompatibility. But thus we need some workaround for right now. Since it's not a specific issue only with WorkaroundFYI, here is the workaround to enable KaTeX with There are two points.
Version
Snippet npm install [email protected] [email protected] gatsby-config.js module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-mdx',
options: {
remarkPlugins: [
require('remark-math'),
],
rehypePlugins: [
[require('rehype-katex'), { strict: 'ignore' }],
],
}
}
]
} gatsby-browser.js import 'katex/dist/katex.min.css' Note that |
I works (I'm using Gatsby 4.12.1 and gatsby-plugin-mdx 3.9.1) |
Dear all,
in gatsby-browser.js doesn't work.
and now it works. |
For What It's Worth, this is the setup that worked for me: Dependencies: "gatsby": "^5.12.4",
"remark-math": "^5.1.1",
"rehype-katex": "^6.0.3", Gatsby Configuration: {
resolve: `gatsby-plugin-mdx`,
options: {
mdxOptions: {
remarkPlugins: [remarkMath],
rehypePlugins: [
[rehypeKatex, { strict: 'ignore' }],
],
},
},
} Example in .mdx: import 'katex/dist/katex.min.css'
$$
x = \frac{{-b \pm \sqrt{{b^2 - 4ac}}}}{{2a}}
$$
The formula \( a + b = 2 \) tells us something important. |
Description
I followed the instructions to install
gatsby-remark-katex
on a website usinggatsby-plugin-mdx
and it didn’t work. No errors, no nothing, it just didn’t transform the LaTeX in the Markdown.Steps to reproduce
In this zip there are two projects:
doesnt-work
: This is a minimal project to show the issue. To create this project I just followed the instructions to installgatsby-remark-katex
.works
: This is a workaround I found based on this comment and the documentation forremark-math
, in which they suggest to userehype-katex
instead ofremark-html-katex
.You can run the projects with the usual
npm install && npx gatsby develop
and visithttp://localhost:8000
.In summary, the difference is instead of:
you do:
Expected result
The LaTeX in the Markdown should be rendered.
Actual result
The LaTeX in the Markdown appears unmodified.
Environment
The text was updated successfully, but these errors were encountered: