2

I'm trying to get references working in a knitr Rnw document using ESS, AUCTex, TeXLive, and natbib.

Here is a minimal example:

\documentclass{article}
\usepackage{natbib}

\begin{document}

<<setup, include=FALSE, cache=FALSE>>=
library(knitr)
@

<<normal-sample, echo=FALSE>>=
x <- rnorm(100)
plot(x)
@

The moon in June is like a big balloon \citep{smith2012}.

\bibliographystyle{apalike}
\bibliography{/path/to/my/references/refs}

\end{document}

When I run ess-swv-knit then ess-swv-PDF with M-n r then M-n P, I see errors like:

Package natbib Warning: Citation Smith2014 on page 23 undefined on input line 374

This is what I think is going on. Running ess-swv-PDF simply calls pdflatex, but to get the citations right, the correct number of bibtex and pdflatex commands need to be run.

Is there an way to do this by simply running M-n r then M-n P?

jrm
  • 121

2 Answers2

0

Setting the variable ess-swv-pdflatex-commands to latexmk, so that running ess-swv.el (M-n P) calls latexmk instead of pdflatex seems to be working, although I haven't tested extensively.

Update: I've been using this for a few days now and latexmk is doing the right thing in that it only runs what is necessary to generate the final document.

jrm
  • 121
0

A solution not tested (I don't use ESS):

Write this in your init.el (or other emacs file of course):

(defun compile-ESS ()
  "compilation" 
  (ess-swv-PDF)
  (tex-bibtex-file)
  (ess-swv-PDF)
  (ess-swv-PDF)
)
(global-set-key "the shortcut you want to use" 'compile-ESS)

Replacing the shortcut you want to use by the one you want to use. Try to not use one that is already bind.

Then M-n r and the shortcut you want to use to do what you wanna perfom.

Romain Picot
  • 6,730
  • 4
  • 28
  • 58