About Me

My Photo
New York, NY, United States
I am Karthik, known to many as TJ, a student of Electrical Engineering at Columbia University in the great city of New York. I am doing PhD in Integrated Circuit (IC) Design. Engineering is my primary interest and it is my dream to become an engineer like Tony Stark (Iron man). Photography, running, cooking and aimless traveling are some of my other interests. Steve Jobs and Kamal Hassan (an Indian actor) are my biggest inspirations. I use this blog to share my travel experiences, interesting recipes and any other story that I feel compelled to share.

Wednesday, April 20, 2011

Shell Script for 'Latex'-ing from vim

I am a vim loyalist.

Features in Emacs like compiling latex code and viewing the output without having to switch to the terminal is awesome. However, having used vim (and recently gvim) for more than 5 years, its easier for me to write scripts for vim to implement the cool features of Emacs rather than switch to Emacs. Below is a simple shell script to compile latex document and show the output without leaving the editor.


 #! /bin/sh
 source=$1
 infile=${source%.tex}
 latex $infile
 bibtex $infile
 latex $infile
 latex $infile
 dvips $infile.dvi
 ps2pdf $infile.ps
 evince $infile.pdf

You can use pdflatex instead of latex. Also, I use evince to view the pdf because any update in the file is updated in the viewer without having to restart it (unlike acroread). The script (I call it compile_latex.sh) needs to be saved in a directory included in the PATH.

Now comes the vim part. The following line needs to be added in .vimrc (or .gvimrc).

map :!compile_latex.sh %

I am now looking for a good psychiatrist program to integrate with vim; helps to vent out frustration :-).

0 comments:

Post a Comment