我正在尝试在 Rmarkdown 中编写一篇 PDF 文章,并希望包含使用 Latex natbib 引文包的科学参考书目。
不幸的是,我收到一条错误消息。
这是一个最小示例,包含 Rmarkdown 文档最重要的细节:
---
output:
pdf_document:
citation_package: natbib
bibliography: test_library.bib
---
@GoelThakor2008
文件 test_library.bib 仅包含一篇文章,为简洁起见:
@article{GoelThakor2008,
year = {2008},
title = {{Overconfidence, CEO selection, and corporate governance}},
author = {Goel, Anand M and Thakor, Anjan V},
journal = {Journal of Finance},
pages = {2737 -- 2784},
volume = {63},
month = {00}
}
使用 Rstudio 将 Rmarkdown 文件编译或“编织”为 PDF 文件后,我收到一条很长的错误消息,其中一部分是这样的:
警告:包 natbib 警告:第 1 页上的引用“GoelThakor2008”在输入中未定义 警告:包 natbib 警告:存在未定义的引用。
有趣的是,如果我注释掉这行
citation_package: natbib
,那么它就像一个魅力。
经过大量调试,我找到了答案:文件名 test_library.bib 有一个下划线“_”,latex natbib 无法处理。
将文件重命名为 testlibrary.bib 后,文件编译正确。