当我尝试编译引用.bib 中的以下条目的 Latex 文档时:
@book{a_book,
title = {A Book},
publisher = {Book Publisher},
author = {Fist, Last},
year = {2015},
language = {en},
}
我收到以下两个错误:
Package babel Error: You haven't defined the language en yet.
Package babel Error: You haven't loaded the language english yet.
当我从 BibTex 条目中删除时,一切都正常language = {en}
。但是,此行包含在@article
条目中且没有错误。
发生了什么事?为什么包含此行只会导致条目出错@book
?
版本信息:
This is BibTeX, Version 0.99d (TeX Live 2013)
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
测试文件:
测试.tex
\documentclass{revtex4-1}
\begin{document}
This is an article. \cite{an_article}.
This is a book \cite{a_book}.
\bibliographystyle{apsrev4-1}
\bibliography{test}
\end{document}
测试文件
@book{a_book,
title = {A Book},
publisher = {Book Publisher},
author = {Last, First},
year = {2015},
language = {en},
}
@article{an_article,
title = {An Article},
volume = {1},
number = {1},
journal = {Journal},
author = {Last, First},
year = {2015},
pages = {1-10},
language = {en},
}
答案1
当您language
在 bib 条目中有一个字段时,您需要babel
为所需的所有语言加载适当的语言选项。最后指定的选项将是默认值。
但是,language={en}
会导致文件\selectlanguage{en}
中出现无法理解的字符。尽管如此,我们可以稍微扩展一下,让它使用语言别名。在我看来,这将是一个不错的功能,而且实现起来并不困难。.bbl
babel
babel
babel
\begin{filecontents*}{\jobname.bib}
@book{a_book,
title = {A Book},
publisher = {Book Publisher},
author = {Last, First},
year = {2015},
language = {en},
}
@article{an_article,
title = {An Article},
volume = {1},
number = {1},
journal = {Journal},
author = {Last, First},
year = {2015},
pages = {1-10},
language = {en},
}
\end{filecontents*}
\documentclass{revtex4-1}
\usepackage[english]{babel}
\makeatletter
% A change to a babel macro
\def\bbl@set@language#1{%
\edef\languagename{%
\ifnum\escapechar=\expandafter`\string#1\@empty
\else\string#1\@empty\fi}%
%%%% ADDITION
\@ifundefined{babel@language@alias@\languagename}{}{%
\edef\languagename{\@nameuse{babel@language@alias@\languagename}}%
}%
%%%% END ADDITION
\select@language{\languagename}%
\expandafter\ifx\csname date\languagename\endcsname\relax\else
\if@filesw
\protected@write\@auxout{}{\string\select@language{\languagename}}%
\bbl@for\bbl@tempa\BabelContentsFiles{%
\addtocontents{\bbl@tempa}{\xstring\select@language{\languagename}}}%
\bbl@usehooks{write}{}%
\fi
\fi}
% The user interface
\newcommand{\DeclareLanguageAlias}[2]{%
\global\@namedef{babel@language@alias@#1}{#2}%
}
\makeatother
\DeclareLanguageAlias{en}{english}
\begin{document}
This is an article. \cite{an_article}.
This is a book \cite{a_book}.
\bibliographystyle{apsrev4-1}
\bibliography{\jobname}
\end{document}