#!/bin/sh5 # # Author: Dag Asheim, email: dash@ifi.uio.no # # bib2dvi: From a .bib sourcefile generate a printable .dvi file. # # The .dvi file is formated with filename and date on top. # Uses bibliography style 'plain' and LaTeX-option 'a4' by default. # Changable with options -b and -l. # # \bibitem{dummy} is filtered out if present (it is dummy after all). # # Assumes bibtex and latex in path, in addition to standard shell utilities: # basename, getopt, [, ls, wc, echo, expr, dirname, ln, sed, cat, rm, mv, awk #PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin USAGE='usage: '`basename $0`' [-h|t] [-l LaTeX-options] [-i input.tex] [-b BiBTeX-style] [file.bib]' BIBSTYLE=plain LATEXOPT=fullpage KEEPTEXF=false INPUT=/u/smann/lib/null.tex CWD=`pwd` set -- `getopt htl:b:i: $* || echo ERROR` if [ "$*" = ERROR ] then echo "$USAGE" 1>&2 exit 1 fi for arg in $* do case $arg in -h) exec 1>&2 echo "$USAGE" cat << 'EOF' From a .bib sourcefile generate a printable .dvi file. The .dvi file is formated with filename and date on top. Uses bibliography style 'plain' and LaTeX-options 'a4' by default. Changable with options -b and -l. \bibitem{dummy} is filtered out if present. EOF exit 0; shift;shift;; -l) LATEXOPT=$2; shift;shift;; -b) BIBSTYLE=$2; shift;shift;; -i) INPUT=$CWD/$2; shift;shift;; -t) KEEPTEXF=true; shift;; --) shift; break 2;; esac done if [ $# -eq 0 ] then if [ `ls *.bib 2> /dev/null | wc -w` -eq 1 ] then BIBALL=`ls *.bib` elif [ `ls *.bib 2> /dev/null | wc -w` -eq 0 ] then echo "No .bib file on current working directory." 1>&2 echo "$USAGE" 1>&2 exit 1 else exec 1>&2 echo "Ambiguous number of .bib files on current directory:" ls *.bib echo "$USAGE" exit 1 fi elif [ $# -eq 1 ] then if [ -f $1 ] then BIBALL=$1 else echo "Argument not an existing file." 1>&2 echo "$USAGE" 1>&2 exit 1 fi else echo "Wrong number of arguments." 1>&2 echo "$USAGE" 1>&2 exit 1 fi OLDDIR=`pwd` BIBLIO=`basename $BIBALL .bib` if [ $KEEPTEXF != true ] then if expr x$BIBALL : x/ > /dev/null then BIBDIR=`dirname $BIBALL` else BIBDIR=$OLDDIR/`dirname $BIBALL` fi cd /tmp if [ -f $BIBLIO.aux \ -o -f $BIBLIO.blg \ -o -f $BIBLIO.log \ -o -f $BIBLIO.bbl \ -o -f $BIBLIO.tex \ -o -f $BIBLIO.bib ] then exec 1>&2 echo "Filename conflict (on /tmp):" for i in $BIBLIO.blg $BIBLIO.log $BIBLIO.bbl $BIBLIO.tex $BIBLIO.bib do if [ -f $i ] then echo " $i" fi done echo "Aborting." exit 1 fi ln -s $BIBDIR/$BIBLIO.bib sed -e "s/xxx/${BIBLIO}/" -e "s/yyy/${BIBSTYLE}/" > $BIBLIO.aux << EOF \relax \citation{*} \bibdata{xxx} \bibstyle{yyy} EOF if (echo "hi\c" ; echo " ") | grep -s c # How to suppress newlines? then N='-n' # ...using -n. C='' else N='' C='\c' # ...using \c fi trap 'cd /tmp; rm -f $BIBLIO.aux $BIBLIO.bbl $BIBLIO.bib $BIBLIO.blg $BIBLIO.log $BIBLIO.tex; exit 1' 2 3 echo $N bibtex...$C if bibtex $BIBLIO | grep -s error then exec 1>&2 echo echo "BiBTeX detected an error:" echo cat $BIBLIO.blg echo rm $BIBLIO.aux $BIBLIO.bbl $BIBLIO.bib $BIBLIO.blg exit 1 fi mv $BIBLIO.bbl $BIBLIO.blg awk 'BEGIN {RS = ""; FS = "\n"; OFS = "\n"; ORS = "\n\n"} /^\\bibitem{dummy}/ {next} {print}' < $BIBLIO.blg > $BIBLIO.bbl fi #sed -e "s/xxx/${BIBLIO}/" -e "s/yyy/${LATEXOPT}/" -e "s/zzz/${BIBSTYLE}/" -e "s/xyz/${INPUT}/" > $BIBLIO.tex << EOF sed -e "s/xxx/${BIBLIO}/" -e "s/yyy/${LATEXOPT}/" -e "s/zzz/${BIBSTYLE}/" > $BIBLIO.tex << EOF \batchmode \documentstyle[yyy]{article} \begin{document} \input{${INPUT}} \centerline{\bf xxx.bib} \centerline{\today} \sloppypar \nocite{*} \bibliographystyle{zzz} \bibliography{xxx} \end{document} EOF if [ $KEEPTEXF = true ] then exit 0 fi echo $N " latex..."$C echo bye | latex $BIBLIO > /dev/null if grep -s "^!" $BIBLIO.log then exec 1>&2 echo echo "LaTeX detected an error:" awk '/^!/ {PRINT=1; print ""} /^$/ {PRINT=0} {if (PRINT) print}' < $BIBLIO.log rm $BIBLIO.aux $BIBLIO.bbl $BIBLIO.bib $BIBLIO.blg $BIBLIO.log $BIBLIO.tex exit 1 fi rm -f $BIBLIO.aux $BIBLIO.bbl $BIBLIO.bib $BIBLIO.blg $BIBLIO.log $BIBLIO.tex mv $BIBLIO.dvi $OLDDIR/$BIBLIO.dvi echo " done."