Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim syntax and Latex math inside markdown

I write documentation in markdown using ViM and I also put math using the latex $$ symbol (I compile using pandoc). The thing is that ViM syntax wouldn't ignore the underscores _ inside the dollar symbols and it is pretty annoying. For instance if I write this:

$$ a_1 = 0 $$

Then Vim will highlight all the following text as italics due to to the underscore used.

How can I change that?

Also it would be nice if I could highlight what's inside $ with a different format.

like image 704
sharp Avatar asked Sep 30 '15 12:09

sharp


1 Answers

I have put these lines in my .vimrc. It works for inline math on the same line and block-mode math.

" This gets rid of the nasty _ italic bug in tpope's vim-markdown
" block $$...$$
syn region math start=/\$\$/ end=/\$\$/
" inline math
syn match math '\$[^$].\{-}\$'

" actually highlight the region we defined as "math"
hi link math Statement

Edit: I've since written a blog post called Vim syntax highlighting for Markdown, Liquid and MathJax.

like image 73
Scott Avatar answered Oct 03 '22 00:10

Scott