Replies: 1 comment
-
Seems like a duplicate of remarkjs/react-markdown#851 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
{ text.map((message, index) => ( <div key={index} className="markdown" id="bot-msg"> <Markdown remarkPlugins={[remarkMath]} rehypePlugins={[rehypeRaw, rehypeKatex]} components={{ img: ({node, ...props}) => <img style={{maxWidth: '100%'}} {...props} /> }} > {preprocessLaTeX(message)} </Markdown> </div> )) }
Here i am using rehypeKatex to render latex text returned by gpt. I know that gpt returns latex equations in \[] but katex supports latex equations starting with $$. I used the following method to convert the text in the correct format
const preprocessLaTeX = (content) => { debugger; // Replace block-level LaTeX delimiters \[ \] with $$ $$ const blockProcessedContent = content.replace( /\\\[(.*?)\\\]/gs, (_, equation) =>
$$${equation}$, ); return inlineProcessedContent; };
Beta Was this translation helpful? Give feedback.
All reactions