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

Global macro definitions should persist between math expressions by default #583

Open PaperCube opened 4 years ago

PaperCube commented 4 years ago

What is the problem?

\global\def doesn't persist between math expressions as described in Katex Official Documentation unless at least one macro is defined in Settings.

How can I reproduce it?

Delete all entries of "markdown.extension.katex.macros" in settings.json, reload window, then create a markdown file with content as below:

$$
\global\def\ud{\mathrm{d}}
$$

$$
\ud
$$

\ud is shown red in the preview panel.


Then, add entry in settings.json:

"markdown.extension.katex.macros": {
        "\\whatever":"\\text{whatever}"
}

Reload window, and a roman d is shown in preview panel correctly.

By the way, it seems that defining macros with arguments in settings.json isn't supported.

Is there any error message in the console?

Seemingly there aren't any error messages related to this plugin in the console.

yzhang-gh commented 4 years ago

Thank you.

According to the description "unless at least one macro is defined in Settings", I guess we should still pass an empty object {} when there are no user macros.

https://github.com/yzhang-gh/vscode-markdown/blob/9805028e2c3f383a2ff909fd6b506ab4cbedd623/src/extension.ts#L20-L25

To my memory, it causes another issue for users who don't use macros. I am not very sure but someone made some tests if interested.