Hi All --

I'm not sure this is the natural place for this question, but this list is
the place with the best Sweave-TeXShop-sync discussion so far.

My problem is that sync+Sweave+TeXShop works sometimes and not others, and
it's not consistent. The failure, in which sync from PDF opens the .tex
file instead of the .Rnw file, always comes after a code chunk.

If I start from a simple example (below), sync works perfectly. But often
when I change the R code (see example alternate code chunk below) , sync
breaks after the code. In the example, if I click on "Maecenas eget dolor
enim" in the pdf, TeXShop opens the tex file
("minSyncWithTable_failsSync.tex"). This outlasted restarting TeXShop and
deleting all files except the .Rnw. Then I deleted a line within the code
chunk and synced successfully. To confirm the importance of that particular
line, I undid the deletion, but this did not break sync: I continued to
sync successfully. Deleting all the files except the .Rnw didn't break sync
again.

Are there types of code in code chunks that break sync?

Is there better way to troubleshoot sync failures? Am I missing a factor?

Examples below. Thanks for your consideration.


Following is my basic file that works - it always flips back to the .Rnw
rather than opening the corresponding .tex file.

<<< MINIMAL EXAMPLE

% !TEX TS-program = Sweave2

\documentclass{article}

\usepackage{Sweave}

\SweaveOpts{concordance=TRUE}

\begin{document}

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

\section{dolor}

<<>>=
n <- 5
for(i in 1:n){
print(i)
}
@


Maecenas eget dolor enim.

\end{document}

END MINIMAL EXAMPLE >>>

Alternate code chunk:

<<>>=
library(xtable)
read.txt<-function (file="", sep="\t", header=TRUE,row.names=NULL, ...){
    read.table(file, sep= sep, header= header, row.names= row.names, ...)
    }
setwd("~/Documents/Dropbox/")
### Variable depth


@

I use a Sweave engine  called Sweave2.engine that contains the following:

### SWEAVE ENGINE FOLLOWS

#!/bin/bash
R CMD Sweave "$1"
latexmk -pdf -silent -pdflatex='pdflatex -shell-escape -synctex=1' "${1%.*}"
Rscript -e ".libPaths('~/Rlibs');
library('patchDVI');patchSynctex('${1%.*}.synctex.gz')"

	[[alternative HTML version deleted]]

