Language problems with biblatex and babel

I am trying to use biblatex with IEEEtran and babel, however I am having an error: Package babel Error: You haven't defined the language ENGLISH yet.. With regular Bibtex everything works as usual. The MWE is the following:

\documentclass[english]{IEEEtran}

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

\usepackage[strict,autostyle]{csquotes}
\usepackage[style=ieee,backend=bibtex]{biblatex}
\bibliography{/usr/local/texlive/2012/texmf-dist/doc/latex/biblatex-ieee/biblatex-ieee.bib}

\usepackage{blindtext}

\begin{document}

\Blindtext

\nocite{*}
\printbibliography

\end{document}

-
Would \usepackage[english]{babel} help? – yo' Jan 1 '13 at 20:38

The error seems indeed to be caused by the combination biblatex/babel/IEEEtran -- your example (with an appropriate .bib file) works with the article class. A workaround is to fake an ENGLISH (uppercase) dialect for the english language.

\documentclass[english]{IEEEtran}

\usepackage{babel}

\makeatletter
\makeatother

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

\usepackage[strict,autostyle]{csquotes}
\usepackage[style=ieee,backend=bibtex]{biblatex}

\usepackage{blindtext}

\nocite{*}

\begin{document}

\Blindtext

\printbibliography

\end{document}

-
Thanks! That works very well. – cacamailg Jan 1 '13 at 22:45
I'm trying this example (except using lipsum instead of blindtext) on TexLive 2014 - and it still spits out the old "Package babel Warning: You haven't loaded the language ENGLISH yet"; regardless if I use \adddialect\l@ENGLISH\l@english or \let\l@ENGLISH\l@english. Any ideas about that? – sdaau Oct 12 '14 at 14:23

The problem is that IEEEtran.cls changes the meaning of \markboth applying yet another \MakeUppercase, to which

\protect\foreignlanguage{english}{%
\protect\bbl@restore@actives\MakeUppercase{\refname}}


is passed, resulting in LaTeX trying to do

\foreignlanguage{ENGLISH}


which gives the error. This is caused by \printbibliography, but is not a responsibility of biblatex, only by a not so wise redefinition of \markboth

One can notice that \refname is already passed to \MakeUppercase.

You have two choices:

1. change the bad redefinition of \markboth:

\makeatletter
\def\markboth#1#2{%
\def\leftmark{\@IEEEcompsoconly{\sffamily}#1}%
\def\rightmark{\@IEEEcompsoconly{\sffamily}#2}}
\makeatother


The IEEEtran definition has \MakeUppercase{#1} and \MakeUppercase{#2}.

2. enable a fake ENGLISH language referring to english:

\makeatletter
\let\l@ENGLISH\l@english
\makeatother


Just put one of the two pieces of code in the preamble of your document. Probably the second one is the safest.

-
Thanks! The second solution is really the safest, and similar to the one provided by lockstep. I will prefer the lockstep solution since it uses a babel command and not the more generic \let. – cacamailg Jan 1 '13 at 22:48
@cacamailg Yes, probably the people at IEEE would remove your definition, just to find them in trouble; so they would remove the call to babel and also to csquotes, ruining your pretty formatting. :( – egreg Jan 1 '13 at 22:50
Yes, and they would also remove biblatex :(. – cacamailg Jan 1 '13 at 23:02

I was just trying these examples with a fresh TexLive 2014; I had been using the \let\l@ENGLISH\l@english fix for a while in TexLive 2011 with success, but now with 2014 the same document gave me the dreaded warning:

Package babel Warning: You haven't loaded the language ENGLISH yet
(babel)                I'll proceed, but expect unexpected results.
(babel)                Reported on input line 38.


This is the example I used, which now compiles in TexLive 2014 without the warning:

\documentclass[english]{IEEEtran}

\usepackage{trace}
% \traceon

\usepackage{babel}

\makeatletter
% \global\let\l@ENGLISH\l@english
\let\l@ENGLISH\relax
\show\l@english
\show\l@ENGLISH
\typeout{BABEL TEST:}
\ifx \csname l@english\endcsname\relax
\typeout{l@english here}
\fi
\ifx \csname l@ENGLISH\endcsname\relax
\typeout{l@ENGLISH here}
\fi
\makeatother

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

\usepackage[strict,autostyle]{csquotes}
\usepackage[style=ieee,backend=biber]{biblatex}

\usepackage{lipsum}

\nocite{*}

\begin{document}

\lipsum[1]

\printbibliography

\end{document}


The weird thing is - in TexLive 2014 versions, the \let\l@ENGLISH\l@english actually triggers the warning to appear. I used trace to scan a bit, and here is an overview:

Eventually, when Latex needs to print a section title it will call \foreignlanguage, e.g.:

\foreignlanguage  #1#2->\begingroup \foreign@language {#1}#2\endgroup
#1<-ENGLISH
#2<-\protect \bbl@restore@actives \protect \MakeUppercase  {REFERENCES}
{\begingroup}
{entering semi simple group (level 12) at line 29}


In the course of its execution, we eventually come to this conditional, which takes the false branch when \let\l@ENGLISH\l@english is in effect:

\@ifundefined #1->\expandafter \ifx \csname #1\endcsname \relax \expandafter \@
firstoftwo \else \expandafter \@secondoftwo \fi
#1<-\bbl@tempe ENGLISH
{\expandafter}
{\csname}

\bbl@tempe ->l@
{\ifx}
{false}
{\expandafter}
{\fi}


Let's look at \@ifundefined more closely:

\expandafter %
\ifx \csname #1\endcsname \relax %
\expandafter \@firstoftwo %
\else %
\expandafter \@secondoftwo %
\fi


So in this case, the \ifx basically checks if the expanded (see comments below) versions of \l@ENGLISH and \relax are the same; and since \relax is unexpandable (a Tex primitive?), obviously the \ifx will be false for any value of \l@ENGLISH different from \relax, such as \l@english (with contents being just \char"0).

So the solution for TexLive 2014 is either to \let\l@ENGLISH\relax - or, not address it at all (which is a bit strange to me, because in that case, \l@ENGLISH is \shown as undefined [not as the command/macro/token, though], and \ifx doesn't see \relax and \undefined as the same:

? i
insert>\ifx\relax\undefined\typeout{A}\else\typeout{B}\fi
B


)

Well, hope this was it with this problem, then - probably it's time to write another TexLive version conditional (Getting Texlive version in pdflatex?)...

-
The redefinition of \markboth that I suggested is independent of babel and works also in TL 2014. The problem seems to be that the new version of babel has changed a bit its working. – egreg Oct 12 '14 at 16:08
Note that \expandafter\ifx\csname l@ENGLISH\endcsname\relax just forms the \l@ENGLISH token and then \ifx compares it with \relax. It doesn't expand \l@ENGLISH. – egreg Oct 12 '14 at 16:12
Thanks for the comments, @egreg - I honestly didn't try the \markboth approach in the past, I liked the simplicity of the \let one :) - so thanks for that mention, and the note about expansion. Cheers! – sdaau Oct 12 '14 at 16:25

Check your bib file for the line which google, or journal, often add when you export a citation.

language={english}


delete it, then delte the .bbl and the .aux, then recompile

-
In the .bib file? – Werner Oct 30 '14 at 20:49