# How to show math equations or formula in markdown file

I like to write notes in markdown file. Most of the times my notes are about coding, but sometimes I need to write some math equations or symbols. I would like to see the equations directly in the vim, so I add the following lines in my vimrc:

set conceallevel=2
set concealcursor=


However, when I write the following content in my .md file, it is not converted into math equations:

$\sqrt{X^2} + \sum{X}$


How could I write markdown notes in vim as I did in typora, with real-time format conversion and math symbols support?

• Have you considered using TeX/LaTeX or digraphs? – Herb Jan 24 '18 at 5:45
• what do you mean by Tex/Latex? I would like to insert some math equations in markdown. Could vim show math symbol directly if I use Tex/Latex completely? @HerbWolfe – CoinCheung Jan 24 '18 at 5:52

Mathematical equations cannot be displayed in Vim in this way: Vim has no means of rendering them, as @BLayer explains in his answer.

However, mathematical symbols you can indeed display using Vim's conceal feature, as you suggest in your tags. The following commands will replace various mathsy HTML entities with their corresponding Unicode characters:

:syntax match MathSymbols /\V&radic;/ conceal cchar=√
:syntax match MathSymbols /\V&sup2;/ conceal cchar=²
:syntax match MathSymbols /\V&sum;/ conceal cchar=∑
:set conceallevel=1


So that:

&radic;x&sup2; + &sum;x


Will display in Vim something like:

√x² + ∑x

You could of course just type those Unicode symbols in directly, instead! (Either using your operating system's input features, or Vim's digraphs feature.)

N.B. Markdown itself does not allow equations to be entered in this way. Typora appears to have added support of these using MathJax.

My interpretation is that the OP is looking for rendering of markup into fancy, graphical depictions of equations and formulae. If instead the question is about simple substitutions of Unicode mathematical characters then @Rich has a nice answer.

vim is a text editor. It can display parallel, uniformly sized and spaced rows of Unicode characters and nothing more. Just like what you're reading now. The best you can do with markup languages is edit them and, possibly, launch an external command that renders them into a format that you'll need to read in an external viewer (e.g. browser, PDF viewer, man, etc.).

In fact, that's exactly what I do with asciidoctor. I write my notes using AsciiDoc markup in vim. I have vim shortcuts to external commands that render the markup as HTML then launch/load my browser with that HTML.

(The next level of sophistication is to set up live preview. We put vim and the viewer app side by side then use a file monitoring tool that upon seeing changes to the markup file renders and reloads the viewer automatically. That's as close to live editing of markup as you'll get with vim.)