orgapp / orgajs

parse org-mode content into AST
https://orga.js.org
MIT License
614 stars 62 forks source link

parser: latex support? #41

Open v2gt opened 4 years ago

v2gt commented 4 years ago

希望:

  1. parser解析出latex公式: $a+b$, [a+b ]
  2. 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这边。

gitonthescene commented 4 years ago

In #49 I suggest adding plugin support. With that, one of these might be helpful.

LaloHao commented 3 years ago

Here's a POC of using LaTeX

Live: https://blorg-latex.hao.systems/using-latex Source: https://github.com/LaloHao/gatsby-theme-blorg-latex

gitonthescene commented 3 years ago

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?

LaloHao commented 3 years ago

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:

  1. First one is the original source code
  2. Second one is the changes to you add to use katex

How to:

  1. I ran npm install --save katex rehype-katex rehype-math rehype-parse for the dependencies

  2. I added the css file to gatsby-browser.js

    require('katex/dist/katex.min.css');
  3. Create a new component post with latex processing

  4. Create org-mode posts