Naereen / StrapDown.js

:sparkles: StrapDown.js is an awesome javascript tool to quickly publish nice-looking web-pages in pure Markdown :pencil:, with no server side compilation :sunglasses: →
https://naereen.github.io/StrapDown.js/
MIT License
108 stars 45 forks source link

Parsing AsciiMath #9

Closed sebi5361 closed 4 years ago

sebi5361 commented 4 years ago

As StrapDown.js is using MathJax that can parse natively AsciiMath is there an easy way to render AsciiMath notation formulas in StrapDown.js?

Naereen commented 4 years ago

Hi @sebi5361. I never heard of AsciiMath. Thanks for asking. From what I see about AsciiMath, the delimiter has to be ` ie backticks, but that's already used by StrapDown.js's MarkDown parser, which renders MarkDown to HTML before latting MathJax render maths equations. In this example file (might take a while to be updated, it's using GitHub pages which is not instantaneous, see this page for a preview from my website), I tried to write a couple of equations in AsciiMath syntax like \Delta = b^2-4ac but it is rendered as code (code <-- like here in this comment), not Math.

Apparently one can change the delimiters of AsciiMath to $...$ instead of backticks. (from the MathJax documentation) I'll try this.

Naereen commented 4 years ago

I updated my example, by adding the suggested configuration line

<script type="text/javascript">
window.MathJax = { loader: { load: ['input/asciimath'] }, asciimath: { delimiters: [['$','$'], ['`','`']] } });
</script>

and trying to write math using AsciiMath notation between $dollars$ or `backticks`, but both of them do not work.

Sorry, I don't know what to try more.

sebi5361 commented 4 years ago

I guess making AsciiMath work with StrapDown.js would take too much effort as this straightaway approach failed... Too bad )-: Thanks anyway

Naereen commented 4 years ago

Yes sorry I don't know what else to try. But honestly, from what I just read about AsciiMath, I don't see the advantages it could have over plain LaTeX.

sebi5361 commented 4 years ago

I understand your argument as you are familiar with Latex, but as I don't have a lot of experience with it I am seduced by the much cleaner syntax of AsciiMath.

`$H_2O$`

Maybe mixed delimiters could do the job if parsed in a right order?

sebi5361 commented 4 years ago

This notation is used in some advanced Markdown + mathematical markup language parsers:

Inline AsciiMath equation: `@(1/2[1-(1/2)^n])/(1-(1/2))=s_n@`

or:

```AsciiMath
oint_Cx^3 dx+4y^2 dy

2=(((3-x)xx2)/(3-x))

sum_(m=1)^oosum_(n=1)^oo(m^2 n)/(3^m(m3^n+n3^m)

Maybe it can give us some hints...
Naereen commented 4 years ago

Oh smart. Escaping backticks works, for inline AsciiMath only! See this example. Capture d’écran de 2020-10-10 15-22-50 All the other things I tried fails (dollar signs for inline, double dollars for display, three backticks or escaped backticks with AsciiMath code block, etc)

Naereen commented 4 years ago

I also added your four examples, which can fail if the are not escaped with a backslash: same issue as using LaTeX with MathJax, as the Markdown parser converts to HTML before loading MathJax, it interprets ` text surrounded by underscores _` as italic!

sebi5361 commented 4 years ago

It's great to have inline equations already!

I really have no clue how the parser(s) work(s), but maybe we could try some nested Markdown code blocks similar to `` ` `` that displays ` once rendered: