1
# This is to allow the use of Sweave with latexmk, and in addition to
2
# make synctex work properly with it.
3
# SEE THE IMPORTANT NOTES below.
5
# Sweave (http://www.stat.uni-muenchen.de/~leisch/Sweave/) is a tool
6
# that allows to embed the R code for complete data analyses in latex
7
# documents. The user edits a file with an extension like .Rnw, and
8
# the .tex file is generated from this.
10
# Four problems are solved by the code below:
11
# 1. Generate the .tex file automatically.
12
# 2. Arrange not to re-run unmodified chunks of R code. (A pure
14
# 3. Fix the execution environment for (pdf)latex.
15
# 4. Deal with synctex: If the user wants to use synctex
16
# (www.tug.org/TUGboat/tb29-3/tb93laurens.pdf) to synchronize the
17
# pdf file with the source file, by default synctex does the
18
# synchronization with the generated .tex file, not the original
19
# source file. Postprocessing of the .synctex.gz file is necessary
22
# The following version was worked out and tested by a user (thanks
23
# to Brian Beitzel) on MSWindows. It will need at least one change to
24
# work on UNIX-like operating systems (which include Linux and OS-X).
26
# N.B. ===> IMPORTANT NOTES <===
28
# 1. The patchDVI package for R needs to be installed from R-Forge, as
31
# install.packages("patchDVI", repos="http://R-Forge.R-project.org")
33
# 2. In all Sweave (.Rnw) documents, the following lines must be included:
36
# \SweaveOpts{concordance=TRUE}
39
# Fix the pdflatex command to run Sweave first, and to postprocess the
41
# !!!!! THIS IS THE VERSION FOR MS-WINDOWS, with && as a command
44
. "Rscript -e \"library(cacheSweave); setCacheDir(getwd()); "
45
. "Sweave('%S', driver=cacheSweaveDriver)\""
46
. " && R CMD pdflatex -interaction=nonstopmode -synctex=1 %O %B.tex"
48
. "\"library('patchDVI');patchSynctex('%B.synctex.gz')\"";
50
# !!!TO FIX THIS FOR Linux/OS-X/UNIX, try uncommenting the following:
51
# (this version hasn't been tested).
52
#$pdflatex = "Rscript -e \"library(cacheSweave); setCacheDir(getwd()); "
53
# . "Sweave('%S', driver=cacheSweaveDriver)\""
54
# . " ; R CMD pdflatex -interaction=nonstopmode -synctex=1 %O %B.tex"
56
# . "\"library('patchDVI');patchSynctex('%B.synctex.gz')\"";