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

Unable to parse latex using rehypeKatex plugin #851

Closed
4 tasks done
agrajgarg opened this issue Aug 12, 2024 · 7 comments
Closed
4 tasks done

Unable to parse latex using rehypeKatex plugin #851

agrajgarg opened this issue Aug 12, 2024 · 7 comments
Labels
👯 no/duplicate Déjà vu 👎 phase/no Post cannot or will not be acted on

Comments

@agrajgarg
Copy link

agrajgarg commented Aug 12, 2024

Initial checklist

Affected packages and versions

react-markdown:^9.0.0

Link to runnable example

No response

Steps to reproduce

Run the following code

const preprocessLaTeX = (content) => {
        // Replace block-level LaTeX delimiters \[ \] with $$ $$
        const blockProcessedContent = content.replace(
          /\\\[(.*?)\\\]/gs,
          (_, equation) => `$$${equation}$$`,
        );
        // Replace inline LaTeX delimiters \( \) with $ $
        const inlineProcessedContent = blockProcessedContent.replace(
          /\\\((.*?)\\\)/gs,
          (_, equation) => `$${equation}$`,
        );
        return inlineProcessedContent;
    };


{text && text.length > 0 &&
                            text.map((message, index) => (
                                <div key={index} className="markdown" id="bot-msg">
                                    <ReactMarkdown
                                        remarkPlugins={[remarkMath]} 
                                        rehypePlugins={[rehypeRaw, rehypeKatex]}
                                        components={{
                                            img: ({node, ...props}) => <img style={{maxWidth: '100%'}} {...props} />
                                        }}
                                    >
                                        {preprocessLaTeX(message)}
                                    </ReactMarkdown>
                                </div>
                            ))
                        }

Expected behavior

Should render latex equations on the page3

Actual behavior

giving error:

_propertyInformation.hastToReact is undefined

Runtime

Node v17

Package manager

npm 8

OS

macOS

Build and bundle tools

Parcel

@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 12, 2024
@wooorm
Copy link
Member

wooorm commented Aug 12, 2024

Please fix your markdown. I cannot read this.

@agrajgarg
Copy link
Author

Please fix your markdown. I cannot read this.

fixed it

@wooorm
Copy link
Member

wooorm commented Aug 12, 2024

Thanks!

Next step, when raising an issue, is to try to make your reproduction smaller.
As small as can be.
Remove everything that’s not related to the error.
I am quite sure that an _propertyInformation.hastToReact error does not come from your img component. Or from preprocessLaTeX.

Then, search through the existing issues. If you look for hastToReact here, you will find: #747

So, it seems that this error occurs because you use an older bundler with bugs: likely Parcel. Can you confirm this is the case?

@agrajgarg
Copy link
Author

Thanks!

Next step, when raising an issue, is to try to make your reproduction smaller. As small as can be. Remove everything that’s not related to the error. I am quite sure that an _propertyInformation.hastToReact error does not come from your img component. Or from preprocessLaTeX.

Then, search through the existing issues. If you look for hastToReact here, you will find: #747

So, it seems that this error occurs because you use an older bundler with bugs: likely Parcel. Can you confirm this is the case?

Yes, I checked the issue disappeared by manually doing

npm install property-information

and

import 'property-information'
in my component.

This comment was marked as duplicate.

@wooorm wooorm added 👯 no/duplicate Déjà vu 👎 phase/no Post cannot or will not be acted on labels Aug 12, 2024
Copy link

Hi! Thanks for taking the time to contribute!

Because we treat issues as our backlog, we close duplicates to focus our work and not have to touch the same chunk of code for the same reason multiple times. This is also why we may mark something as duplicate that isn’t an exact duplicate but is closely related.

Thanks,
— bb

@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Aug 12, 2024

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/duplicate Déjà vu 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants