vi, LaTeX and amusing myself

So as I have said I use LaTeX to prepare most of my professional documents.  Since I work almost exclusively in a Linux environment — or on a Mac, and Mac OS X is thankfully essentially a variant of UNIX with a GUI — I mostly use 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).  That is very simple


syntax enable
setl tw=72


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.  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:

  • evince (this can be replaced with the name of your favourite pdf viewer.  evince is good because if you update the pdf file, it will reload automatically).
  • gv (this can be replaced with the name of your favourite postscript viewer, including).
  • dvi2tty (this renders a dvi file (LaTeX output) as plain text.  Notionally this lets you review your work on a text terminal.  I suspect this rarely happens these days, but I quite like it, plus it is a good way to see how many words your article is in length — run dvi2tty and pipe into wc (word counter).  It would be possible to run pdflatex and then pdftotext and do something similar).
  • xfig (I use this all the time to annotate figures then export them to LaTeX-friendly formats).
  • ispell (this is just a spell checker.  I have it create a custom dictionary associated with the document, called say filename.tex.dic, so that once you have inserted all the character combinations particular to your file into it, it won’t ask you about them again.  This is very useful with scientific documents where you might have a chemical formula or something that a spell checker would pick up every time, and you don’t want to clutter up your global dictionary with cruft that is specific to a single project).
  • advi (an alternative dvi viewer to xdvi).

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.

If you get any benefit from it. let me know.  If you make a better version, let me know.  If you think it is a waste of time, you are probably right but you don’t need to tell me.


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
Advertisements

Tags: , ,

About Darren

I'm a scientist by training, based in Australia.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: