I often write non-trivial mathematical formulas inside Markdown documents, and having them syntax-highlighted would really help.
In Markdown, LaTeX math formulae are denoted:
$x^2$
and $$x^2$$
, and are escaped as \$x\$
and \$\$x\$\$
.
Markdown math formulas are rendered via MathJax (to match future googlers' keywords).
If I use vim-markdown to syntax highlight the Markdown, how can I use vimtex to syntax highlight only the text inside the formulae?
Note: I only want the text inside $
to be treated differently if the filetype is markdown
or foobar
(future proofing against my lack of VimL).
Bonus: I'd like the $
delimiters themselves to use the syntax highlight group Statement
.
Hints:
I think these are along the right path, but I couldn't work out how the solution from them:
- Perhaps vim-SyntaxRange would help. (I couldn't work out how to set it up with the delimiters.)
- vim wikia's Different syntax highlighting within regions of a file
-
" Block math. Look for "$$[anything]$$" syn region math start=/\$\$/ end=/\$\$/ " Inline math. Look for "$[not $][anything]$" syn match math_block '\$[^$].\{-}\$'