[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX] ESS (Sweave) and AucTeX "integration"

From: Kiermeier, Andreas \(PIRSA - SARDI\)
Subject: [AUCTeX] ESS (Sweave) and AucTeX "integration"
Date: Wed, 20 Jun 2007 09:22:04 +0930

Dear all, 

I posted this message to the ESS mailing list yesterday and received a
suggestion that this may also be of interest to members of this list (so
apologies for cross-posting).

Being a lisp neophyte I suspect that there are improvements which could
be made. In particular, I would be interested in improving the "compile
cycle" (e.g. Sweave -> Latex ->Bibtex -> Latex -> View). I read that
AucTeX tries to guess the next command, which has always worked well for
me, except for here (its different to what AucTeX is used to).

Any suggestions would be greatly welcome.



-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
Kiermeier,Andreas (PIRSA - SARDI)
Sent: Tuesday, 19 June 2007 11:06
To: address@hidden
Subject: [ESS] ESS (Sweave) and AucTeX integration

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

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 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.



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
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

address@hidden mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]