cmark icon indicating copy to clipboard operation
cmark copied to clipboard

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

Open j7168908jx opened this issue 2 years ago • 3 comments

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 avatar Feb 03 '22 05:02 j7168908jx

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!

j7168908jx avatar Feb 03 '22 05:02 j7168908jx

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.

jgm avatar Feb 11 '22 18:02 jgm

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

eric-wieser avatar Nov 08 '23 21:11 eric-wieser