question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem using remark-math with MDX

See original GitHub issue

I’ve been trying to plug in the KaTeX renderer into the chain of plugins for MDX, but so far, I’m stuck with with some of the formulae incorrectly rendering.

My webpack rules part is as follows:

{
  test: /\.mdx$/,
  use: [
    ...babelLoader,
    {
      loader: '@mdx-js/loader',
      options: {
        mdPlugins: [math],
        hastPlugins: [katex]
      }
    }
  ]
}

…where math and katex are the packages remark-math and rehype-katex, respectively. I’m using preact and preact-compat with the following aliases:

alias: {
  react: 'preact-compat/dist/preact-compat',
  'react-dom': 'preact-compat/dist/preact-compat',
  'react-addons-create-fragment': 'preact-compat/dist/preact-compat'
}

To illustrate the problem, I’m trying to render the following page:

import 'katex/dist/katex.css';
import { h } from 'preact';

## Math test

$$
\sum{1}
$$

$$
\sum{i}
$$

The first equation renders fine, since 1 is a literal and is just converted to a string in the JSX. However, the second equation uses {i} in the rendered JSX and tries to evaluate the i, which fails because i is undefined.

Is there a way to have JSX be ignored or forced to escape in the math portion of the MDX?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
silvenoncommented, Sep 20, 2018

@linonetwo released in v0.15.3-0.

1reaction
KrofDrakulacommented, Sep 19, 2018

Sorry, I’m AFK for the next couple of days, I may have missed something in my reproduction, like an older version of MDX, maybe. I’ll see if this is still an issue with my setup when I can check it. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js MDX rendering problem with remark-math and rehype ...
I am using MDX in my NEXT.JS project with the react-math and rehype-katex plugins. When I render the MDX files it gives me...
Read more >
Math - MDX
This guide explores how to support math (LaTeX) in MDX. ... Math can be enabled by using a remark plugin: remark-math , combined...
Read more >
remark-math examples - CodeSandbox
Remark Math Examples. Learn how to use remark-math by viewing and forking example apps that make use of remark-math on CodeSandbox.
Read more >
Using KaTeX With Gatsby and MDX - Trevor Blades
My website is built with Gatsby and MDX using gatsby-plugin-mdx , which accepts remark and rehype plugins as configuration options. Luckily there's a...
Read more >
remark-plugin - Keywords - unified
remark plugin to support MDX syntax ... remark plugin to autolink references like in GitHub issues, PRs, and comments. 71%; 330k; 2.71 kB...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found