I am using WinEdt 9.1 with RManager and pdflatex to knit PDF files from Rnw files. The process generally works well. But I cannot use "inverse search" from my PDF documents to my Rnw files. When I try to do so, WinEdt opens the corresponding .tex file -- not the .Rnw file that I actually need to edit. How may I fix this problem?

I understand that SyncTeX "doesn't know" about Rnw files. But I gather that this is exactly the problem that the "patchDVI" package for R is supposed to solve -- and that is why RManager requires that the package be installed. In any case, I do have the patchDVI package installed, but inverse search from my PDFs still takes me to the intermediate .tex files, not to the .Rnw files that I need to edit.

I have no problem using inverse search when my documents are ordinary .tex files instead of .Rnw files.

A search of this site turned up a few related posts, including a link to [this post]. A comment on the post led me to hope that I could solve the problem by going to Options > Execution Modes > PDFLaTeX and adding the "synctex=-1" switch when pdflatex is called. But that didn't help.

1 Answer 1


The solution turns out to be simple: when using knitr, one must include

knitr::opts_knit$set(concordance = TRUE)

in a code chunk in the file. (This line is equivalent to \SweaveOpts{concordance=TRUE} for those who use Sweave instead of knitr.) When that line is included, forward and inverse search work as expected.

There is one qualification. For whatever reason, there seems to be a conflict between the cache.lazy = FALSE chunk option and the setting of the concordance option: if cache.lazy = FALSE is set for a chunk, and the concordance = TRUE line is in that chunk, the concordance = TRUE line will have no effect. In other words, cache.lazy = FALSE seems to negate the concordance = TRUE line.

There is a simple solution: just specify knitr::opts_knit$set(concordance = TRUE) in an early chunk, before any chunk that has the cache.lazy = FALSE option.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .