[ESS] ESS (Sweave) and AucTeX integration

Kiermeier, Andreas (PIRSA - SARDI) Kiermeier.Andreas at saugov.sa.gov.au
Tue Jun 19 03:35:42 CEST 2007


Hi folks,

David Whiting has previously published a set of functions which a very
useful for sweaving and consequent latex-ing. The only thing that has
not satisfied me (which is not a reflection on David's efforts) is that
they are somewhat separate from AucTeX (some hard-coding is involved).

I've played around with AucTeX and ESS a bit today and am happy to
report that I have come up with an alternative approach, which may be
useful for some of you.  The only piece of code required in your .emacs
file is the following.


(add-to-list 'auto-mode-alist '("\\.Rnw\\'" . Rnw-mode))
(add-to-list 'auto-mode-alist '("\\.Snw\\'" . Snw-mode))

;; Linking ESS with AucTex
(add-hook 'Rnw-mode-hook
	  (lambda ()
	    (add-to-list 'TeX-command-list
			 '("Sweave" "R CMD Sweave %s" 
			   TeX-run-command nil t :help "Run Sweave") t)
	    (add-to-list 'TeX-command-list
			 '("LatexSweave" "%l \"%(mode)\\input{%s}\"" 
			   TeX-run-TeX nil t :help "Run Latex after
Sweave") t)
	    (setq TeX-command-default "Sweave")))



The first two lines may already be in your .emacs file. Since Snw-mode
is a synonym (at least for now) to Rnw-mode we only need to modify the
Rnw-mode-hook.

The code above adds two new commands to "Command" menu when you visit a
.Rnw (or .Snw) file. These new commands are
* Sweave:  Sweave the current file and produce a .tex file (the new
default for .Rnw files)
* LatexSweave: Run "latex" or "pdflatex" on the .tex file

Both of these commands can also be invoked when pressing C-c C-c inside
a documentation chunk in the .Rnw file - this is similar to the way you
would process a .tex file.

Note: Sweaving is done by invoking the Sweave.sh script inside the \bin
folder of your R installation (comes with R).

Note: latex or pdflatex is invoked based on whether "PDF Mode" is
enable" (see "TeX Options" under the "Commands" menu).

Note: Once the .tex file has been successfully and fully processed (you
may need to run bibtex and latex several times - in the usual way), a
further press of C-c C-c will prompt you for "View" which will give you
the default viewer (pdf or dvi) - all in the usual AucTeX compile cycle.

I have only tried this under the following configuration:
* Windows XP (SP2)
* GNU Emacs 22.1.1 (i386-mingw-nt5.1.2600) of 2007-06-02 on RELEASE
* AucTeX 11.83
* ESS 5.3.4

Any comments are welcome.

Cheers,

Andreas


_____________________________
Dr Andreas Kiermeier
Senior Statistician
Food Innovation & Safety
South Australian Research & Development Institute
33 Flemington Street, Glenside, SA, 5065

Ph:	+61 8 8207 7884
Fax:	+61 8 8207 7854
Mob:	0423 028 565

Email: Kiermeier.Andreas at saugov.sa.gov.au
Web:   http://www.sardi.sa.gov.au/
_____________________________
If you would like to correspond with me in a secure way, using public
key encryption, please contact me directly for details of my GPG public
key or visit the SARDI website, where you can download my public key
from my personal staff page.

The information in this e-mail and attachments (if any) may be
confidential and/or legally privileged. If you are not the intended
recipient, any disclosure, copying, distribution or action taken is
prohibited. SARDI, The South Australian Research and Development
Institute, is the research division of Primary Industries and Resources
(SA)




More information about the ESS-help mailing list