orgajs icon indicating copy to clipboard operation
orgajs copied to clipboard

parser: latex support?

Open v2gt opened this issue 5 years ago • 4 comments

希望:

  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这边。

v2gt avatar Jan 07 '20 08:01 v2gt

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

gitonthescene avatar Jun 16 '20 01:06 gitonthescene

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 avatar Jun 05 '21 14:06 LaloHao

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?

gitonthescene avatar Jun 06 '21 09:06 gitonthescene

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');
  1. Create a new component post with latex processing

  2. Create org-mode posts

LaloHao avatar Sep 11 '21 05:09 LaloHao