3

I am trying to create new commands for markdown in an ipython notebook file in VSCode, but am having trouble doing so

This post shows an example which (kinda) works in jupyter notebook:

$\newcommand{\vect}[1]{{\mathbf{\boldsymbol{{#1}}}}}$
This is the vector $\vect{x}$.

But pasting this exact code in VSCode, I get the error:

ParseError: KaTeX parse error: Undefined control sequence: \vect at position 1: \vect{x}.

So it seems the new command does not get created. Am grateful for any solution

Eknoma
  • 51
  • 3

2 Answers2

1

Issue 125425 opened by Chandresh Pant and mentioned in the comments seems to be solved for VSCode 1.69 (June 2022)

See PR 148006 and commit acb156d:

In order to make macros defined by the author persistent between KaTeX elements, we need to pass one shared macros object into every call to the renderer.
KaTeX will insert macros into that object and since it continues to exist between calls, macros will persist.

See KaTeX docs.

https://user-images.githubusercontent.com/1220427/164980400-148fbeea-c928-44eb-819e-dd74179ab16b.png

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Try the Markdown + Math extension by Stefan Goessner which supports macros. It works really well on my setup.

We can also define macros in the user settings, e.g.

"mdmath.macros": {
    "\\vect" "{\\mathbf{\\boldsymbol{{#1}}}}"
}

or in a separate json file as follows.

"mdmath.macroFile": "/path/to/macros.json"
David Scholz
  • 8,421
  • 12
  • 19
  • 34