Parsing AsciiMath #9

Closed
opened 2020-10-10 13:01:36 +02:00 by sebi5361 · 9 comments
sebi5361 commented 2020-10-10 13:01:36 +02:00 (Migrated from github.com)

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

As StrapDown.js is using [MathJax](https://mathjax.org/) that can parse natively [AsciiMath](http://asciimath.org/) is there an easy way to render AsciiMath notation formulas in StrapDown.js?
Naereen commented 2020-10-10 13:20:03 +02:00 (Migrated from github.com)

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.

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](https://naereen.github.io/StrapDown.js/example11.html) (might take a while to be updated, it's using GitHub pages which is not instantaneous, see [this page](https://perso.crans.org/besson/publis/StrapDown.js/example11.html) 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](https://docs.mathjax.org/en/latest/input/asciimath.html#asciimath-delimiters)) I'll try this.
Naereen commented 2020-10-10 13:25:09 +02:00 (Migrated from github.com)

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.

I updated my example, by adding the suggested configuration line ```html <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 2020-10-10 13:30:48 +02:00 (Migrated from github.com)

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

I guess making AsciiMath work with StrapDown.js would take too much effort as this straightaway approach failed... Too bad )-: Thanks anyway
Naereen commented 2020-10-10 13:56:39 +02:00 (Migrated from github.com)

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.

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 2020-10-10 14:11:22 +02:00 (Migrated from github.com)

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?

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 2020-10-10 14:50:36 +02:00 (Migrated from github.com)

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...

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 2020-10-10 15:25:06 +02:00 (Migrated from github.com)

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)

Oh smart. Escaping backticks works, for *inline* AsciiMath only! See [this example](https://perso.crans.org/besson/publis/StrapDown.js/example11.html). ![Capture d’écran de 2020-10-10 15-22-50](https://user-images.githubusercontent.com/11994719/95656127-7aa3cb80-0b0c-11eb-8f75-c0bc4de69284.png) 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 2020-10-10 15:29:44 +02:00 (Migrated from github.com)

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!

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 2020-10-10 16:00:08 +02:00 (Migrated from github.com)

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:

``````
`````
````
```
```
````
`````
``````
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: ``````` `````` ````` ```` ``` ``` ```` ````` `````` ```````
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Lerking/StrapDown.js#9
No description provided.