commonmark / cmark

CommonMark parsing and rendering library and program in C
Other
1.64k stars 546 forks source link

[Feature] Support math environment via $ and $$ like LaTeX #439

Open j7168908jx opened 2 years ago

j7168908jx commented 2 years ago

Can we start a branch or anything to have another version that supports math inline and display style rendering just like LaTeX syntax?

So this line $f(x) = 1$ or $$ g(x)=2 $$

shall render directly as if typing LaTeX.

I was originally working on letting my self-hosted GitLab server accept LaTeX dollar expressions starting with $ or $$. This is done by taking dollar as a special char as well as other special chars.

My solution: https://github.com/j7168908jx/commonmarker

Suggested from https://github.com/gjtorikian/commonmarker/issues/80

j7168908jx commented 2 years ago

This is currently a draft though. Some defections might exist in my current implementation.

If anyone would like this to be better implemented, I can check deeper into my code and try to meet up the requirements to merge into commonmark. Thanks anyway!

jgm commented 2 years ago

For comparison, here is the syntax I use for the math extension in commonmark-hs. It is compatible with what pandoc does. https://github.com/jgm/commonmark-hs/blob/master/commonmark-extensions/test/math.md

Your implementation is not compatible, because it allows opening/closing $ delimiters for inline math to be followed/preceded by spaces. I think that's going to end up capturing dollar signs meant for currency.

I think that if we added something like this to cmark, we'd want two new node types, one for inline math and one for display math.

But since we're not adding extensions yet to cmark, this isn't pressing.

eric-wieser commented 11 months ago

https://github.com/commonmark/commonmark-spec/pull/745 is related