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

An error occurs with certain text when using remarkMath and rehypeKatex. #853

Closed
4 tasks done
devleejb opened this issue Aug 19, 2024 · 8 comments
Closed
4 tasks done
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on

Comments

@devleejb
Copy link

Initial checklist

Affected packages and versions

react-markdown:9.0.1

Link to runnable example

No response

Steps to reproduce

  1. Implement the following code. (Node 18, npm 10)
    <Markdown
        remarkPlugins={[remarkMath]}
        rehypePlugins={[rehypeKatex]}
    >
      {`$\\begin\\ca$`}
    </Markdown>
  2. Run the code.
  3. Check for any errors.

Expected behavior

It should render the markdown text correctly.

Actual behavior

�Following error occurs.
image

Runtime

Other (please specify in steps to reproduce)

Package manager

Other (please specify in steps to reproduce)

OS

macOS

Build and bundle tools

Vite

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Aug 19, 2024
@devleejb devleejb changed the title Error An error occurs with certain text when using remarkMath and rehypeKatex. Aug 19, 2024
@wooorm
Copy link
Member

wooorm commented Aug 19, 2024

This looks like a KaTeX problem, why not raise it with KaTeX? Why raise it here? Do you think there is something to change here?

@devleejb
Copy link
Author

@wooorm
At first, I thought that it is a KaTex problem. But, when I run the following code, it runs correctly.

const file = await unified()
  .use(remarkParse)
  .use(remarkMath)
  .use(remarkRehype)
  .use(rehypeKatex)
  .use(rehypeStringify)
  .process(`$\\begin\\ca$`)

@wooorm
Copy link
Member

wooorm commented Aug 19, 2024

Cannot reproduce:

import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkMath from 'remark-math'
import remarkRehype from 'remark-rehype'
import rehypeKatex from 'rehype-katex'
import rehypeStringify from 'rehype-stringify'

const file = await unified()
  .use(remarkParse)
  .use(remarkMath)
  .use(remarkRehype)
  .use(rehypeKatex)
  .use(rehypeStringify)
  .process(`$\\begin\\ca$`)

console.log(String(file))
file:///Users/tilde/Projects/oss/react-markdown/node_modules/katex/dist/katex.mjs:7482
    throw new Error("Expected node of type " + type + ", but got " + (node ? "node of type " + node.type : String(node)));
          ^

Error: Expected node of type textord, but got node of type color
    at assertNodeType (file:///Users/tilde/Projects/oss/react-markdown/node_modules/katex/dist/katex.mjs:7482:11)
    at Object.handler (file:///Users/tilde/Projects/oss/react-markdown/node_modules/katex/dist/katex.mjs:11491:18)
    at Parser.callFunction (file:///Users/tilde/Projects/oss/react-markdown/node_modules/katex/dist/katex.mjs:17637:19)
    at Parser.parseFunction (file:///Users/tilde/Projects/oss/react-markdown/node_modules/katex/dist/katex.mjs:17620:17)
    at Parser.parseGroup (file:///Users/tilde/Projects/oss/react-markdown/node_modules/katex/dist/katex.mjs:18012:21)
    at Parser.parseAtom (file:///Users/tilde/Projects/oss/react-markdown/node_modules/katex/dist/katex.mjs:17450:21)
    at Parser.parseExpression (file:///Users/tilde/Projects/oss/react-markdown/node_modules/katex/dist/katex.mjs:17312:23)
    at Parser.parse (file:///Users/tilde/Projects/oss/react-markdown/node_modules/katex/dist/katex.mjs:17244:24)
    at parseTree (file:///Users/tilde/Projects/oss/react-markdown/node_modules/katex/dist/katex.mjs:18247:21)
    at renderToDomTree (file:///Users/tilde/Projects/oss/react-markdown/node_modules/katex/dist/katex.mjs:18337:16)

As in: there’s definitely a KaTeX error, when using the latest dependencies otherwise.

Now, rehype-katex also has a problem. It should catch that error.

@devleejb
Copy link
Author

@wooorm
Okay. Sorry, I'll check it again and raise it in KaTeX.

@wooorm
Copy link
Member

wooorm commented Aug 19, 2024

OK, if you believe that math input to be valid for KaTeX.

I’ll also work on a fix in rehype-katex to swallow that error and display the raw input instead of crashing.

@wooorm
Copy link
Member

wooorm commented Aug 19, 2024

In rehype-katex I am getting this error btw:

ParseError: KaTeX parse error: Undefined control sequence: \ca at position 7: \begin\̲c̲a̲
    at new ParseError (file:///Users/tilde/Projects/oss/remark-math/node_modules/katex/dist/katex.mjs:147:16)
    at Parser.parseGroup (file:///Users/tilde/Projects/oss/remark-math/node_modules/katex/dist/katex.mjs:18016:17)
    at Parser.parseAtom (file:///Users/tilde/Projects/oss/remark-math/node_modules/katex/dist/katex.mjs:17450:21)
    at Parser.parseExpression (file:///Users/tilde/Projects/oss/remark-math/node_modules/katex/dist/katex.mjs:17312:23)
    at Parser.parseArgumentGroup (file:///Users/tilde/Projects/oss/remark-math/node_modules/katex/dist/katex.mjs:17955:27)
    at Parser.parseGroupOfType (file:///Users/tilde/Projects/oss/remark-math/node_modules/katex/dist/katex.mjs:17705:21)
    at Parser.parseArguments (file:///Users/tilde/Projects/oss/remark-math/node_modules/katex/dist/katex.mjs:17670:22)
    at Parser.parseFunction (file:///Users/tilde/Projects/oss/remark-math/node_modules/katex/dist/katex.mjs:17619:14)
    at Parser.parseGroup (file:///Users/tilde/Projects/oss/remark-math/node_modules/katex/dist/katex.mjs:18012:21)
    at Parser.parseAtom (file:///Users/tilde/Projects/oss/remark-math/node_modules/katex/dist/katex.mjs:17450:21) {
  position: 6,
  length: 3,
  rawMessage: 'Undefined control sequence: \\ca'
}

So could be that that is the root problem

@wooorm wooorm added the 👀 no/external This makes more sense somewhere else label Aug 19, 2024

This comment has been minimized.

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants