为什么我从非常简单的例子中得到了“!未定义的控制序列”?

为什么我从非常简单的例子中得到了“!未定义的控制序列”?

我从一个简单的参考书目示例中收到一条非常意外的错误消息。

我有一个 .tex 和一个 .bib 文件:

测试.tex:

\documentclass[letterpaper]{article}

\begin{document}

This is a citation: \cite{pearl88probabilistic}.

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

b.围兜:

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

然后我运行(在 Windows 上使用 MikTeX 2.9):

pdflatex test
bibtex test
pdflatex test

并收到错误:

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

使用latex而不是pdflatex,或者使用不同的 bibtex 条目,会产生相同的错误。

以下是 test.bbl 中有问题的一行:

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

.tex 和 .bib 输入看起来没问题,为什么我会收到此错误消息?

这是我所做操作的完整(但已清理)跟踪(我用“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}

答案1

提示位于 中named.bst,其中包含文件顶部附近:

% 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.

因此你应该遵循以下建议:

\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}

如果我不遵循建议,就会得到错误。如果我按照建议定义命令,就不会得到错误。

答案2

按照@Troy 的建议,是这样的吗?

\documentclass[letterpaper]{article}



\usepackage{natbib}
\bibliographystyle{named}



\begin{document}

This is a citation: \citet{pearl88probabilistic}.

\bibliography{b}
\end{document}

答案3

很好,它解决了我的引用问题:

之前(错误):

\begin{document}

This is a citation: \citet{pearl88probabilistic}.

\bibliographystyle{named}
\bibliography{b}

\end{document}

之后(无错误):

\usepackage{natbib}
\bibliographystyle{named}

\begin{document}

This is a citation: \citet{pearl88probabilistic}.

\bibliography{b}

\end{document}

相关内容