Using latexmk, vim spell checking and vim latex-suite

I was originally doing my thesis writing with the Latex editor kile but since it doesn’t have in-line spell checking I decided to try vim which I already use for anything beside .tex files. While playing with the spell checking in Vim my friend Rasmus Fonseca told be about latexmk which turned out to be a really nice tool to compile latex document with.

Inline spell checking

To enable the in-line spell checker one should either use following commands in the editor or add them to the .vimrc file:

:set spell

This will highlight all the errors in the file. I am writing my thesis in English but I will also be writing documents in danish. In the .vimrc file I can set the spell checking language:

"" Spellchecking
if v:version >= 700
    "Sets in-line spellchecking
    set spell
    " Set local language 
    setlocal spell spelllang=en_us
    "setlocal spell spelllang=da

This will however not work out of the box on a recent (8.10) Ubuntu machine, so I need to download the danish spelling files from the webpage:
In my case I downloaded these files, da.latin1.spl, da.latin1.sug, da.utf-8.spl, da.utf-8.sug and copied them to the folder /usr/share/vim/vim71/spell/. After this the danish spell checker worked as well.

To use the spell checking a few commands are needed:

  • ]s — next misspelled word
  • [s — previous misspelled word
  • z= — view spelling suggestions for a mispelled word
  • zg — add a word to the dictionary
  • zug — undo the addition of a word to the dictionary

Using Latexmk
Instead of writing my own makefile or some script to run latex, bibtex and makeindex on my thesis files I was made aware of latexmk. This great tool take care of everything:

Latexmk is a perl script for running LaTeX the correct number of times to resolve cross references, etc; it also runs auxiliary programs (bibtex, makeindex if necessary, and dvips and/or a previewer as requested). It has a number of other useful capabilities, for example to start a previewer and then run latex whenever the source files are updated, so that the previewer gives an up-to-date view of the document.

The install is simple:

aptitude install latexmk

So now when I starting writing on my thesis I change to folder with my tex files and run the command latexmkspeciale which is an alias to a command that finds the master document and starts latexmk:

alias latexmkspeciale="grep -l '\\documentclass' *tex | xargs latexmk -pdf -pvc -silent"

Every time I write a change to any of the files included by the master latex document latexmk will do the necessary compiling automatically. By default latemk calls xpdf which can reload the current page by pressing r – this got me tired so I created a file called .latexmkrc in my home folder where I told latexmk to use the evince pdf viewer instead:

tjansson@euler:~$cat .latexmkrc
$pdf_previewer = "start evince";
$pdf_update_method = 0;

Using VIM’s built-in latex-suite
One thing I would be missing from kile would be autocompletion of \cite and \ref environments in Latex. It turned out that there is a excellent latex-suite for vim called vim-latexsuite. The installation should rather simple with a

aptitude install vim-latexsuite

but it turned out that it was also need to add the latex-suite to the local user by running:

vim-addons install latex-suite

and adding these lines to your local ~/.vimrc file:

" These settings are needed for latex-suite
filetype indent on
filetype plugin on
filetype on
let g:tex_flavor='latex'
set grepprg=grep\ -nH\ $*
"let g:Tex_Folding=0 "I don't like folding.
set iskeyword+=:

Once this suite is loaded I could do all sorts of nice stuff such as pressing F5 to insert a new environment or even more interesting pressing F9 while inside a \cite{ environment. Read more about the latex-suite on the webpage

At first I couldn’t get autocompletion of cite environments to work and after a lot of work it turned out to be due to that kbibtex included a extra whispace in the bibtex file which the latex-suite couldn’t understand. So I changed all my settings from:

@ARTICLE{ svenningsen2007crb,



Bug at launchpad: Spellchecking impossible for most languages
Faster and more comfortable LaTeX editing and previewing with latexmk
How to Use Vim’s Spellchecker

24 thoughts on “Using latexmk, vim spell checking and vim latex-suite”

  1. For those using dvi-files instead of pdflatex i can recommend
    xdvi -watchfile 1
    This makes xdvi refresh every 1 second. Combined with latexmk you dont have to perform another compile-cycle in latex ever again. Almost wysiwyg.

  2. Now I updated the article to include vim-latexsuite and info on how to use evince instead of xpdf. I used quite some time trying to make making xpdf auto update by using -remote and -reload but i seemed that latexmk just wouldn’t execute the command. The closest I got was the following in my .latexmkrc file

    $pdf_previewer = "start xpdf -remote localhost";
    $pdf_update_method = 4;
    $pdf_update_command = "xpdf -remote localhost -reload";
    #0 Automatic update
    #1 Manual update
    #2 Unix update
    #3 Acrobat locks the file (Windows)
    #4 Run a command

    But for some reason $pdf_update_command was never executed. Thanks to for putting me in the correct direction on -reload.

    With evince it just works. 🙂

  3. A quick follow up on my previous post: “latexmk -pvc” automatically starts a previewer (xdvi) but xdvi does not auto-update (although the ability is there). To enable this add the following to .latexmkrc:

    $dvi_previewer = 'start xdvi -watchfile 1';
  4. The following in my .latexmkrc file makes xpdf reload automatically:

    $pdf_previewer = "start xpdf -remote %R %O %S";
    $pdf_update_method = 4;
    $pdf_update_command = "xpdf -remote %R -reload -raise";

    The last option (-raise), which brings the pdf window to the front when it reloads, isn’t necessary.

  5. gedit with Latex plugin has fly spell and many other goodies. It is a great tool foe witting in Latex.

  6. I tried to add geometry parameters to Jon Engel’s latexmkrc file (see below), but it doesn’t work. What am I missing?

    $pdf_previewer = “start xpdf -remote %R  -g 920x1270+1076+0 -z width %O %S”;
    $pdf_update_method = 4;
    $pdf_update_command = “xpdf -remote %R -reload -raise”;
  7. I’m having problems with running latexmk, when more than one .tex file is present in the directory. I get the following error:

    Latexmk: Need to specify exactly one filename for preview-continuousmode
    but 2 were specified

    I have made a empty file: file.tex.latexmain, where file.tex is the latex file I want to compile, but it still doesn’t work. I know you have solved this problem for me before, but have forgotten have to do it.

  8. I think the problem is that you use a .bashrc alias like this:

    alias latexmkmod='grep -l documentclass *tex | xargs latexmk -pdf -pvc -silent'

    Such a alias will feed latexmk with all .tex files. So I would suggest to use the regular call:

    latexmk -pdf -pvc -silent foobar.tex
  9. Incredibly useful post–Latexmk is great. I’m defintely a fan of Evince too, the other readers are a bit nasty.

    For those foobs like me that don’t know what an alias is, have a read of:

    Does anyone know how to get forward/inverse searching working with evince?

    I’ve been trying to fix that cite problem for months, I don’t know how to change the reference you are talking about, could you elaborate?

    Thanks again,

  10. Hi Chris

    I am glad you could use it! 🙂 Regarding the cite problems – the reason for my problems was that I had included a space in the bibtex file like this
    @ARTICLE{ svenningsen2007crb,
    once i removed the space, like this
    vim-latex could again read the bibtex file successfully.

  11. I am also using Vim with vim-latexsuite but I have found a spell-checking trouble that I don’t know how to solve:
    I have ‘set spell’ in my vimrc file, which works OK in all the files except the .tex files.
    In the .tex files, the vim spell-checker only works in the lines which start with a ‘%’ (the comments in LaTeX files), but it does nothing in the normal text.

    Does anybody knows how can I solve this??

  12. Thanks for the tip 🙂
    I noticed a typo, you write
    “this got me tired so I created a file called .latemkrc in my”
    I think “.latemkrc” should be “.latexmkrc”.

Leave a Reply