Monday, August 20, 2012

vim for latex

What you need:

A text editor that can perform an action each time the document has changed
A fast way to recompile LaTeX
A viewer that can quickly reload the document.
I used gVim as the text editor, latexdaemon as the compilation engine,
and Sumatra as the PDF viewer.

In Vim, issue the command :au! CursorHoldI,CursorHold <buffer> silent!
:update to make it auto-save the document every time you stop typing.
Also :set updatetime=800 to set the timeout after which saving happens
to a low value.

latexdaemon will auto-compile the document in an efficient way every
time it's changed. Use the following at the beginning of the file to
make it produce PDF:

%Daemon> ini=pdflatex
Or just start it with latexdaemon -ini=pdflatex.

Sumatra will automatically re-load the file every time it is changed,
and it will not lock the PDF (so it can be recompiled without closing
Sumatra first).

This recipe will give you an almost real-time preview, but it takes
some effort to set up, and is not without issues. For example, you
might not want to continuously auto-save, in case you'd want to revert
to an earlier version.

There's a lot to improve on this, but I've been using it for some time
(after reading your question), and thought putting the recipe out here
might be useful for others too.

Since I was lazy, I just put everything to set this up into a .bat file:

@start C:\Path\To\Sumatra\SumatraPDF.exe %1.pdf
@start latexdaemon -ini=pdflatex %1.tex
@gvim -c ":au! CursorHoldI,CursorHold <buffer> silent! :update" -c
":set updatetime=800" %1.tex

also the sync issue, refer to
http://william.famille-blum.org/blog/static.php?page=static081010-000413

No comments:

Post a Comment