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

Rehype KaTeX fails once options are added. #108

Closed
4 tasks done
RimuruOtter opened this issue Jan 29, 2025 · 3 comments
Closed
4 tasks done

Rehype KaTeX fails once options are added. #108

RimuruOtter opened this issue Jan 29, 2025 · 3 comments
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on

Comments

@RimuruOtter
Copy link

RimuruOtter commented Jan 29, 2025

Initial checklist

Affected package

[email protected]

Steps to reproduce

First note which I believe is important is that I'm using Tauri to make the project which uses their own package called wry for cross-platform WebView.

const macros: Record<string, any> = {
    "\\lims": "\\lim\\limits_{x \\to #1}",
}

const rehype = rehypeKatex({ macros })

const render = useCallback(async (data: string) => {
        try {
            const evalMarkdown = await compile(data, {
                outputFormat: "function-body",
                remarkPlugins: [remarkMath],
                rehypePlugins: [rehype]
            })
    
            const { default: Content } = await run(evalMarkdown, {
                ...runtime,
                baseUrl: import.meta.url
            })
    
            // @ts-ignore
            setMdxContent(<Content />)
        } catch (error) {
            console.table(error)
        }
    }, [])

I am using MDX in combo with remark math and rehype katex. When I leave the rehypeKatex without options, it would completely fine and nothing wrong happens, when I add the options provided above for macros, it completely fails. I have verified that the above macro works on KaTeX's site.

There error I get is as show:

TypeError: Cannot use 'in' operator to search for 'children' in undefined
    at visit (index.js:353:11)
    at visitParents (index.js:304:30)
    at Function.<anonymous> (index.js:44:5)
    at Function.freeze (index.js:636:36)
    at Function.process (index.js:716:10)
    at compile2 (compile.js:39:35)
    at App.tsx:93:40
    at App.tsx:129:13
    at commitHookEffectListMount (react-dom.development.js:23189:26)
    at commitPassiveMountOnFiber (react-dom.development.js:24965:13)
(anonymous) @ App.tsx:107
(anonymous) @ App.tsx:129
commitHookEffectListMount @ react-dom.development.js:23189
commitPassiveMountOnFiber @ react-dom.development.js:24965
commitPassiveMountEffects_complete @ react-dom.development.js:24930
commitPassiveMountEffects_begin @ react-dom.development.js:24917
commitPassiveMountEffects @ react-dom.development.js:24905
flushPassiveEffectsImpl @ react-dom.development.js:27078
flushPassiveEffects @ react-dom.development.js:27023
(anonymous) @ react-dom.development.js:26808
workLoop @ scheduler.development.js:266
flushWork @ scheduler.development.js:239
performWorkUntilDeadline @ scheduler.development.js:533

I have had this problem before when using Docusourus and was unable to fix it them but didn't matter as much then.

Actual behavior

The actual behavior that is happening is that it is refusing to take in options and works fine when not provided.

Expected behavior

The expected behavior that should happen is that it should take in the options without problems.

Runtime

5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0

Package manager

[email protected]

Operating system

Windows 11

Build and bundle tools

Vite, other (please specify in steps to reproduce)

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 🤞 phase/open Post is being triaged manually 👋 phase/new Post is being triaged automatically labels Jan 29, 2025

This comment has been minimized.

@github-actions github-actions bot added the 🤞 phase/open Post is being triaged manually label Jan 29, 2025
@ChristianMurphy ChristianMurphy added the 🙋 no/question This does not need any changes label Jan 29, 2025
@ChristianMurphy
Copy link
Member

ChristianMurphy commented Jan 29, 2025

@RimuruOtter that isn't how plugins are passed.
Please see https://mdxjs.com/packages/mdx/#processoroptions and the examples of remarkPlugins


const rehype = rehypeKatex({ macros })

Is unexpected and will not work.


It should be passed as

           const evalMarkdown = await compile(data, {
                outputFormat: "function-body",
                remarkPlugins: [remarkMath],
                rehypePlugins: [[rehypeKatex, {macros}]]
            })

@ChristianMurphy ChristianMurphy closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2025

This comment has been minimized.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants