TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

One of the things I love about emacs is being able to specify a master file, then compile an included .tex file - I just use C-c C-b

For sweave documents, I have the following layout:

  • master.Rnw

    • \SweaveInput{chapter1}

    • \SweaveInput{chapter2}

    • \SweaveInput{chapter3}

I would like to use the same idea as C-c C-b to only sweave/latex chapter1. Is this possible in emacs?

share|improve this question

I am no expert on Sweave, but it seems to be integrated in the ESS package with an Rnw and Snw mode where you can have it run Sweave or R on the buffer code directly. So that might be what you want if it's just to preview the sweave file result.

I also found details on integrating ESS more tightly with AUCTeX here. It's not tested, but C-c C-c is mapped to run the command on the master file, so it might work for you.

While this is not a complete answer, I hope it helps. I put it in WIKI mode so you can add more details if you find anything more.

share|improve this answer
That should be "ESS" not "EES" – Seamus Feb 16 '11 at 14:17
thanks, I fixed it. – Mortimer Feb 16 '11 at 16:32
@Mortimer no you changed it the wrong way! – Seamus Feb 16 '11 at 16:41
I Fixed it now... – Seamus Feb 16 '11 at 16:42
@Seamus, thanks, must have been tired ;) – Mortimer Feb 17 '11 at 9:12

I doubt this sort of thing is possible, because running tex just on chapter 1 won't work, since it will need the common preamble which is presumably in the master document. And if you run tex on the master, then it doesn't know to only do the first chapter.

One way to do what you want is to use \includeonly to tell the compiler which files to include. (I expect the \SweaveInput has a similar command...) See here for some details

If the problem is you want emacs to treat .Rnw files like .tex files, try adding this to your .emacs:

(add-to-list 'auto-mode-alist '("\\.Rnw~?$" . latex-mode))
share|improve this answer
In emacs C+c C+b copies the preamble and the "included file" into a temporary file called _region.tex. It then latexs that file. Of course, chapter numbers, etc, are off. But it's very handy for quick checks. – csgillespie Jan 17 '11 at 11:09
@csgillespie That's interesting. I've always just compiled with C-c C-c. Why doesn't exactly the same thing work with sweave documents? I'd have thought the process would be identical... – Seamus Jan 17 '11 at 11:20
To sweave a document you use the command M-n s and it doesn't (seem) to have any idea about the concept of a master file. I tried to hack my .emacs, but things quickly got messy. For example, auctex expects .tex file extensions. At this point, I thought there must be a better way. – csgillespie Jan 17 '11 at 11:28
@csgillespie C-c C-b type Other and then try typing Sweave at the next prompt. Does this work? – Seamus Jan 17 '11 at 11:56
No. I think it something to do with the file extensions (they're .Rnw not .tex). – csgillespie Jan 17 '11 at 12:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.