Use Sweave with TeXmaker and make SyncTeX work properly with it
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 (http://www.stat.uni-muenchen.de/~leisch/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)
- I assume that you have R, LaTeX and TeXmaker installed.
- Install the patchDVI package ( the package is available online at http://r-forge.r-project.org/projects/sweavesearch ) Start R, and run the command:
- Open TeXmaker and go to Options menu -> Configure Texmaker -> Quick Build. Select Quick Build command 'User' and copy the following:
- In all Sweave (.Rnw) documents, the following lines must be included:
- Open your .Rnw file in TeXmaker and compile it to PDF using F1 user command
- 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
news and tutorials
on topics such as: visualization (ggplot2
), programming (RStudio
, Web Scraping
) statistics (regression
, time series
) and more...
If you got this far, why not subscribe for updates
from the site? Choose your flavor: e-mail
, or facebook