vscode-docs-view icon indicating copy to clipboard operation
vscode-docs-view copied to clipboard

Add Markdown support by markdown-it-texmath

Open PaulEibensteiner opened this issue 1 year ago • 1 comments

TLDR: Adds latex math support to the preview using markdown-it, markdown-it-texmath and katex (using katex css).

The default preview does not support math because of latency issues that the visual studio code team does not want on hover windows. Since this docs-view is not a hover, I think the latency is not an issue. One downside is, that we need to use a different markdown library than visual studio code uses for the preview, since marked does not support math. This may lead to unintentional differences between the hover view and the panel view.

Another unfortunate current state is that Pylance converts reST math (the standard for docstrings) to markdown code blocks. Therefore this will not be able to render reST math in the default state, because there is no way for this extension to differentiate between a normal code block and a code block that was converted from math. There are two workarounds: 1. Use the Jedi language server, which correctly returns reST math as markdown math. 2. Write your documentation in markdown, s.t. the language server does not alter the markup since it expects reST.

This is potentially a solution to this vscode issue, this reddit thread, this stackoverflow question and even potentially for some people currently using pycharm, so I think even with the caveats mentioned it is a valuable contribution for many scientific and mathematic programmers out there.

Example previewing scipy.special.softmax

image

PaulEibensteiner avatar Oct 05 '24 09:10 PaulEibensteiner

Using this branch, I noticed a couple of bugs. As a disclaimer, I have not tried the main branch as I only wanted the extension for the equation support. The bugs are:

  1. Inline maths has large spacings around it: image The portion of the docstring that generated this was components $\omega_j$ and amplitudes.
  2. There are <ul> tags in the output: image The portion of the docstring that generated this was:
Parameters
----------
spins : int
    The number of spins in the chain

Christopher-K-Long avatar May 17 '25 12:05 Christopher-K-Long