Use Sweave with TeXmaker and make SyncTeX work properly with it

October 13, 2013

(This article was first published on Hidden Treasures, and kindly contributed to R-bloggers)

Although there are many materials online relating to Sweave and its workflow, I could not find any source on how to make SyncTeX work properly with my favorite TeXmaker editor. I hope that you know the Sweave ( is a tool that allows to embed the R code for complete data analyses in LaTeX documents.

If you use TeXmaker as your main editor of Sweave files (*.Rnw), it is time now to fix the annoying problem with SyncTeX and Sweave. Have ever compiled an .Rnw (Sweave) file to a PDF and tried to reverse sync the PDF using SyncTeX with the source in TeXmaker or other Sweave compatible editor? The result was always the same: TeXmaker/editor opens the .tex file instead of .Rnw source. The problem was even worse, if you did not notice that and you could continue editing the .tex file instead of .Rnw! Although TeXmaker supports SyncTeX, the synctex information (in the .synctex.gz file) was originally designed to work only with .tex sources. Postprocessing of the .synctex.gz file is necessary to fix this.
Due to efforts of Duncan Murdoch who developed the patchDVI R package, we can fix it and make it possible to jump from compiled PDF file directly to the .Rnw source of an Sweave document. After many trial and error attempts I have found a configuration that does work with TeXmaker. Below is my configuration that is successful for the following software setup:

  • Ubuntu 12.10 32bit

  • TeXmaker v.4.0.4 (compiled with Qt 4.8.3 and Poppler 0.20.4)

  • pdfLaTeX / pdfTeX, Version 3.1415926-2.5-1.40.14 from TeX Live 2013 distribution (format=pdflatex 2013.7.15)

  • R (R version 3.0.2 (2013-09-25) -- "Frisbee Sailing")

  • patchDVI R package version 1.9 (works with Sweave and document previewers to facilitate editing: it modifies the links that LaTeX puts into the output so that they refer to the original source)


  1. I assume that you have R, LaTeX and TeXmaker installed.

  2. Install the patchDVI package ( the package is available online at ) Start R, and run the command:

  3. Open TeXmaker and go to Options menu -> Configure Texmaker -> Quick Build. Select Quick Build command 'User' and copy the following:

  4. In all Sweave (.Rnw) documents, the following lines must be included:

  5. Open your .Rnw file in TeXmaker and compile it to PDF using F1 user command

  6. When PDF is successfully compiled, check whether sync works or not by: In TeXmaker, set cursor to the word and open right-click mouse menu, select "Jump to pdf", if everything is Okay, the viewer shows a line with the word. Holding key, double-click any word n PDF viewer, the cursor moves to right place of the .Rnw source file.

Wow! It works!

To leave a comment for the author, please follow the link and comment on his blog: Hidden Treasures. offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.