vim-pandoc / vim-pandoc-legacy

[UNSUPPORTED/use vim-pandoc/vim-pandoc] vim bundle for pandoc users
143 stars 23 forks source link

displayed LaTeX equations are not highlighted correctly #92

Closed allefeld closed 10 years ago

allefeld commented 11 years ago

When I include a "displayed" LaTeX math environment in the Markdown text,

$$
2+2
$$

it is not highlighted as math. It is only recognized in the form

$$2+2$$

Since the former is the normal way to write displayed math in LaTeX, and since the pandoc manual does not have any special regulations on this, I'd propose to adapt the syntax definitions to cover this.

Side note: I've seen the discussions on mixing different kinds of syntax highlighting, and would like to say that for me it would be sufficient if the whole math environment $-$ or $$-$$ is highlighted, highlighting of the contained LaTeX syntax is not essential imho.

Asymp commented 11 years ago

I have a little change which will highlight multi-line math.

To use it, just modifier "syntax/pandoc.vim" file.

Find this line:

" Math Tex
syn match pandocLatex /\$.\{-}\S\$/ contains=@LATEX

Add another line below them:

syn match pandocLatex /^\$\$\n\=\S\_.\{-}\$\$/ contains=@LATEX

But make sure there is no empty line or space between $$ and the following equations.

I am not good at Regex, so this is the best i can do. Maybe author will have better solution?

allefeld commented 10 years ago

Hi Asymp,

thanks for trying to help. I'm not a regexp wizard either, but I came up with these two separate expressions.

For inline math: /\$[^ $][^$]*\$/ – a region between two $s, where the first character inside is not a space.

For display math: /\$\$\_[^$]\+\$\$/ – a region between two $$s that can stretch across lines and that has to contain at least one character.

What do you think? I'm not sure what you regexp does...


Offtopic: I'm wondering whether the developers are still active on this project. I found a few more bugs in the syntax highlighting:

Not sure whether I should properly report them.

Asymp commented 10 years ago

Hi, Murfit

Your regexp for display has a small problem. If the $$s are all in pair in the document, this is OK. But considering some unpaired $$ for what ever reason:

Some thing $$  something

normal text

$$
2+2
$$

It will highlight the normal text mistakenly.

In my method. \n\= matches 0 or 1 newline, then followed by some non-whitespace character \S, so ^\$\$\n\=\S will match the start of math like:

$$2+2
...

or

$$
2+2
...

But not normal text like:

$$

2+2
...

Anyway, i think they are many different ways to match what you want. So you can first try in vim by searching them.

Other bugs you have mentioned does not bother me so much. So i am just ignoring them. I think you can talk with the author or hack by yourself.

fmoralesc commented 10 years ago

Hi. I was mantaining the syntax file, but for several reasons had to leave it aside. It has many embarrassing bugs! Anyway, I'm working on it at http://www.github.com/fmoralesc/vim-pandoc-syntax (will move into the org eventually, for now it is not stable enough).

As for this bug, the better option is to change the syntax match rule for a region rule, imho. I'll see what I can do.

fmoralesc commented 10 years ago

I'm working on this issue now in the other repo. As for the other bugs mentioned here, they are all fixed there (I think).

PeterlitsZo commented 4 years ago

Hi. I was mantaining the syntax file, but for several reasons had to leave it aside. It has many embarrassing bugs! Anyway, I'm working on it at http://www.github.com/fmoralesc/vim-pandoc-syntax (will move into the org eventually, for now it is not stable enough).

As for this bug, the better option is to change the syntax match rule for a region rule, imho. I'll see what I can do.

Hi, fmoralesc

the link is breaked, do you mean https://github.com/vim-pandoc/vim-pandoc-syntax?

but the way, if i indent my list, the second line and below will not be hightlighted. It worry me. Could you give me some tips?(if I find the way, I will edit this. Thanks)

pic


I think I get the way: If I indent 4 space, then it will lost its color(but why?). I delete a space then it work well ^_^