yzhang-gh / vscode-markdown

Markdown All in One
https://marketplace.visualstudio.com/items?itemName=yzhang.markdown-all-in-one
MIT License
2.93k stars 325 forks source link

Highlighting and auto-suggestion for math spans containing line endings #636

Open ichirou2910 opened 4 years ago

ichirou2910 commented 4 years ago

What is the problem?

I want to request the hightlighting and auto-suggestion of a math block that starts and ends with a single dollar sign (not inline math) just like normal math block between 2 double dollar signs

How can I reproduce it?

Put a math block between 2 single dollar signs so that it's left aligned

image

Is there any error message in the console?

none

yzhang-gh commented 4 years ago

Thanks for the feedback. I even didn't know that (single dollar blocks) is a valid syntax.

Lemmingh commented 4 years ago

“Single dollar signs math block” is actually inline math or bug.

Simply check the HTML output. Display math areas (math blocks) are wrapped in <span class="katex-display">, while inline math areas are not.


Before proceeding, here is an essential problem:

What's the definition of “space character”?

This extension now depends on markdown-it-katex which follows pandoc's convention:

Anything between two $ characters will be treated as TeX math. The opening $ must have a non-space character immediately to its right, while the closing $ must have a non-space character immediately to its left, and must not be followed immediately by a digit. Thus, $20,000 and $30,000 won’t parse as math. If for some reason you need to enclose text in literal $ characters, backslash-escape them and they won’t be treated as math delimiters.

Traditionally, line feed is regarded as a kind of space character. However, markdown-it-katex currently allows one line feed next to the $, which leads to “single dollar signs math block”:

https://github.com/yzhang-gh/markdown-it-katex/blob/4205ef9a4cea47113e9a2a055522421740c9d1c5/index.js#L23-L34

(This is just a piece of the code. The whole problem may be related to more parts.)

We have to first make it clear whether it's a bug or feature.

yzhang-gh commented 4 years ago

I think it is more of an unexpected "feature" than a bug. But I do recommend using $inline math$ instead of multiple lines.