parser: latex support?
希望:
- parser解析出latex公式: $a+b$, [a+b ]
- orga-rehype 生成的html直接就可以展示数学公式,比如用katex
输入org:
* test
$a+b$
\[a+b+\alpha\]
html
<div class="section"><h1>test</h1><p>$a+b$</p><p>\[a+b+\alpha\]</p></div>
会的,这个 parser 会尽量跟org-mode syntax 12保持一致。对于parser本身,我觉得最make sense 的实现是直接返回node:
{ type: “latex”, name: “equation”, value: “x=\sqrt{b}” } 具体的render可以在org-mode to HTML 层用其他包来实现。这样其实就没有多少工作在parser这边。
In #49 I suggest adding plugin support. With that, one of these might be helpful.
Here's a POC of using LaTeX
Live: https://blorg-latex.hao.systems/using-latex Source: https://github.com/LaloHao/gatsby-theme-blorg-latex
Here's a POC of using LaTeX
Live: https://blorg-latex.hao.systems/using-latex Source: https://github.com/LaloHao/gatsby-theme-blorg-latex
@LaloHao Is this all done with the katex import? I.e. did this require zero changes to orgajs? I mean you didn’t have to render the latex to the AST at all right?
Here's a POC of using LaTeX Live: https://blorg-latex.hao.systems/using-latex Source: https://github.com/LaloHao/gatsby-theme-blorg-latex
@LaloHao Is this all done with the katex import? I.e. did this require zero changes to orgajs? I’m you didn’t have to render the latex to the AST at all right?
Yes, you don't need to change orgajs internals, you can do it on your own project
There are 2 commits on my example repository:
- First one is the original source code
- Second one is the changes to you add to use katex
How to:
-
I ran
npm install --save katex rehype-katex rehype-math rehype-parsefor the dependencies -
I added the css file to
gatsby-browser.js
require('katex/dist/katex.min.css');