Vim and LaTeX - some simple scripts

I used to use LaTeX to prepare most of my professional documents.  I mostly used an editor called vi (or really vim).

Why?  Because it is there.  It comes with Linux and it isn't Emacs.

There are many tools to make it into a shell for LaTeX (Vim-LaTeX, LaTeX Box) and I've put together what is quite probably the most simple-minded of them possible.  It is the opposite of full-featured.

Basically, I have some extra text in my vi configuration file (this is called .vimrc and it lives in your home directory).  This is very simple:

syntax enable
command L   !latex %
command B   !bib.sh %
command V   !dviv.sh %
command A   !dvia.sh %
command D   !dvips.sh %
command G   !gv.sh %
command M   !maki.sh %
command F   !pdfv.sh %
command I   !spell.sh %
command PP  !ps2pdf.sh %
command PDF !pdflatex %
command W   !wc %
command XF  !xfig &
command T   !dvi2tty.sh %
command WT  !wctty.sh %
command VT  !viewtty.sh %

and all it is is a bunch of extra vi commands, accessed by typing ':CMD' where CMD is the command (case sensitive).  I assume that I have started vi with a command like

$vi filename.tex

where the $ is the command line prompt and 'tex' is in lower case.  Some of the commands are just that -- commands.  Like run LaTeX on the file, or run pdfLaTeX on it.  Most call a tiny shell script.  It does not have to be done this way, but I have my reasons -- the main one being that there is a second editor I also use when the mood takes me (TDE), and it can be configured to call the same bunch of shell scripts. In fact, they were first written for it.

The shell scripts are available at http://djg.altervista.org/downloads/latex_vi_scripts.zip, and you just stick them somewhere in your path.  Apart from LaTeX and its various ancillaries, the programs I call include:

Apart from that, it calls a bunch of standard stuff like dvips, xdvi, wc, basename, view, bibtex, makeindex and so on, all of which would either be part of your Linux core system or your LaTeX core system.  It is also pretty damned obvious how to add in new commands if you want them.

I know this is all pretty simple-minded, but I am putting it up here for two reasons.  One, it means I can get at it and 'install' it on any machine I am using and, two, someone might find some value in it; why not?

So the clear usage instructions:

(1) Add the stuff in '.vimrc' to your own '.vimrc' file.

(2) Unpack the archive of small shell scripts into some directory in your path (they are shown in a badly formatted list at the end of this post, as well).

(3) Make sure the small number of tools this uses are installed.

(4) Add any new commands you want.

(5) Run vi as normal.


The scripts and what they do:
--------------
bib.sh
--------------
#!/bin/bash
NM=`basename $1 .tex`
bibtex $NM
--------------
dvi2tty.sh
--------------
#!/bin/bash
NM=`basename $1 .tex`.tty
IM=`basename $1 .tex`.dvi
dvi2tty -w132 $IM > $NM
--------------
dvia.sh
--------------
#!/bin/bash
NM=`basename $1 .tex`.dvi
advi $NM &
--------------
dvips.sh
--------------
#!/bin/bash
NM=`basename $1 .tex`
dvips $NM
--------------
dviv.sh
--------------
#!/bin/bash
NM=`basename $1 .tex`
xdvi $NM &
--------------
gv.sh
--------------
#!/bin/bash
NM=`basename $1 .tex`.ps
gv $NM &
--------------
maki.sh
--------------
#!/bin/bash
NM=`basename $1 .tex`
makeindex $NM
--------------
pdfv.sh
--------------
#!/bin/bash
NM=`basename $1 .tex`.pdf
evince $NM &
#xpdf $NM &
--------------
ps2pdf.sh
--------------
#!/bin/bash
NM=`basename $1 .tex`.ps
ps2pdf $NM
--------------
spell.sh
--------------
#!/bin/bash
echo $1
echo $1.dic
touch $1.dic
echo "ispell -t -p $1.dic $1"
ispell -t -p $1.dic $1
--------------
viewtty.sh
--------------
#!/bin/bash
NM=`basename $1 .tex`.tty
IM=`basename $1 .tex`.dvi
dvi2tty -w132 $IM > $NM
echo Created $NM, piping into view
sleep 2s
view $NM
--------------
wc.sh
--------------
#!/bin/bash
wc $1
sleep 5s
--------------
wctty.sh
--------------
#!/bin/bash
NM=`basename $1 .tex`.tty
IM=`basename $1 .tex`.dvi
dvi2tty -w132 $IM | wc
sleep 5s

bib.sh run bibtex
dvi2tty.sh convert dvi file to text
dvia.sh view dvi file in advi
dvips.sh convert dvi file to postscript
dviv.sh view dvi file in xdvi
gv.sh view postscript file in gv
maki.sh run makeindex
pdfv.sh view pdf file (in evince in this case)
pdfv.sh view pdf file (in evince in this case)
ps2pdf.sh convert postscript to pdf
spell.sh run ispell on .tex file
viewtty.sh convert dvi to tty (text file) and view in view
wc.sh word count .tex file
wctty.sh word count the textified .dvi file

Home