Add math-block notation#190
Add math-block notation#190heavywatal wants to merge 8 commits intoburodepeper:masterfrom heavywatal:math-block
Conversation
|
Cool! As I feared, the CI tests failed. Are you familiar with that? I'd like to have a couple new ones added for these new math notations as well. |
|
Now I think <div>\[
a = \sum_{i=1} \frac 1 i
\]</div>Where should I add the pattern for this? maybe languege-html package, or here? |
|
Thanks for your efforts so far! I'm a little busy at the moment, so I haven't had time to review your PR in depth yet. From what I could see, you haven't added any spec that tests for situations that it shouldn't match. Could you add a couple of those? Think about situations where a similar notation might be used, or the good notation with a typo, etc. This will help cover any regressions in the future. The pattern you mentioned should go into language-html. Although I'm not sure why it is needed. Rather, it seems that it shouldn't be needed. Maybe the order in which the patterns are matched might also solve this issue. If it does, be sure to leave a comment describing so. |
|
Please take your time. I am happy with using my branch on Atom for the time being. I guess the matching order is not the only problem here because the required number of backslashes is different: |
| { | ||
| name: 'block.math.markup.md' | ||
| begin: '(\\${2})' | ||
| end: '(\\${2})(?:.*)' |
There was a problem hiding this comment.
Thank you for the suggestion, and sorry for my late reaction. I have just fixed it accordingly.
| 1: name: 'punctuation.md' | ||
| endCaptures: | ||
| 1: name: 'punctuation.md' | ||
| } |
There was a problem hiding this comment.
This is the correct number of backslashes, four \ to represent a single literal \, and then two \ to escape the [.
If it's not showing up correctly, it's the fault of language-latex and their use of $base. See #226, area/language-latex#185.
On my branch of language-latex with the changes mentioned in area/language-latex#185, I see:
|
I think the code looks fine but it depends on area/language-latex#185. Otherwise the latex highlighting will be off. |
What flavor of Markdown are you using? By default Pandoc supports only There are non-Pandoc extensions for both
I'm surprised to see that there's actually no definition for math in the Commonmark spec. So which of the following should we color as math environments?
|
|
Oh, I didn't know that pandoc has such options. How does pandoc process equations? I am using Hugo/Blackfriday for HTML generation, and MathJax for equation rendering. Hence for me it is not surprising that CommonMark does not have math specs. It is MathJax's job. What Markdown has to do is generating proper HTML code to be interpreted by JavaScript. From that point of view, According to In summary, the following patterns in Markdown should be colored IMO: Using |
If converting from markdown to HTML, it converts to the appropriate HTML and uses either MathJax or KaTeX. If converting to PDF/LaTeX, it converts to the appropriate LaTeX commands and then optionally compiles the LaTeX to PDF. I'm in agreement for Supporting I'm also in agreement for the For example, this raises an error with So if we want to support {
begin: '\\begin\\{(align|equation|multline|split|gather|alignat|aligned|gathered|eqnarray|array|tabular)(\\*)?\\}'
end: '\\end\\{$1\\}'
}As an aside, my attitude about Commonmark and Math is this:
|
Got it.
No. Blackfriday knows nothing about math equations, as CommonMark does. It just generates HTML code like this: which is later processed by MathJax, KaTeX, or any JavaScript libraries. I totally agree with you and your quote: “you don’t have to do anything with this, but you must still parse it correctly”.
Agree. But I am not sure which environments should be included. For example, in the list you suggested, |
|
I didn't take the time to see which of those were still used. It's probably easier to take a few minutes and include a good list in this PR. |
|
OK, I have just added simple ones: I excluded |
|
Alternatively, similar to how we include all rules from HTML, we could include all rules from latex after the Markdown rules. But I'm guessing that would have more side effects |
|
I like the idea, and it seems to be a powerful and beautiful solution, but far beyond my ability and resource. |
|
No I mean instead of writing them all ourselves, as long as the user has language-latex installed, we can just write {include: 'text.tex.latex'}And all of the latex highlighting rules get applied after the Markdown ones (depending on where that line is placed) |
|
Yes, I think I see your point. I mean considering the side effects of including whole language-latex functions will be much harder than keeping math block grammars by ourselves. LaTeX is not just about math equations, but here we should limit the scope to math blocks. |
Common workaround for markdown parsing, e.g., <div>\[ \]</div>, gets also matched as math block.




As discussed in #189, the following notations are added to math-block notation: