vim-markdown icon indicating copy to clipboard operation
vim-markdown copied to clipboard

Support Inline Equation and Equation Block

Open hupili opened this issue 12 years ago • 8 comments
trafficstars

It seems more and more people are combining markdown and mathjax now. This modification is adapted from the original code fence parsing rules. It gives better highlighting in vim.

Before (some normal texts are highlighted as italic )

b

After

a

Sine there are a lot _ (underscore) in math formula, it is essential to isolate them in order not to other texts.

hupili avatar May 11 '13 07:05 hupili

The modification is premature. I used the "Comment" option for the highlighting because it gives a better looking (different from code delimiter). Any idea to assign it a better group?

hupili avatar May 11 '13 07:05 hupili

+1, I was about to submit an issue about this:

math

but, except for the math with underscore which is not correctly displayed (and mess up the rest), does anyone knows why the red background on underscores, is it on purpose or error?

oblitum avatar May 28 '13 01:05 oblitum

@oblitum , The following two lines are responsible for that red block.

 97 syn match markdownError "\w\@<=_\w\@="
129 hi def link markdownError                 Error

So the syntax is marked as error, on purpose.. I don't know the reason, either.

hupili avatar May 28 '13 02:05 hupili

@hupili ok thanks.

oblitum avatar May 28 '13 02:05 oblitum

I'm guessing the underscores are marked as errors to highlight the problem that unescaped mid-word underscores cause some Markdown parsers to start italicizing (valid behavior per the original spec, but many parsers have deactivated it for being too annoying) - I've noticed that if I enter, say, a url that contains underscores, they get flagged, but then if I wrap the url in <> or []() (or escape the _ with \ if just regular text), the error goes away.

I find myself adding unneeded (for parsers I use) backslashes in front of mid-word underscores simply to make the error indication go away in the Vim syntax highlighting -- actually, I'd love to be able to stop doing that.

Personally, I'd love to see some hypothetical Markdown 2.0 decree that mid-word _ isn't part of italics (everywhere, rather than just in some parsers).

CarlRJ avatar May 31 '13 16:05 CarlRJ

@CarlRJ, thanks, good to know. Also, I'd like a Markdown 2.0 too, that would provide syntax for "please this is not markdown. parser, don't touch this!", both for paragraph (div-like) and inline (span-like). Would solve issue with embedding MathJax and other stuff inside markdown for all parsers, currently I must use kramdown because of that.

oblitum avatar May 31 '13 16:05 oblitum

Also, it's one of the reasons of this highlighter issue. Really, I can't undertand how markdown started without this simple but useful feature, would solve so much.

oblitum avatar May 31 '13 16:05 oblitum

Good to find this extended discussion. I'm also looking for MD 2.0. There are so many missing features in MD. I think the philosophy of MD is to only define syntax for 80% of your daily work. The rest 20% can always degrades to HTML. However, the original 80% daily work in the author's mind can only cover 50% of ours now, e.g. formula, table, etc.

I like the please this is not markdown. parser, don't touch this!-syntax mentioned by @oblitum . More generally, I would want a way to specify meta info. for a MD doc. One example: some people uses $ for inline math and some others use \( notation. Another example: MD has long been questioned due to * and _; Apparently they are not rare enough characters to use a delimiter. No matter how hard the original designer tries, he/she will miss some scenarios. Those characters are rare for some people but very common for others. I think a per-doc specification via meta info will help.

Leave some pointers for my trial on MD:

  • evermd is initiated last year when I switched my daily work to MD. At first, I only want to collect some "best current practices", like the how to generate MD headings Taglist . Later I find MD is so limited in function and did some extensions . That was before I massively study what others have done (e.g. different parsers) so the extensions are quite naive and the syntax is far from concise. Some notable features may be variable substitution; template embedding; tex style formula and table.
  • As to mathjax, people all over the world are trying hard to integrate it with MD. e.g. this discussion . Some clumsy solutions are to insert <span> or <div> to wrap your formula. Some parsers can support the Mathjax notation but no ideal (e.g. generate pics). At last, I decide to solve this by two steps: 1) wrap fragile formula with code syntax that all parsers support; 2) use JS to substitute them back (if $ symbol if found at the boundary). very short code diff . This is the best I found so far: 1) work with all parsers; 2) without JS, it degrades to code segment, at least giving some information; 3) with JS, it renders well.

hupili avatar Jun 01 '13 03:06 hupili