9

I use \usepackage[english]{babel}, but I am keeping getting error:

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

while parsing bibliography with \bibliographystyle{apsrev4-1} (curiously enough, for some other bibliography styles I don't get this problem).

I've discovered that in some bib entries there are lines

language = {en},

Changing en to english does solve the problem. However, as I get the bib file generated from other tool (Mendeley) it would be annoying.

Is there a way to define language en as a synonym of english?

Note:

There is a similar question Unable to get rid of error babel: You haven't defined the language en yet?, but it is closed as unclear.

Example:

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

And 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}
}
4
  • 1
    Also this question is unclear, mainly because an example is missing.
    – egreg
    Sep 3, 2014 at 10:42
  • 1
    @egreg What is unclear in "[In babel], [i]s there a way to define language en as a synonym of english?"? In any case, as of now I am working on a phd thesis, so it would take me time to create a "minimal (not) working example". Sep 3, 2014 at 10:46
  • 2
    How are we supposed to reproduce the issue? Just a minimal preamble, the bibliography style, a citation and an entry that creates the problem. I tried to make a M(n)WE, but got no error.
    – egreg
    Sep 3, 2014 at 10:47
  • I added example. Sep 3, 2014 at 11:12

1 Answer 1

7

This is not a full aliasing system, because it acts just on \selectlanguage, but it should be sufficient for your purpose. A full system would need deep surgery in 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}

The filecontents* trick is just to make the example self-contained, you don't need it and you can use the normal .bib file you have.


Following a suggestion of Javier Bezos, patching \bbl@fixname seems better, because it also works with all language changing commands.

\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}
5
  • Thanks, works! For the full file I had to add also \definelanguagealias{EN}{english}, as it seems to be case-sensitive. Sep 3, 2014 at 13:05
  • @PiotrMigdal Yes, it is. But it's just a matter of adding the necessary aliases once the need arises.
    – egreg
    Sep 3, 2014 at 13:47
  • This solution does not work for the IEEEtran style, see tex.stackexchange.com/questions/527949/…
    – stefanct
    Feb 11, 2020 at 14:55
  • @stefanct IEEEtran.bst is not the same as apsrev4-1. There's no reason to expect they work the same.
    – egreg
    Feb 11, 2020 at 15:04
  • Well, no, not exactly... (OTOH the patch does not do anything natbib-specific AFAICS) but this question+solution was still the next best thing and thus I ended up here before posting my own question and thus adding that comment/link seems useful to me.
    – stefanct
    Feb 11, 2020 at 16:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .