[Tex/LaTex] get “! Undefined control sequence” in bbl from very simple example

bibtex

I am getting a very unexpected error message from a simple bibliography example.

I have a .tex and a .bib files:

test.tex:

\documentclass[letterpaper]{article}

\begin{document}

This is a citation: \cite{pearl88probabilistic}.

\bibliographystyle{named}
\bibliography{b}
\end{document}

b.bib:

@BOOK{pearl88probabilistic,
  AUTHOR = {J. Pearl},
  YEAR = {1988},
  title = {Probabilistic reasoning in intelligent systems: networks of plausible inference},
  PUBLISHER = {Morgan Kaufmann, San Mateo (Calif.)},
}

Then I run (using MikTeX 2.9 on Windows):

pdflatex test
bibtex test
pdflatex test

and get an error:

("C:\dir\test.bbl"
! Undefined control sequence.
<argument> \protect \citeauthoryear
                                    {Pearl}{1988}
l.3 ...horyear{Pearl}{1988}]{pearl88probabilistic}

Using latex instead of pdflatex, or using a different bibtex entry, produces the same error.

Here's the offending line in test.bbl:

\bibitem[\protect\citeauthoryear{Pearl}{1988}]{pearl88probabilistic}

Why am I getting this error message, given that the .tex and .bib inputs seem fine?

Here's the full (but cleaned up) trace of what I did (I replaced my user's directory by "dir"):

C:\dir>pdflatex test
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (MiKTeX 2.9)
entering extended mode

LaTeX2e <2011/06/27>
Babel <v3.8m> (...)
("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\base\size10.clo"))
No file test.aux.

LaTeX Warning: Citation `pearl88probabilistic' on page 1 undefined on input lin
e 6.

No file test.bbl.
[1{C:/ProgramData/MiKTeX/2.9/pdftex/config/pdftex.map}]
("C:\dir\test.aux")

LaTeX Warning: There were undefined references.

 )<C:/Program Files (x86)/MiKTeX 2.9/fonts/type1/public/amsfonts/cm/cmbx10.pfb>
<C:/Program Files (x86)/MiKTeX 2.9/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on test.pdf (1 page, 22197 bytes).
Transcript written on test.log.

C:\dir>bibtex test
This is BibTeX, Version 0.99d (MiKTeX 2.9)
The top-level auxiliary file: test.aux
The style file: named.bst
Database file #1: bib.bib

C:\dir>pdflatex test
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (MiKTeX 2.9)
entering extended mode

("C:\dir\test.tex"
LaTeX2e <2011/06/27>
Babel <v3.8m> (...)("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\base\article.cls"
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
("C:\Program Files (x86)\MiKTeX 2.9\tex\latex\base\size10.clo"))
("C:\dir\test.aux")

LaTeX Warning: Citation `pearl88probabilistic' on page 1 undefined on input lin
e 6.


("C:\dir\test.bbl"
! Undefined control sequence.
<argument> \protect \citeauthoryear
                                    {Pearl}{1988}
l.3 ...horyear{Pearl}{1988}]{pearl88probabilistic}

Best Answer

The hint is found in named.bst, which contains near the top of the file:

% The LaTeX style has to have the following (or similar)
%     \let\@internalcite\cite
%     \def\cite{\def\citeauthoryear##1##2{##1, ##2}\@internalcite}
%     \def\shortcite{\def\citeauthoryear##1{##2}\@internalcite}
%     \def\@biblabel#1{\def\citeauthoryear##1##2{##1, ##2}[#1]\hfill}
% which makes \shortcite the macro for short citations.

So you should follow the advice:

\documentclass[letterpaper]{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
%
@BOOK{pearl88probabilistic,
  AUTHOR = {J. Pearl},
  YEAR = {1988},
  title = {Probabilistic reasoning in intelligent systems: networks of plausible inference},
  PUBLISHER = {Morgan Kaufmann, San Mateo (Calif.)},
}
\end{filecontents*}

\makeatletter
    \let\@internalcite\cite
    \def\cite{\def\citeauthoryear##1##2{##1, ##2}\@internalcite}
    \def\shortcite{\def\citeauthoryear##1{##2}\@internalcite}
    \def\@biblabel#1{\def\citeauthoryear##1##2{##1, ##2}[#1]\hfill}
\makeatother

\begin{document}

This is a citation: \cite{pearl88probabilistic}.

\bibliographystyle{named}
\bibliography{\jobname}
\end{document}

If I don't follow the advice, I get your error. If I define the commands as suggested, I do not.