vscode-markdown icon indicating copy to clipboard operation
vscode-markdown copied to clipboard

Equation cannot support pandoc-eqnos or pandoc-crossref

Open philher opened this issue 4 years ago • 5 comments

Problem

Problematic behavior

Using pandoc pandoc-crossref or pandoc-eqnos equation identifiers breaks markdown parsing, as shown in the screenshot below. The outline and code folding are also broken in the same way (Title 2 is not considered a header). Syntax highlighting is correct.

VSCode with Markdown All in One

VSCode extension rendering

Outline

Syntax highlighting

Possibly related to #346 Equation identifier using pandoc-eqnos breaks syntax highlighting.

Expected behavior

Markdown Preview Enhanced (MPE) default renderer or with pandoc work as expected, as shown in the two screenshots below:

MPE, Pandoc renderer and --filter=pandoc-crossref filter

MPE pandoc rendering

MPE, default renderer

MPE default rendering

Furthermore, VSCode without the extension also exhibits the expected behavior:

VSCode no Markdown All in One

VSCode no extension

Outline no extension

Environment

  • VSCode version: 1.51.1
  • Markdown All in One version:
    • 3.4.0 from VSCode marketplace
    • Latest development build
  • OS: Ubuntu 20.04 LTS

How to reproduce

The previous screenshots are the results of the following snippet:

# Title 1
$$
a = b
$${#eq:e}

Refer to [@eq:e]

# Title 2

philher avatar Dec 08 '20 11:12 philher

Duplicate of #194

Lemmingh avatar Dec 08 '20 14:12 Lemmingh

Let me briefly explain what happens behind the scene:

  • The outline and folding are currently provided by VS Code.
  • VS Code relies on markdown-it.
  • VS Code loads markdown-it plugins first.
  • Our extension contributes a plugin called markdown-it-katex.
  • markdown-it-katex currently requires:
    • A line begins with $$ is the beginning of a math_block.
    • A line ends with $$ is the end of a math_block.

Thus, you're right; the parsing is changed when our extension is enabled.

In your example, markdown-it-katex regards line 2 as the beginning of a math_block. Then, it looks for a line that ends with $$. However, not found. So, it marks line 2 to the end of the file as one math_block.


I understand that this design breaks your experience.

I'm sorry to say that we are hesitant. Changing it is complex, and will be a breaking change. https://github.com/yzhang-gh/vscode-markdown/issues/839#issuecomment-719199801

We are still collecting user feedback.

Lemmingh avatar Dec 08 '20 15:12 Lemmingh

Thanks for the detailed feedback @philher, and also nice summary @Lemmingh.

I cannot think of a good solution (even after 2 years). So just use the MPE preview if you need these pandoc options. And you can still have the other features from our extension.

yzhang-gh avatar Dec 08 '20 16:12 yzhang-gh

Thanks for the explanation @Lemmingh (and obviously, thanks @yzhang-gh for creating this extension).

Following your explanations, I looked around at the options and found that setting "markdown.extension.math.enabled": false surprisingly does not remove the highlighting nor the completion of the latex math commands inside the block, but solves the outlining and code folding issues.
It does however disable, as expected, the math rendering in VSCode preview. I can confirm that your extension is the one that provides highlighting and completion.

This is absolutely fine with my use case, as it allows me to use the editing features of your extension with MPE and pandoc to render the preview.


As I saw that MPE provides the option to set custom math block delimiters, maybe it would be possible to provide a setting for your extension to allow arbitrary delimiters ? If it was possible to allow markdown-it-katex to use arbitrary delimiters and also for these delimiters to contain wildcards, one may still keep the default behavior, but also add something like the following to their user settings:

"markdown-preview-enhanced.mathBlockDelimiters": [
        [
            "$$",
            "$${#eq:*}"
        ]
    ]

Maybe it is too complex to implement, it is only something that crossed my mind.

philher avatar Dec 08 '20 16:12 philher

Following your explanations, I looked around at the options and found that setting "markdown.extension.math.enabled": false surprisingly does not remove the highlighting nor the completion of the latex math commands inside the block, but solves the outlining and code folding issues.

Aha, it makes sense as that option only disables markdown-it-katex. Perfect!

Maybe it is too complex to implement, it is only something that crossed my mind.

Thanks. I'm not very sure but it doesn't seem to be an easy thing.

yzhang-gh avatar Dec 08 '20 16:12 yzhang-gh