8

When I try to compile a Latex document citing the following entry in a .bib:

@book{a_book,
    title = {A Book},
    publisher = {Book Publisher},
    author = {Fist, Last},
    year = {2015},
    language = {en},
}

I get the following two errors:

Package babel Error: You haven't defined the language en yet.
Package babel Error: You haven't loaded the language english yet.

Everything is fine when I remove language = {en} from my BibTex entry. However, this line is included without error on @article entries.

What's going on? Why does including this line cause an error only with @book entries?

Version Info:

This is BibTeX, Version 0.99d (TeX Live 2013)
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)

Test Files:

test.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}

test.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},
}
  • 2
    Welcome to TeX.SE! You should call package babel with option english and change language={en} in the bib entries to language={english}. – Mensch Sep 7 '15 at 21:08
4

When you have a language field in a bib entry, you need to load babel with the appropriate language options for all the languages you need. The last one specified will be the default.

However, language={en} will result in \selectlanguage{en} in the .bbl file, which babel doesn't understand. Nonetheless, we can stretch a bit babel and make it use language aliases. It would be a good feature for babel, in my opinion, and it's not really so difficult to implement.

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.