Friday, October 29, 2010

Simple LaTeX build and preview or "How I learned to stop worrying and love latexmk"

I have always loved LaTeX and liked latexmk to manage the compiling. latexmk checks to be sure that the proper compilers are run an appropriate number of times.

I also knew that it could be used with the -pvc option that leaves it in "continuous preview mode" which means it monitors the file and everytime you save it it recompiles automatically. This is a cool feature but it involved initializing a previewer that would check to refresh itself and I never gave it enough time to get it working.

Just tonight though I learned that latexmk can also have a configuration file in your home folder (i.e. ~ or /home/yourname) which can have all the necessary information for this setup all ready to go.

In your home folder create a file called ".latexmkrc" (no quotes). In it, put exactly this:

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

Of course you need to be sure that you have a LaTeX environment installed as well as the latexmk script and xpdf. I recommend using the latexmk that is available from CTAN rather than the one in your package manager (in fact I always manage my own LaTeX implementation, its not hard using the tools available from CTAN and using the tlmgr script included with TeXlive).

Anyway when you run latexmk yourfile.tex (yep you don't even need to use -pdf), it will compile and open xpdf to preview. Then the next time you save your document in your editor, the previewer will automatically reflect the saved (and compiled!) changes.

Cool eh?

NB: This might finally be the thing that finally breaks me of my old editor TeXlipse (still awesome, but might not play well with other things that change the workspace).

No comments: