0

I use LaTex to compile documents in Rstudio, and use the 'natbib' package for bibliographies. My university upgraded all computers to Windows 10 a couple months ago. After the change, I reinstalled R (version 3.6.2), Rstudio, and MikTex (version 2.9), and updated packages. I have had trouble compiling documents ever since. Most pertinently, when I open a .Rnw with citations in it and hit the "Compile PDF" button in Rstudio, it usually fails, even if the document and associated .bib file are error-free. The errors in the log read "Package natbib warning: citation 'xxx' on page x undefined on input line xxx", and "No file dissertation.bbl. Package natbib Warning: There were undefined citations."

It would seem that this .bbl file isn't getting written by whatever process is initiated after I hit the "Compile PDF" button perhaps? However, for a .Rnw titled 'test_for_latex_stackexchange_post.Rnw', if I run the commands

Sweave('test_for_latex_stackexchange_post.Rnw')
system("latex test_for_latex_stackexchange_post")
system("bibtex test_for_latex_stackexchange_post")
system("latex test_for_latex_stackexchange_post")
system("latex test_for_latex_stackexchange_post")

(indeed running the final "latex " command twice), the "Compile PDF" button will (usually) work. I've tried a lot of stuff I've found in other posts, and while it seems to be better than it was when I first reinstalled everything after the Windows 10 upgrade, I am not satisfied. I want the "Compile PDF" button to work properly all the time.

A sample .Rnw, with all associated auxiliary files that were written after a successful compile using the commands in the code chunk above (contained in the file 'test_for_latex_stackexchange_post.R') and a .bib (and assoicated .bst file, which I don't really understand) are in a Google Drive folder at

https://drive.google.com/drive/folders/14ShNc91R-s8nh8LVvkXkrEG9-K7522Bs?usp=sharing

Perhaps this isn't useful if the log file doesn't contain all the original errors. Any guidance anyone might provide would be greatly appreciated, and I will gladly provide additional information if necessary. I am a latex infant.

0

I had similar problems compiling my .Rnw file into a PDF in RStudio and getting undefined citation warnings from natbib. I tried compiling the .Rnw in RStudio and then compiling the .tex file in TeXworks, but compiling the .tex would work the first time and fail spectacularly when I ran it a second time (with vague error messages). Reinstalling MiKTeX worked but the issue came back. Eventually, I found a comment online that suggested underscores in the file name or path might be an issue.

Once I removed the underscore from the directory name, I was able to compile the .tex file in TeXworks and get the citations from natbib to appear correctly. It's not elegant, but it works - I hope this saves someone else the same headache!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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