-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
latex parsing needed #480
Comments
Open to PRs if you can implement it in a lightweight fashion |
are you thinking just a separate category that you can apply an override to? Is there a suitable semantic HTML element container? |
Spent some time looking at this, I think the most straightforward way to handle it is to leverage the existing fenced code block grammar and perhaps add an option to customize the wrapper things are placed in and a function to invoke after rendering. For example, it could look like this in markdown: ```latex
$$f(X,n) = X_n + X_{n-1}$$
```
This matters because many of the utilities for parsing LaTeX I looked at will automatically ignore
This would probably also be useful for syntax highlighters, often they struggle to know when they need to reparse the document. |
@quantizor that makes sense to me! |
If you want a hack that will work in the meantime:
import "katex/dist/katex.min.css";
import {InlineMath} from "react-katex";
import Markdown from 'markdown-to-jsx'
// Change this to whatever you want,
// Just make sure that wherever you want latex to appear, you use this.
// You could, for instance, write a script to turn any pair of `$$` statements into the correct
// enclosing tags, as that is a common way to denote "latex starts here"
const NAME_OF_LATEX_TAG = "latex"
// Make sure your latex has double-backslashes!!
// If you don't double-up on the backslashes, sometimes formatting gets lost...
const mdStringWithLatex = `
# Regular Markdown
*italics* **bold**
# Latex
<${NAME_OF_LATEX_TAG}>\\\\sqrt{a^2 + b^2}</${NAME_OF_LATEX_TAG}>
`
const renderComponent = () => {
<Markdown
options={{
overrides: {
// Here's where we tell Markdown-To-JSX to ignore whatever is in the tag,
// and replace it with our own component.
// In this case we're replacing it with <InlineMath> from `react-katex`,
// But you can use whatever react component you'd like.
[NAME_OF_LATEX_TAG]: (props: any) => {
// Hacky, doesn't support multiline children
const childstr = props.children[0] as string
return <InlineMath math={childstr}/>
}
},
}}
>
{mdStringWithLatex}
</Markdown>
} |
Thanks for the great component!
It seems that both inline and block latex equations are not supported as for now. For example, it would be ideal for
in markdown to be parsed as a special element so that we can further overwrite the component by katex.js etc. to get the final result as follows:
Please refer to https://ashki23.github.io/markdown-latex.html for more examples. This feature is critical to handle markdown for math, computer science, machine learning etc. Thanks in advance.
The text was updated successfully, but these errors were encountered: