[R] Sweave, Texshop, and sync with included Rnw file

Duncan Murdoch murdoch.duncan at gmail.com
Fri Jan 11 04:08:00 CET 2013


On 13-01-10 4:54 PM, michele caseposta wrote:
> Hi everybody,
> thanks for the replies.
> I might have not explained the problem completely.
> Duncan Mackay:
> Yes, I am already having a master file and separate Rnw files.
> Duncan Murdock:
> I am using patchDVI in the TexShop Sweave engine.
> Sync works flawlessly between the master file and the pdf produced by pdflatex.
>
> My problem is that I don't seem to be able to obtain sync between the *included* Rnws and the pdf, either way.

I think you said before that you were using \SweaveInput to include the 
files.  I thought this had been handled, but perhaps not, or perhaps 
there's a bug.  What I'd recommend is that you don't use \SweaveInput. 
Set up your main file main.Rnw like this:

... usual header stuff ...
<<echo=FALSE>>=
.SweaveFiles <- c("chap1.Rnw", "chap2.Rnw")
@

\input{chap1}
\input{chap2}


Set up the chapters like this.  They aren't standalone files, so they 
don't need the usual LaTeX header lines, but they'll need some Sweave stuff:

% Put a commented usepackage so Sweave doesn't insert one
%\usepackage{Sweave}

% Make sure to set a unique prefix in each chapter
% so that figures and concordances don't clash
\SweaveOpts{concordance=TRUE,prefix=chap1}

% Tell SweaveAll about the other files
<<echo=FALSE>>=
.SweaveFiles <- "main.Rnw"
.TexRoot <- "main.tex"
@

Then patchDVI::SweaveAll (or SweavePDF, etc.) on any chapter or on the 
main.Rnw file will run Sweave on all the chapters (in a slightly 
unpredictable order, so don't count on it).  You should get the 
concordances working for each file.

I'll take a look at what is happening with SweaveInput, but not tonight. 
  (Besides working, the setup described above has the advantage of 
making things go faster:  you won't need to run Sweave on unmodified 
chapters.  Only modified ones get run each time.  You can also use 
\include in place of \input, and then LaTeX will run faster with 
\includeonly to select particular chapters.

Duncan Murdoch

>
> The sweave engine is as follows:
>
> #!/bin/bash
>
> R CMD Sweave "$1"
> latexmk -pdf -silent -pdflatex=‘pdflatex –shell-escape –synctex=1′"${1%.*}"
> Rscript -e "library(‘patchDVI’);patchSynctex(‘${1%.*}.synctex.gz’)"
>
>
> Funny thing is that the sync works in texworks, using the following Rscript line
>
> patchDVI::SweavePDF('$fullname',stylepath=FALSE)
>
> I tried to mix and match configurations between texshop and texworks but I had no luck
>
>
>
>
>
>
> On Jan 10, 2013, at 11:23 AM, Duncan Murdoch wrote:
>
>> On 13-01-09 9:09 PM, Duncan Murdoch wrote:
>>> On 13-01-09 3:25 PM, michele caseposta wrote:
>>>> Hello everyone.
>>>> I am in the process of writing a book in Latex with Texshop, on Mac.
>>>> This book contains a lot of R code, hence the need to use Sweave.
>>>> I was able to compile Rnw files, and to sync back and forth from the pdf to the source Rnw.
>>>> My problem now is that the book is divided in Chapters, and every chapter is in its own Rnw file.
>>>> I can compile them from the main one (book.Rnw) using the directive
>>>>
>>>> \SweaveInput{chapter1.Rnw}
>>>>
>>>> The problem stands in the fact that like this I am missing synchronization between the pdf and the source Rnw. If part of text is in book.Rnw I can synchronize, but if the text is in one of the included files, it just doesn't work.
>>>> I am using the sweave engine found in the following webpage:
>>>>
>>>> http://cameron.bracken.bz/synctex-with-sweavepgfsweave-in-texshoptexworks
>>>>
>>>> Has anybody succeeded in synchronizing with included Rnw files?
>>>
>>> This is a problem addressed by my patchDVI package, available on
>>> R-forge.  You have a main file (which can be .tex or .Rnw), and put code
>>> at the start of each .Rnw file to indicate where to find it.  Then you
>>> just run Sweave on one of the chapters, and it automatically produces
>>> the full document.
>>>
>>> The sample document here:
>>>
>>> http://www.umanitoba.ca/statistics/seminars/2011/3/4/duncan-murdoch-using-sweave-R/
>>>
>>> includes an appendix describing how to set this up with TeXShop.
>>
>> I just committed an update to the vignette in patchDVI giving a quick version of the instructions for basic use. Version 1.8.1585 has the new vignette.
>>
>> I should get around to pushing it to CRAN one of these days...
>>
>> Duncan Murdoch
>>
>
>




More information about the R-help mailing list