viernes, 24 de abril de 2009

Fully vim style linux (part 2) - Vim for latex

Writing documents with latex with vim is fairly pleasant because you have your usual maps available, and you can configure most things with scripts but, as always, someone has already done that (don't reinvent the wheel).

latex-suite


Latex-suite is a great and very complete set of plugins for vim that helps writting faster latex with vim. It has lots of options and configuration bits, but you only need to remember a tiny set of shortcuts to use it (at least at a beginner level)

Environment complete (F5) . you're in a document and you want to insert a tabular environment. Just type 'tabular' and press F5. a full tabular environment will be placed right there, with the appropiate number of params and placeholders (you can navigate to the next placeholder with ctrl-j).

Package inserting (F5): in the preamble section, if you press F5 after typing a word, latex-suite will enclose it into a \usepackage{word}
snipMate

Compiling (ll) : to compile a document, just press your leaderkey followed by 'll' (that's two 'els').

View the compiled doc (lv): just type leader lv to open your viewer program with your dvi/pdf file in it.

There are lots of other useful things in latex-suite. you can find further info in its website.

LaTeX::Table

Tabulars can go from the simplest things to fairly complicate structures. Let there be perl.

There's a small module named LaTeX::Table that helps us to make pseudo ascii tables, and put some options embedded in a comment, and it converts them to fully functional tables.

Try cpan:

sudo cpan LaTex::Table
It uses Moose (a great modern OOP system for Perl 5), so if you don't use perl regularly, cpan will probably install a big bunch of perl modules.

If you have any problem installing those modules from cpan, you can always install them (or at least, the one that fails) with the good old method:

perl Makefile.PL, make, make install

Now a usage example.

theme=Berlin;caption_top=1;caption=foo
one & Two & Three
CAN I & haz a & CHEEZBURGER
& OH & KTHX
FOO & bar & Baz
Just visually select it and apply the !ltpretty filter. You're done

Latexhelp

With latexsuite, there is a latex reference in vim help format, so you can access the syntax of latex commands easily in vim. It doesn't need additional configuration, provided you placed the latex reference file in your doc/ directory and ran helptags on it. Probably :helptags ~/.vim/doc will do.

you can find the separate doc files here.

vim config

There are lots of possible configurations depending on your workflow and/or preferences. My configs are just theese lines.

let g:tex_flavor='latex'
let g:Tex_CompileRule_pdf = 'pdflatex -interaction=nonstopmode $*'

More things

As you probably know, learning to use vim effectively has many paths to go, and what is useful for me, can be painful for you. You can combine plenty of other vim plugins to help you writting faster latex.

For example, using snippetsEmu/snipMate/whatever snippets plugin can be useful, using supertab can speed up your (general) writting, or even little maps like the ones explained in my previous post 'Fully vim style linux (part 1)' can enhance your typing experience.

Please post comments about comments/improvements, and I'll make the appropiate updates.

See ya in the next post.

No hay comentarios: