1

I am trying to cite the following

@article{ghahramani2015probabilistic,
title={Probabilistic machine learning and artificial intelligence},
author={Ghahramani, Zoubin},
journal={Nature},
volume={521},
number={7553},
pages={452--459},
year={2015},
publisher={Nature Publishing Group}
}

with

\citet{ghahramani2015probabilistic}

But I keep getting the error

Package natbib Error: Bibliography not compatible with author-year citations.

But that citation contains a year and an author. I am importing natbib with the square option, and using \bibliographystyle{alpha}. Any idea?

I already removed all files and compiled everything again, but I get the same error.

I am compiling with

"pdflatex" -synctex=1 -interaction=nonstopmode %.tex|"bibtex" %.aux|"pdflatex" -synctex=1 -interaction=nonstopmode %.tex|"pdflatex" -synctex=1 -interaction=nonstopmode %.tex

which I have a template that I always used to compile bibliographies.

3 Answers 3

4

To extract the author and the year for a citation, natbib needs a bibliography entry (in the bbl) which starts like this:

\bibitem[Ghahramani(2015)]{ghahramani2015probabilistic}

The important part is the syntax of the optional argument [Ghahramani(2015)]. natbib scans this and splits it in author and year.

With \bibliographystyle{alpha} the entry looks like this:

\bibitem[Gha15]{ghahramani2015probabilistic}

This is unusable for natbib, there is no year or author it can extract.

If you want to use natbib you should use a compatible style like e.g. plainnat instead of alpha. If you want an alpha style you could try to create your own bst with https://tex.stackexchange.com/a/495642/2388. Or you can switch to biblatex and biber which supports more styles.

4
  • Ohh, beaten again by 45 seconds. What surprised me was that at least on my machine I didn't get the error from alpha that I expected and it turns out natbib checks the style name and automatically forces numbers when it sees \bibliographystyle{alpha}, but that is overridden by the square option used by the OP.
    – moewe
    Commented Jul 7, 2020 at 7:25
  • @moewe I didn't really check under which conditions it errors or warns as there was no real example. The main point imho is anyway to understand that not every style works with natbib. Commented Jul 7, 2020 at 7:27
  • Absolutely, that's the main point. I was just confused because in a short MWE I made up for my answer I couldn't reproduce the error with \bibliographstyle{alpha} - and now I'm just impressed by how clever natbib is.
    – moewe
    Commented Jul 7, 2020 at 7:34
  • you should not use it. It is created by bibtex. Look in the bbl-file. Commented Jul 7, 2020 at 14:58
3

The error message

Package natbib Error: Bibliography not compatible with author-year citations.

has two major causes:

  • Either it can be taken at face value and then says that the bibliography style you used is incompatible with natbib's authoryear citation option
  • or the style you use is in principle compatible with natbib's authoryear citation option, but certain entries are missing author/editor or year fields.

All that is due to the way author-year citations are implemented in natbib. The usual bibliography that is created by BibTeX is essentially a glorified enumerate environment and \cite works just like a \ref to a \label (you can read more about this at A design question: citation commands). In order to be able to produce flexible author-year citations natbib uses a clever way to make the author and year known in the document. But that means that the bibliography created by BibTeX must have a particular format, this is explained in a code comment in natbib.sty

 % If author-year citations are selected, \bibitem must have one of the
 %   following forms:
 %   \bibitem[Jones et al.(1990)]{key}...
 %   \bibitem[Jones et al.(1990)Jones, Baker, and Williams]{key}...
 %   \bibitem[Jones et al., 1990]{key}...
 %   \bibitem[\protect\citeauthoryear{Jones, Baker, and Williams}{Jones
 %       et al.}{1990}]{key}...
 %   \bibitem[\protect\citeauthoryear{Jones et al.}{1990}]{key}...
 %   \bibitem[\protect\astroncite{Jones et al.}{1990}]{key}...
 %   \bibitem[\protect\citename{Jones et al., }1990]{key}...
 %   \harvarditem[Jones et al.]{Jones, Baker, and Williams}{1990}{key}...

You can only get author-year citations if your \bibliographystyle produces \bibitems looking like this. Not all styles are compatible with this format.

If author or year fields are missing, even styles that are in principle compatible with this format can produce a \bibitem that can not be parsed by natbib according to the above specification. In that case you will also get this error.

A 'solution' that works for both problems is to forget about author-year citations and tell natbib to use numeric citations by loading it with the numbers option. Then natbib does not try to extract author-year data for normal citations. \citet may still not work as desired though. So it is somewhat pointless to use natbib with an incompatible style.

If the style is incompatible the other straightforward solution is to choose a compatible style. The natbib styles plainnat, abbrvnat, unsrtnat are obviously a good natbib compatible choice, but there are many more styles out there that work.

If the problem is just caused by your entry missing author/editor or year fields, the obvious solution is to try and supply these fields. If that is not possible you may get a slightly better result if you add placeholder values for those fields. Like author = {N.N.}, and year = {n.d.},


natbib has a very clever method to avoid this kind of error for some common styles: If you just load natbib without any additional citation style options \usepackage{natbib} some styles automatically force the numbers option without you explicitly setting it and even if you have passed the authoryear option. But that method is disabled when you use the citation style option square.

Compare the following MWE with and without the square option.

\documentclass{article}
\usepackage[square]{natbib}

\begin{filecontents}{\jobname.bib}
@article{ghahramani2015probabilistic,
  title   = {Probabilistic machine learning and artificial intelligence},
  author  = {Ghahramani, Zoubin},
  journal = {Nature},
  volume  = {521},
  number  = {7553},
  pages   = {452--459},
  year    = {2015},
}
\end{filecontents}

\begin{document}
\citep{ghahramani2015probabilistic}
\citet{ghahramani2015probabilistic}
\bibliographystyle{alpha}
\bibliography{\jobname}
\end{document}
0
0

I added the options numbers while importing natbib and now I don't get the error anymore. Not sure why though.

You must log in to answer this question.