I’m a huge vim
When I begrudgingly have to use an IDE the first thing I install is a Vim plugin.
So when I finally got pissed off enough with Microsoft Word to learn LaTeX, I knew it would also mean getting my Vim set up for it.
Vim doesn’t support LaTeX out of the box as well as it does for certain things, like shell scripts and C. LaTeX also isn’t as popular as other programming languages, so the documentation for getting the two working together isn’t all there. When the documentation is there, it doesn’t usually work too nicely with OS X.
This is what I ended up doing to get autocompletion working, syntax highlighting, tag jumping and auto compiling and preview up and running with LaTeX, Vim and OS X. This is a guide to just get Vim and LaTeX working together nicely so you can get started and making some pretty documents.
The first thing you need to do is get LaTeX installed, luckily MacTeX makes that trivially easy. Warning: This is a big download, and is going to take a couple GBs of space on your SSD (or HD).
This plug does a lot of great things without being intrusive. Instructions for installing LaTeX-BoX can be found here.
If you don’t already have
filetype plugin on in your .vimrc, add it now.
If you want LaTeX box to be able to continuously compile your document on saves, add the following lines as well:
let g:LatexBox_latexmk_preview_continuously = 1 let g:LatexBox_quickfix = 2 let g:LatexBox_latexmk_options = "-d"
let g:LatexBox_latexmk_preview_continuously = 1 tells the plugin to run latexmk in continuous mode, which is the goal here.
When a syntax error is found, a small pane on the bottom of Vim will appear, listing all the errors, and you can select them to jump to where the syntax errors are.
Normally in my workflow I write something, save, then review. If there are syntax errors, I’m usually already on that line, so having the quick fix box steal my cursor can get annoying,
let g:LatexBox_quickfix =2 prevents that.
let g:LatexBox_latexmk_options = "-d" runs latexmk as a daemon, so it runs continuously in the background listening for file changes.
In order for the LaTeX-BoX plugin to run latexmk for continuous compilation, it needs to be in your PATH. If you installed MacTeX, add the following to your ~/.bashrc, ~/.profile or ~/.zshrc:
This will make latexmk visible to Vim and LaTeX-BoX.
If you open up a *.tex document, write some LaTeX, run :Latexmk (case sensitive!)in Vim, every time you save after that it will automatically compile to a PDF which you can view in Preview. Personally I run a split full screen with the two side by side, it’s a great workflow.
Note: Preview only updates once you alt tab onto it, you might be better off with a third party PDF viewer.