Live Preview of LaTeX in Vim

Last updated on October 1, 2016

Vim, as a highly configurable and customizable editor, already has a powerful Vim-LaTeX plugin. However, I don’t like the lack of live preview feature. For this reason, I developed a plugin called vim-latex-live-preview last year. Although it currently can’t handle complex situations such as multiple tex files, it could basically handle single tex file project well (with or without BibTeX, thanks to Asis Hallab).

Note: This plugin currently doesn’t work on Windows.

Installation

Before installing this plugin, please make sure that you have ++python feature in your Vim. Type :version and if you see +python in the output, then you have this feature enabled in your Vim. Then, you could either:

I would recommend using the second way, since pathogen can well organize your installed plugin, making plugin installation and uninstallation much easier.

Usage

First please set the vim option updatetime to a smaller value, which is the frequency that the output PDF is updated. I would recommend setting it to 1. Basically you can simply add the following line to your .vimrc file:

autocmd Filetype tex setl updatetime=1

Then visit this page to see a list of PDF viewers that could work with this plugin. If you want to use any pdf viewers that are not marked as “built-in”, you need to add the following line to your .vimrc file:

let g:livepreview_previewer = 'my_pdf_viewer'

Now open up a tex file with Vim. Run :LLPStartPreview to start previewing and enjoy!

If you frequently need to use the preview feature, I suggest you to map the preview command onto some key binding:

nmap <F12> :LLPStartPreview<cr>

Screenshot

A simple screenshot:

An Alternative

An alternative might be Kevin Klement’s vim-live-latex-preview, which I haven’t tried out though.

7 thoughts on “Live Preview of LaTeX in Vim

  1. newuser

    works great, i can preview the pdf.
    But everytime i write something and use braces, this thing appears .
    For example: when i type wp() and press enter, i get wp()
    any idea what this ?

    Thanks 🙂

    Reply
  2. grapeot

    How about `latexmk`? Personally I simply throw `latexmk -pvc -silent -pdf` in the background, and then it will update the pdf file whenever the file is saved, with multi-file, cross-platform, bibtex, and click-through support. And to make it better, it comes with TeXLive in my impression (at least in both Debian and Mac OS X).

    Reply
    1. Hong Xu

      Sure, it can work. Unfortunately I didn’t make this plugin work in a full-fledge way. Can you make a pull request to make the compilation string customizable? I don’t think I’ll have time to handle it until next weekend. Thanks!

      Reply
      1. grapeot

        Thanks for your reply Hong. Sorry for not having made it clear enough. I mean latexmk, which is a LaTeX utility, looks to be able to achieve the same feature(s) as mentioned in this post, with possibly better support. Just want to kindly recommend to use/consult it in case you didn’t use it. 🙂

        Reply

Leave a Reply

Your email address will not be published. Required fields are marked *