babel-定义语言同义词

babel-定义语言同义词

我使用\usepackage[english]{babel},但一直收到错误:

Package babel Error: You haven't defined the language EN yet.

在解析参考书目时\bibliographystyle{apsrev4-1}(奇怪的是,对于一些其他参考书目样式,我没有遇到这个问题)。

我发现有些bib条目中有几行

language = {en},

更改enenglish确实解决了问题。但是,当我bib从其他工具(Mendeley)获取文件时,这会很烦人。

有没有办法将语言定义en为的同义词english

笔记:

有一个类似的问题无法摆脱错误 babel:您尚未定义语言 en?,但由于不清楚而被关闭。

例子:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}

\usepackage{hyperref}

\usepackage{natbib}
\bibliographystyle{apsrev4-1}
\usepackage{doi}

\begin{document}

    \cite{Renyi1961}

    \bibliography{notwrk}

\end{document}

notwrk.bib

@inproceedings{Renyi1961,
author = {R\'{e}nyi, Alfr\'{e}d},
booktitle = {Proceedings of the Fourth Berkeley Symposium on Mathematical Statistics and Probability, Volume 1: Contributions to the Theory of Statistics},
issn = {0097-0433},
language = {en},
publisher = {The Regents of the University of California},
title = {{On Measures of Entropy and Information}},
url = {http://projecteuclid.org/euclid.bsmsp/1200512181},
year = {1961}
}

答案1

这不是一个完整的混叠系统,因为它只对 起作用\selectlanguage,但它应该足以满足您的目的。完整的系统需要对 进行深入的改造babel

\begin{filecontents*}{\jobname.bib}
@inproceedings{Renyi1961,
author = {R\'{e}nyi, Alfr\'{e}d},
booktitle = {Proceedings of the Fourth Berkeley Symposium on Mathematical Statistics 
  and Probability, Volume 1: Contributions to the Theory of Statistics},
issn = {0097-0433},
language = {en},
publisher = {The Regents of the University of California},
title = {{On Measures of Entropy and Information}},
url = {http://projecteuclid.org/euclid.bsmsp/1200512181},
year = {1961}
}
\end{filecontents*}

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}

\usepackage{hyperref}

\usepackage{natbib}
\bibliographystyle{apsrev4-1}
\usepackage{doi}

\usepackage{letltxmacro}

\LetLtxMacro{\ORIGselectlanguage}{\selectlanguage}
\makeatletter
\DeclareRobustCommand{\selectlanguage}[1]{%
  \@ifundefined{alias@\string#1}
    {\ORIGselectlanguage{#1}}
    {\begingroup\edef\x{\endgroup
       \noexpand\ORIGselectlanguage{\@nameuse{alias@#1}}}\x}%
}
\newcommand{\definelanguagealias}[2]{%
  \@namedef{alias@#1}{#2}%
}
\makeatother

\definelanguagealias{en}{english}


\begin{document}

    \cite{Renyi1961}

    \bibliography{\jobname}

\end{document}

诀窍filecontents*只是使示例自成一体,您不需要它,而可以使用.bib您已有的普通文件。


根据 Javier Bezos 的建议,修补\bbl@fixname似乎更好,因为它也适用于所有语言更改命令。

\begin{filecontents*}{\jobname.bib}
@inproceedings{Renyi1961,
  author = {R{\'{e}}nyi, Alfr{\'{e}}d},
  booktitle = {Proceedings of the Fourth Berkeley Symposium on Mathematical Statistics 
               and Probability, Volume 1: Contributions to the Theory of Statistics},
  issn = {0097-0433},
  language = {en},
  publisher = {The Regents of the University of California},
  title = {{On Measures of Entropy and Information}},
  url = {http://projecteuclid.org/euclid.bsmsp/1200512181},
  year = {1961}
}
\end{filecontents*}

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{natbib}
\usepackage{doi}

\usepackage{hyperref}

\bibliographystyle{apsrev4-1}

\makeatletter
\let\ORIbbl@fixname\bbl@fixname
\def\bbl@fixname#1{%
  \@ifundefined{languagealias@\expandafter\string#1}
    {\ORIbbl@fixname#1}
    {\edef\languagename{\@nameuse{languagealias@#1}}}%
}
\newcommand{\definelanguagealias}[2]{%
  \@namedef{languagealias@#1}{#2}%
}
\makeatother

\definelanguagealias{en}{english}

\begin{document}

    \cite{Renyi1961}

    \bibliography{\jobname}

\end{document}

相关内容