Skip to content
Prev 31434 / 398506 Next

Working comfortably with (X)Emacs + Sweave

On Wed, Apr 30, 2003 at 07:11:01PM +0200, Tamas Papp wrote:
Excellent question. Below is my pedestrian answer. I edit in XEmacs,
and then call this shellscript. You could also bind it to what gets 
called from latex/auctex when you 'compile' the input file.

Dirk


#!/bin/bash -e

function errorexit () {
    echo "Error: $1"
    exit 1
}	

function filetest () {
    if [ ! -f $1 ]; then
       errorexit "File $1 not found"
    fi
    return 0
}
		       
	       
if [ "$#" -lt 1 ]; then
    errorexit "Need to specify argument file"
fi
			   
		   
BASENAME=$(basename $1 .Rnw)
			   
RNWFILE=$BASENAME.Rnw
filetest $RNWFILE
echo "library(tools); Sweave(\"$RNWFILE\")" \
      | Rterm --no-save --no-restore --slave
			       
LATEXFILE=$BASENAME.tex
filetest $LATEXFILE && pdflatex $LATEXFILE
			       
PDFFILE=$BASENAME.pdf
filetest $PDFFILE && acroread