Site icon R-bloggers

Emacs: AucTeX + Rubber + Sweave

[This article was first published on Super Nerdy Cool » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I got rubber to work with auctex and sweave (Rnw) files with the help of this.

Basically, combined with my other stuff, I tweaked my .emacs file to look like:

;;following is AucTeX with Sweave -- works
;;http://andreas.kiermeier.googlepages.com/essmaterials
(setq TeX-file-extensions
      '("Snw" "Rnw" "nw" "tex" "sty" "cls" "ltx" "texi" "texinfo"))
(add-to-list 'auto-mode-alist '("\\.Rnw\\'" . Rnw-mode))
(add-to-list 'auto-mode-alist '("\\.Snw\\'" . Snw-mode))
(add-hook 'Rnw-mode-hook
(lambda ()
(add-to-list 'TeX-command-list
'("Sweave" "R CMD Sweave %s"
TeX-run-command nil (latex-mode) :help "Run Sweave") t)
(add-to-list 'TeX-command-list
'("LatexSweave" "%l %(mode) %s"
TeX-run-TeX nil (latex-mode) :help "Run Latex after Sweave") t)
;; following 3 lines for rubber, taken from same site as next paragraph, http://www.nabble.com/sweave-and-auctex-td23492805.html, xpdf to open
(add-to-list 'TeX-command-list
'("RubberSweave" "rubber -d %s && open '%s.pdf'" 
TeX-run-command nil t) t) 
(setq TeX-command-default "Sweave")))

;; AucTeX with rubber
;;http://www.nabble.com/sweave-and-auctex-td23492805.html
(eval-after-load "tex"
   '(add-to-list 'TeX-command-list
                ;;'("Rubber" "rubber -d %t && xpdf '%s.pdf'" TeX-run-command nil t) t)) ;; change by vinh
                '("Rubber" "rubber -d %t && open '%s.pdf'" TeX-run-command nil t) t))

Now, when a *.Rnw file is open, I can do C-c C-c, select Sweave. Then repeat, select RubberSweave (or LatexSweave).

To leave a comment for the author, please follow the link and comment on their blog: Super Nerdy Cool » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.