-2

I am using Sweave in RStudio to build a pdf with the following settings:

Weave Rnw files using: knitr

Typeset LaTeX into PDF using: pdfLaTeX

I am also on Windows and using MiKTeX.

The pdf successfully compiles each time, with the exception of the citations, which are appearing as [? ].

Here is an example of the file, called filename.rnw:

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

@

\documentclass{article}

\begin{document}

The lumen is calculated by weighting a spectra of light by the photopic luminosity function \cite{CVRL2008}

\reftitle{References}

\externalbibliography{yes}
\bibliography{bibliography}

\end{document}

With the following bibliography (bibliography.bib) file:

@misc{CVRL2008,
    title = "CIE (2008) physiologically-relevant 2-deg V($\lambda$) luminous efficiency functions",
    author = "CVRL",
    organization = "The Colour & Vision Research laboratory",
    type = "Database",
    howpublished = "ONLINE",
    year   = "2008",
    url = "http://www.cvrl.org/"
}

And here is the .pdf that is built

"The lumen is calculated by weighting a spectra of light by the photopic luminosity function [?]

References"

I first resolved this issue with the following steps:

  1. Ensuring that MiKTeX was installed in the same directory as R & RStudio,

  2. Making sure the user/administrator updates were not out of sync in MiKTeX

  3. Switching to admin mode

  4. Running the following commands in Command Prompt, in accordance with this thread (https://tex.stackexchange.com/questions/63852/question-mark-or-bold-citation-key-instead-of-citation-number):

    latex filename

    bibtex filename

    latex filename

    latex filename

  5. Compiling the .pdf

However, every time I add an additional reference I need to run bibtex and latex in the command prompt to update the .bbl file, so the references will appear in the .pdf when I compile it.

Is there a way to permanently fix this?

Any help would be greatly appreciated.

ZekeMarshall
  • 131
  • 5

1 Answers1

0

I have now resolved this issue. The problem appeared to be the fact that I was using the "Compile pdf" button rather than running knitr::knit2pdf("filename.rnw") in the console; adding new references and compiling the pdf via the console now updates the .bbl file, in-text references, and bibliograpy each time. This problem seems to be documented in this thread (Difference: "Compile PDF" button in RStudio vs. knit() and knit2pdf()).

ZekeMarshall
  • 131
  • 5