goessner/mdmath

Please persist macros with KaTeX globalGroup

chrisyeh96 opened this issue · 2 comments

Summary

Macros such as $\newcommand{\ra}{\rightarrow}$ are not persisting between math blocks.

Steps to reproduce

  1. Install the latest version of VSCode (1.58).

  2. Disable VSCode's built-in markdown math renderer: uncheck the Markdown > Math setting checkbox.

  3. Create a new markdown file in VSCode.

  4. Write the following:

    $\newcommand{\ra}{\rightarrow}$
    
    $\ra$

I would like for this to work, but it currently does not. However, I believe that by using KaTeX's globalGroup option, it should be able to work.

Environment

- OS: Windows 10 21H1 64-bit
- mdmath v2.7.4
- VSCode 1.58 (with the native `Markdown > Math` setting disabled)
ickc commented

This is already doable. In settings.json:

    "mdmath.katexoptions": {
        "globalGroup": true,
    },

I added

    "mdmath.katexoptions": {
        "globalGroup": true,
    },
    "markdown.math.enabled": false,

to my settings.json and reloaded vscode, but markdown still does not display the rightarrow correctly:

$\newcommand{\ra}{\rightarrow}$

$\ra$

Edit: If I also add "markdown.extension.math.enabled": false to settings.json, then the $\ra$ displays correctly. However

  1. If I re-render the preview the $\newcommand{\ra}{\rightarrow}$ displays in red as invalid latex, I believe because the command still exists from the previous rendering
  2. I still get an error when using these commands in a python notebook: ParseError: KaTeX parse error: Undefined control sequence: \ra at position 1: \ra.

This may be related to this katex issue.

Environment

- OS: Ubuntu 20.04.4 LTS
- mdmath v2.7.4
- VSCode 1.64.2 (with the native `Markdown > Math` setting disabled)