I am writing and have been writing several documents using Sweave. In the past, I have been able to create a .bib file and cite using the natbib package with apa styling. Since updating (to enjoy the lovely jobs feature) I can not compile my old .rnw files that used to work.
I've spent hours searching (like this person) around and the only solution that has worked is to open the .tex file that is generated and compile there (this works flawlessly in both cases below). However, using two programs is less than ideal and I'd like to get RStudio to build the pdf directly.
There was some discussion online that perhaps RStudio is not running the BibTex command to create the .bbl file. This seems to be correct because after I build the pdf in TeXStudio (which creates the .bbl file) RStudio will use it and build the pdf properly and fail again once the .bbl file is deleted or moved.
Another approach that seems to work is to
- Compile pdf to create the .aux file (it fails)
- Run bibtext on the filename in the terminal to create the .bbl file
- Compile pdf (it fails)
- Compile pdf (it works)
This seems to make it pretty clear that bibtex isn't being run.
Global Settings:
- Weave Rnw files using knitr (doesn't work with sweave either)
- Typeset Latex into PDF using pdfLaTeX (doesn't work with XeLaTeX either)
- Clean auxiliary output after compile is checked (unchecked for the terminal solution above that requires the aux file.)
METHOD 1:
BIB:
@article{majumder2017,
title={Higher Rates Of Hate Crimes Are Tied To Income Inequality},
author={Majumder, Maimuna},
journal={FiveThirtyEight. Last modified January},
volume={23},
year={2017}
RNW:
\documentclass{article}
\usepackage{natbib}
\bibliographystyle{apalike}
\begin{document}
I want to cite this \cite{majumder2017}.
\bibliography{bib}
\end{document}
METHOD 2:
RNW:
\documentclass{article}
\usepackage{natbib}
\usepackage{filecontents}
\bibliographystyle{apalike}
\begin{document}
I want to cite this \cite{majumder2017}.
\begin{filecontents}{bibliography.bib}
@article{majumder2017,
title={Higher Rates Of Hate Crimes Are Tied To Income Inequality},
author={Majumder, Maimuna},
journal={FiveThirtyEight. Last modified January},
volume={23},
year={2017}
}
\end{filecontents}
\bibliography{bibliography}
\end{document}