23 July 2007

My first useful, original script

LaTeX is wonderful, but it clutters up my folders with .aux, .bbl, and other files. So I wrote this script for one-part articles:

# q-tex - takes a .tex file, copies it to a hidden directory, runs
# pdflatex (and later, bibtex), and writes a symlink to the .pdf in
# the original directory.


if [ $# -eq 0 ] ; then
    echo "Usage: $0 basefilename (no .tex extension)" >&2
    exit 1

if [ $(echo $1 | grep '.tex') ] ; then
    echo "Usage: 0$ basefilename (OMIT .tex EXTENSION)"

basefilename="$(echo $1 | sed 's/.tex$//g')"

if [ ! -d $workdir ] ; then
    echo "q-tex directory does not exist yet; creating it."
    mkdir .q-tex

if [ -s ${basefilename}.pdf ] ; then 
    rm ${basefilename}.pdf ; 
elif [ -f ${basefilename}.pdf ] ; then
    echo "There is already ${basefilename}.pdf in this directory.  Delete or rename it to use $0"
    exit 1

cp $1 $workdir/
cd $workdir
pdflatex $basefilename
cd ..
ln -s $workdir/${basefilename}.pdf ${basefilename}.pdf

exit 0

# TODO: use the same basic plan with .bib file: copy it to .q-tex, run
# stuff there, return to original directory. This way, I can have my
# RCS directories in the original directory without screwing things
# up.  Where should I keep my .sty files, though?  bibq-tex.sh


Post a Comment

<< Home