Skip to content
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

fails to render math equations in mdx #1

Open
ArnieHung opened this issue Dec 27, 2022 · 1 comment
Open

fails to render math equations in mdx #1

ArnieHung opened this issue Dec 27, 2022 · 1 comment
Assignees

Comments

@ArnieHung
Copy link
Owner

ArnieHung commented Dec 27, 2022

Description

// gatsby-config.js
resolve: 'gatsby-plugin-mdx',
    options: {
      gatsbyRemarkPlugins: [
        {
          resolve: `gatsby-remark-katex`,
          options: {
            strict: `ignore`
          }
        },
      },
  • But when running gatsby develop, the following warnings show up despite it's been successfully built:
warn Error persisting state: function mathPlugin (opts) {
  if (opts == null) opts = {}
  blockPlugin.call(this, opts)
  inlinePlugin.call(this, opts)
} could not be cloned.

Possible solutions

// gatsby-config.js
{
    resolve: 'gatsby-plugin-mdx',
    options: {
      extensions: ['.mdx', '.md'],
      remarkPlugins: [require('remark-math')],
      rehypePlugins: [require('rehype-katex')],
    },
  },

Problem Remains

@danghoangnhan danghoangnhan pinned this issue Dec 28, 2022
@danghoangnhan danghoangnhan self-assigned this Dec 28, 2022
@ingyer-ks
Copy link

Dear,
Like you guessed, until Gatsby 5.3 it didn't support ESM.
So, you need to use remark-math^3.0.1 and rehype-katex^5.0.0 with your Possible solutions style.
And like I mentioned in gatsbyjs/gatsby#21866 (comment) load katex css in gatsby-ssr.js file like below:

const HeadComponents = [
  <link
    rel="stylesheet"
    href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.min.css"
    integrity="sha384-AfEj0r4/OFrOo5t7NnNe46zW/tFgW6x/bCJG8FqQCEo3+Aro6EYUG4+cU+KJWu/X"
    crossorigin="anonymous"
  ></link>
]

export const onRenderBody = ({ setHeadComponents }) => {
  setHeadComponents(HeadComponents)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants