#Parsing error with math in MDX.

3 messages · Page 1 of 1 (latest)

ancient cloud
#

Hey everyone, I'm having trouble using math inside of MDX. There are a few libraries that may be the source of the issue, but I thought this might be a good first place to ask for help after Googling failed me.

I get an error whenever I have an escaped expression inside of curly braces. Take this simple expression for example:

$$
\frac{1}{\sigma}
$$

The \sigma raises this error in VSCode : Could not parse expression with acorn. It comes with a link to https://github.com/micromark/micromark-extension-mdx-expression/tree/main/packages/micromark-extension-mdx-expression#could-not-parse-expression-with-acorn which leads me to believe that acorn is erroneously treating the curly braces in my math like JavaScript expressions, but only when a \ is present. What's weird is that the website still compiles and everything is rendered correctly, despite the red text file names and squiggly lines.

Here's my astro.config.mjs:

// @ts-check
import { defineConfig } from 'astro/config';
import mdx from '@astrojs/mdx';
import react from '@astrojs/react';
import sitemap from '@astrojs/sitemap';
import tailwind from '@astrojs/tailwind';
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';

// https://astro.build/config
export default defineConfig({
  integrations: [react(), mdx(), sitemap(), tailwind()],
  markdown: {
    remarkPlugins: [remarkMath],
    rehypePlugins: [rehypeKatex],
  },
});

And here's the versions of every installed module:

├── @astrojs/[email protected]
├── @astrojs/[email protected]
├── @astrojs/[email protected]
├── @astrojs/[email protected]
├── @tailwindcss/[email protected]
├── @types/[email protected]
├── @types/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Thank you in advance 🙏

ancient cloud
ancient cloud
#

I still haven't had any luck. Can anyone else replicate it?