Vscode-markdown: KaTex Math render problem

Created on 17 Oct 2018  ·  17Comments  ·  Source: yzhang-gh/vscode-markdown

What is the problem?

This is a small problem. This code:

$\text{\`{a}}$ <code>\\`{a}</code>

on katex.org should be rendered like this:

image

However, I got this:

image

How can I reproduce it?

Write in your md file:

|||||
|:---------------------|:---------------------|:---------------------|:-----
|$\text{\'{a}}$ `\'{a}`|$\text{\~{a}}$ `\~{a}`|$\text{\.{a}}$ `\.{a}`|$\text{\H{a}}$ `\H{a}`
|$\text{\`{a}}$ <code>\\`{a}</code>|$\text{\={a}}$ `\={a}`|$\text{\"{a}}$ `\"{a}`|$\text{\v{a}}$ `\v{a}`
|$\text{\^{a}}$ `\^{a}`|$\text{\u{a}}$ `\u{a}`|$\text{\r{a}}$ `\r{a}`|

Is there any error message in the console?

No.

All 17 comments

Oh, it seems we should add another \(to https://raw.githubusercontent.com/Khan/KaTeX/master/docs/supported.md):

<code>\\\`{a}</code>

It is all about escaping the special characters \ and `.

For inline code span, Markdown parser does seem to escape them. So you need to use \\ to denote \.
And for code block, it seems that we can use \ without escaping.

I find math rendering in vscode-markdown is really powerful! Thanks for your great work, and based on your project, I create a plugin for rendering KaTex in docsify, hope it helps.

😀

Hi, I found this problem can be solved by setting html option to true when using markdown-it:

markdownit({html: true})
  .use(markdownitKatex, { "throwOnError": false });

In this way, the \ in code tag will not be escaped and ` will be escaped.

For example:

<code>`</code>

will be rendered as:

`

However, the following:

<code>\</code>

will be rendered as:

image

The html option is already true. (See the source code (for vscode preview), source code (for exported HTML))


<code>`</code>

looks no problem because you are lucky that there is no following ` character to form an inlne code span. If you try

<code>`</code> and `hello`

Observe the above Markdown syntax highlight and the markdown-it demo

image
image

both ` and \ need to escape

<code>\`</code> and `hello`

So theoretically, it should be <code>\\\`</code> rather than <code>\\`</code>

Thanks a lot for your plain explanation!

I find another problem with \neq, with following equation:

$$

a \neq b

$$

is rendered as:

20181029165836.png

it should be rendered as:

image

I also noticed it and suspects it to be a vscode issue. Let's tract it in #252.

I encountered another problem with KaTeX rendering (Though I guess it is a parser thing).

This will work:

Does this ${c}^{2} = {a}^{2} + {b}^{2}$ work?

While this won't:

Does this $ {c}^{2} = {a}^{2} + {b}^{2} $ work?

Mind the Gap (Space) after and before the $ mark.
Could you please let the parser identify ti as Math?

I know many parses do that in order to prevent cases of using the USD sign.
Yet in LaTeX it is acceptable hence to keep compatibility I'd let the option do it here as well.

Even if it is an Opt In option in preferences.
So people who asks for LaTeX compatibility will know to use this option and escape the USD sign.

I have many many MD documents that MarkDownEnhanced display correctly while this won't because of that (Also MarkDown Preview in Sublime Text).

Thank You.

I know many parses do that in order to prevent cases of using the USD sign.

You are right. https://github.com/waylonflinn/markdown-it-katex#syntax

I am afraid I cannot do much here.

@yzhang-gh , Is that the Math Parser you're using for Math?

Yes

Maybe you can use https://github.com/classeur/markdown-it-mathjax for MathJaX.
Also in order to support spaces after $ all needed is to edit this line: https://github.com/classeur/markdown-it-mathjax/blob/master/markdown-it-mathjax.js#L77

Of course. Almost all issues can be solved programmatically.

There are various features people would love to add, like many Markdown dialects, different TOC link styles (GitHub, GitLab etc.). You request (MathJax, $ rule) is one of them.

As a maintainer, I can only do some of the high-priority features (with many votes), and avoid modifying upstream packages which will increase the maintainance effort (some of them have not been updated since 2016).


If you really want to solve a problem, there are always 3 ways.

  • do it yourself (although a single person's ability is usually limited)
  • find many people who also have this problem, hopefully one of them can get it resolved
  • find a workaround (change the problem itself)

I am not saying which one is better than the others. But I am sure not all issues can be resolved. (Look VSCode's issue page)
Welcome to the real world. Good luck.

My friend,
I didn't come with demands.
No need for a wake up call. I know reality just as you.

I suggested a feature, I gave a way to do both (MathJaX support and supporting space after $).
It is up to you what to do with it.

My logic is addressing Students and other people using LaTeX.
If you feel this ignite motivation on your side, perfect.
If not, I thank you for what you did so far.

As for me, I suggested a contribution of ~Hour of coding.
Not because it is an hour work but in order to show I do appreciate your time and would like to show it.

Again, thank you for this nice extension.
On my side, given a full LaTeX support it would have been the perfect student replacement for LaTex.

As for me, I suggested a contribution of ~Hour of coding.
Not because it is an hour work but in order to show I do appreciate your time and would like to show it.

I see. Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

smallprogram picture smallprogram  ·  3Comments

deanishe picture deanishe  ·  4Comments

rdhar picture rdhar  ·  4Comments

akshaybabloo picture akshaybabloo  ·  3Comments

lotapp picture lotapp  ·  3Comments