comrak icon indicating copy to clipboard operation
comrak copied to clipboard

Mathematics

Open jeanm opened this issue 7 years ago • 4 comments

A commonly requested feature is the ability to input mathematics using LaTeX syntax without the markdown parser getting confused and messing it all up. All the parser needs to do is leave the maths alone, without interpreting underscores/askerisks/escapes, and rendering can then be delegated to something like MathJax or KaTeX. It would certainly be a nice feature for scientists, or people needing to describe algorithms etc.

A while ago I made a summary table of all the ways this syntax extension has been implemented in other markdown software, available here: https://github.com/cben/mathdown/wiki/Math-in-MarkDown#appendix-summary-table. I'd say probably the right answer is to do what pandoc does, and have $ ... $ to delimit inline formulae, and $$ ... $$ for display-mode.

jeanm avatar Jun 26 '17 16:06 jeanm

I have indeed seen this feature request a number of times across a number of channels!

My primary goal for comrak is to implement GFM-compatible CommonMark and to leave it at that, but I think it could be valuable to implement experimental extensions (such as math). There's a number of threads on the CommonMark forums about implementing math in CommonMark, either directly or as an extension.

I don't have the time to implement such an extension myself, but I would welcome a PR.

kivikakk avatar Jun 27 '17 02:06 kivikakk

I think that when math is enabled, we should use something like ${ to open math and }$ to close it. This is compatible (the opening { and closing } are simply ignored by TeX) and avoids many false positives on things such as item prices. In such cases, $ should be somehow escaped to avoid problems, and there should be a way to escape it in Markdown input.

DemiMarie avatar Aug 06 '17 02:08 DemiMarie

No other parser uses this syntax. Is it really worth introducing something nonstandard?

The pandoc author claims that, with some simple heuristics, false positives are simply not an issue: https://talk.commonmark.org/t/ignore-latex-like-math-mode-or-parse-it/1926/6. My experience has matched his so far.

jeanm avatar Aug 06 '17 18:08 jeanm

@jeanm You are probably correct. In that case Comrak will need to wrap $ in a <span> tag.

DemiMarie avatar Aug 06 '17 20:08 DemiMarie