Skip to content

Add Markdown support by markdown-it-texmath#56

Open
PaulEibensteiner wants to merge 3 commits intomattbierner:masterfrom
PaulEibensteiner:add-markdown-support
Open

Add Markdown support by markdown-it-texmath#56
PaulEibensteiner wants to merge 3 commits intomattbierner:masterfrom
PaulEibensteiner:add-markdown-support

Conversation

@PaulEibensteiner
Copy link

@PaulEibensteiner PaulEibensteiner commented Oct 5, 2024

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

@Christopher-K-Long
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants