1

I have a problem almost identically to this old other question. The differences are that I am using Zotero and the IEEEtran bib style.

Zotero basically does the same thing as Mendeley, i.e. producing language fields in the .bib with the value en etc. So this difference is insignificant to this question and I state it here only for search engine users.

The IEEEtran bib style emits some code that apparently checks if the language's value is a defined babel language. If that's not the case it produces a warning:

** WARNING: IEEEtran.bst: No hyphenation pattern has been
** loaded for the language `en'. Using the pattern for

This comes from the following code:

\providecommand{\BIBforeignlanguage}[2]{{%
\expandafter\ifx\csname l@#1\endcsname\relax
\typeout{** WARNING: IEEEtran.bst: No hyphenation pattern has been}%
\typeout{** loaded for the language `#1'. Using the pattern for}%
\typeout{** the default language instead.}%
\else
\language=\csname l@#1\endcsname
\fi
#2}}

Just like in the other question I would like to use the bib style without changing the .bib file. However, the workaround/solution of the other question does not work with IEEEtran.

MWE (w/o the defunct workaround for natbib):

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

\bibliographystyle{IEEEtran}

\begin{document}

    \cite{Renyi1961}

    \bibliography{\jobname}

\end{document}
stefanct
  • 841
  • 6
  • 16
  • If you export using the BBT plugin, the language en in the item will be exported as langid = {english}. Would that make a change for your case? – retorquere Feb 23 '20 at 15:59
  • I guess you mean when exporting to biblatex? Because I am using BBT but it generates language fields that don't have their value processed AFAICT. – stefanct Feb 24 '20 at 05:41
  • I did mean that, but if there's a more sensible way to export languages for bibtex, feel free to open an issue on https://github.com/retorquere/zotero-better-bibtex/issues and I'll get it sorted. – retorquere Feb 24 '20 at 08:27

3 Answers3

1

Edit. Sorry, my answer does not solve the problem. I was assuming the selection was done with babel, but it turns out this is not true. However, I won't delete it because it could be useful in other cases.

Original answer

Here is a quick hack:

\documentclass{article}

\usepackage[danish,english]{babel}

% The hack:
\makeatletter
\let\old@fixname\bbl@fixname
\def\bbl@fixname#1{%
  \@ifundefined{babelalias#1}%
    {\old@fixname{#1}}%
    {\edef\languagename{\csname babelalias#1\endcsname}}}
\makeatother

% The synonymous:
\newcommand{\babelaliasen}{english}
\newcommand{\babelaliasda}{danish}

\begin{document}

\selectlanguage{da}

\languagename --- \chaptername

\selectlanguage{en}

\languagename --- \chaptername

\end{document}

Not very elegant, but it seems to work. An interface for BCP 47 codes is under study, and very likely it will be available in a couple of months.

Javier Bezos
  • 10,003
1

You can do better, see the other thread.

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

\usepackage{hyperref}

\bibliographystyle{IEEEtran}

\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}%
}
\let\BIBforeignlanguage\foreignlanguage
\makeatother

\definelanguagealias{en}{english}

\begin{document}

    \cite{Renyi1961}

    \bibliography{\jobname}

\end{document}

The trick is inducing IEEEtran to use a better command than \language\l@<language>, namely \foreignlanguage{<language>}{...}

egreg
  • 1,121,712
0

The easiest way to solve this seem to be simple TeX macros to define an alias, e.g.:

\makeatletter
\def\l@en{\l@english}
\makeatother

However, I am not sure if that solve the issue completely without regressions. It does load the correct hyphenation settings though. Also, I was not able to declare a suitable replacement for the \definelanguagealias command (either it was producing errors when defined with TeX primitives, or it was not creating the aliases correctly for babel/IEEEtran to pick up).

I'd be happy to select a more elegant suggestion as correct answer...

stefanct
  • 841
  • 6
  • 16