Re: [R] Sweave, R and complex latex projects

From: Mark Wardle <>
Date: Thu 09 Nov 2006 - 20:02:41 GMT


This is an update to my previous query on dealing with complex (complex in my eyes anyway) LaTeX/Sweave projects. Based on the work of others, please see my current thesis Makefile below. I didn't get Sweave and LaTeX to cope with a master document in one directory, and chapters in subdirectories, so instead I moved all individual chapter .tex and .Rnw files into the same directory. The only reason for having directories in the first place was to group all the charts and tables etc. and Sweave makes that unnecessary anyway.

The other issue is that Sweave can interact with typeface settings in a LaTeX document. One may avoid this by using the [noae] option, or just making sure any typeface directives (including \usepackage{times}) come after the \usepackage{Sweave} directive in your master LaTeX document.

I hope this is of help to someone else... No guarantees as I am not a Makefile expert!

# Makefile
# Global project Makefile
# This makefile was based on
# (The original file found on Google is no longer available and I
couldn't track a new version)
# This is credited to Johannes Ranke, based on work by Nicholas
Lewin-Koh and Rouben Rostmaian, and also from Deepayan Sarkar's email on the R-help mailing list.
# The master document (document preamble, \include's the other files) is
MASTER = thesis.pdf

# the master document depends on all of the tex files
RNWFILES = $(wildcard *.Rnw)
TEXFILES = $(wildcard *.tex)
DEPENDS = $(patsubst %.Rnw,%.tex,$(RNWFILES)) $(TEXFILES)

RERUN = "(There were undefined references|Rerun to get (citations|cross-references|the bars) (correct|right)|Table widths have changed. Rerun LaTeX.|Linenumber reference failed)" RERUNBIB = "No file.*\.bbl|Citation.*undefined"

all: $(MASTER)

$(MASTER): $(DEPENDS) %.tex: %.Rnw

        R CMD SWEAVE '$<'

%.pdf: %.tex

	@pdflatex $<
	@egrep -c $(RERUNBIB) $*.log && (bibtex $*;pdflatex $<); true
	@egrep $(RERUN) $*.log && (pdflatex $<) ; true
	@egrep $(RERUN) $*.log && (pdflatex $<) ; true

	@rm -f *.aux *.log *.bbl *.blg *.brf *.cb *.ind *.idx *.ilg  \
          *.inx *.ps *.dvi *.toc *.out *.lot *~ *.lof *.ttt *.fff \
          *.eps *.pdf
	@rm -f $(patsubst %.Rnw,%.tex,$(RNWFILES))

Dr. Mark Wardle
Clinical research fellow and Specialist Registrar in Neurology,
C2-B2 link, Cardiff University, Heath Park, CARDIFF, CF14 4XN. UK

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Fri Nov 10 11:25:49 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 10 Nov 2006 - 02:30:17 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.