I am creating a pdf-book with bookdown using the following YAML:

site: bookdown::bookdown_site
geometry: "left=4cm,right=3cm,top=3cm,bottom=3cm"
subparagraph: true
    latex_engine: xelatex
    fig_caption: yes
    toc: false
    citation_package: natbib
      before_body: frontpage.tex
      after_body: after_body.tex
      in_header: preamble.tex
fontsize: 11pt
linestretch: 1.2
documentclass: book
bibliography: [packages.bib,library.bib]
biblio-style: [plainnatnew.bst]
link-citations: yes

In my preamble.tex i use \setcitestyle{numbers,square,comma} to specify citation type. I have created a new biblio-style to match my needs for the bibliography, where most of it is similar to the plainnat.bst style (i have specified to remove URLs from article entries, f. ex.). I cite in R like this: [@Reference1996].

I use Zotero to create the .bib file, with betterBibtex. The R-packages i use is found in the packages.bib, created by knitr::write.bib().

Last week this worked perfectly, with no errors. However, suddenly I get a lot of this error:

Package natbib Warning: Citation X on page 9 undefined on input line 271

Additionally, I get a bunch of these

Warning--empty publisher/year in X

However, in the specific citation, both Year and publisher are present.

After seeing this error I tried to update all the R packages (including bookdown, markdown and knitr), reinstalled LaTeX with reinstall_tinytex(), re-created both .bib files, and tried compiling without the plainnat.new specification, but nothing seem to work. I have double-checked the .bib files, and they have all the entries that natbib says it cannot find. Also, I have deleted all files created by bookdown and re-ran everything from the start.

Does anyone know what may be the issue? As everything seemed to work fine before I do not understand what the issue may be... However, I did notice that this issue arose after i used bookdown::preview_chapter() on a single chapter of the book to Word-format, but this haven't changed any settings in the files as far as I am aware.

This is my preamble.tex:

  {\normalfont\LARGE\bfseries}{\thechapter}{1em}{}  % set title format
\titlespacing*{\chapter}{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\captionsetup[figure]{textfont={small,it}, labelfont={normalsize,bf,it}}  % set figure caption font size and style
\renewenvironment{figure}[1][2] {
} {
\fancyhead[LO]{\slshape \rightmark} %section
\fancyhead[RE]{\slshape \leftmark} % chapter
\setlength{\headheight}{27.7pt} % as requested by fancyhdr's warning
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\renewcommand{\chaptermark}[1]{%    % change settings for including headers
    \markboth{Chapter \thechapter{}: #1}{}%
  • Have you checked that the cite of the text ( @X or [@X]) correspond really with one reference in the .bib file? that is, that really there are some reference as @article{X, author={X... but not @article{, author={X... nor @article{whatever, author={X... ? – Fran Sep 23 '19 at 19:11
  • @Fran The .bib file is correctly formatted. Since everything worked fine previously and suddenly stopped working i wondered what the cause may be... – Haakonkas Sep 24 '19 at 9:45
  • Try to reduce your document and .bib removeing cites and references. At some point the error will be lost and you will know where it is. If the error persist even with only one cite and one reference and the mistake is not evident for you , post both the complete .Rmd file and the .bib file. – Fran Sep 26 '19 at 19:45

After a lot of detective work I managed to identify the issue: Two entries in the library.bib-file were almost identical, the only thing different between them was the case of a letter

Martines-Martines1998 and Martines-martines1998. Nice to know that case doesn't matter in the .bib file. I changed one of the entries, then the book compiled as before.

  • To avoid undefined citations take a look to JabRef: It change automatically duplicated keys (even in this case) and also detect duplicated entries even if the keys do not match (or even if there are minor differences in entry fields). On the other hand, also can help with undefined references due to errors in the text citations, as you can copy easily the keys of the selected entry/entries with Ctrl+Shift+K and then paste in the editor without make mistakes. – Fran Sep 30 '19 at 23:29

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.