davidgranstrom / nvim-markdown-preview

Markdown preview for neovim using pandoc and live-server
GNU General Public License v3.0
105 stars 16 forks source link

How to show mathematical notation? #11

Closed tempegarit closed 2 years ago

tempegarit commented 2 years ago

Hi! Thanks for this great plugin, it's very useful.

I have this code in hello.md:

$a^2 + b^2 = c^2$

But the preview doesn't show the mathematical notation. It shows this: $a^2 + b^2 = c^2$

How can I get it to show the mathematical notation?

I know that it has something to do with katex but I don't know how to fix it.

Thanks.

davidgranstrom commented 2 years ago

Hi!

The markdown rendering will depend on your input format type g:nvim_markdown_preview_format, the default is to use github flavoured markdown but I don't think it supports mathematical notation such as in your example. It works here if I change the input format to "pandoc markdown" instead.

g:nvim_markdown_preview_format = 'markdown'
tempegarit commented 2 years ago

I've modify g:nvim_markdown_preview_format = 'markdown' and it still doesn't work.

Seems like it query katex from localhost. I got this error.

GET http://127.0.0.1:8080/usr/lib/nodejs/katex/dist/katex.min.js net::ERR_ABORTED 404 (Not Found)

Refused to apply style from 'http://127.0.0.1:8080/usr/lib/nodejs/katex/dist/katex.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Refused to apply style from 'http://127.0.0.1:8080/usr/lib/nodejs/katex/dist/katex.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Uncaught ReferenceError: katex is not defined at HTMLDocument.<anonymous>
davidgranstrom commented 2 years ago

Hmm, strange. According to pandoc's documentation a CDN should be used if the URL argument is missing. For me it embeds a valid URL to katex.min.js.

What is your pandoc version? I'm using 2.14.2.

From the pandoc user guide

--katex[=URL] Use KaTeX to display embedded TeX math in HTML output. The URL is the base URL for the KaTeX library. That directory should contain a katex.min.js and a katex.min.css file. If a URL is not provided, a link to the KaTeX CDN will be inserted.

tempegarit commented 2 years ago

Mine is 2.5.

$ pandoc --version
pandoc 2.5

Here's the screen shot:

1

davidgranstrom commented 2 years ago

@tempegarit Thanks for the info. I'd suggest that you update your pandoc binary and see if that resolves your issue (2.5 is from 2018 according to this page)

tempegarit commented 2 years ago

You're right. I installed pandoc using sudo apt install pandoc. I thought I got the latest version. Turns out pandoc installed from apt is an old version.

I installed the latest pandoc from the release page, which is 2.17. Now it works as expected. Thanks mate!

Antomek commented 2 years ago

Thanks for your work on this, @davidgranstrom!

I am having this exact issue. Pandoc is at its most recent version, and I have let g:nvim_markdown_preview_format = 'markdown' set. How would I even go about an attempt at figuring out what is wrong?

davidgranstrom commented 2 years ago

Hi @Antomek,

I would check in the log in the developer tools of your web browser first to see if it is related to the katex CDN (the issue @tempegarit had). Other than that, I would test by just converting the markdown using pandoc directly on the command line and see that you get the expected results. Please let me know if you find a solution, maybe there might be something we could add to the docs.

Antomek commented 2 years ago

Hello,

The problem is resolved, but I honestly have no idea what caused it in the first place. I checked pandoc which was working fine, so I simply reinstalled the plugin and that appears to have helped somehow. Sorry I can't be more helpful than that!