[Tex/LaTex] Including a .bib file with \input does not work

external filesfont-encodingsinputunicode

In the following simple document, the bibliography does not work :

\documentclass{article}
\usepackage[numbers]{natbib}
\usepackage{inputenc}

\inputencoding{utf8}
\begin{filecontents}{\jobname.bib}
\input{references_utf8}
\end{filecontents}
\inputencoding{latin1}

\begin{document}
\noindent
\cite[voir][chap. 12]{2009solar}
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}

I want to do this because my main documents are in latin-1 and the .bib file is in utf-8. The idea of using \inputencoding was recommended in this question : How to convert UTF-8 to latin-1 on the fly?.

The file references_utf8.bib looks like this :

@book{2009solar,
address = {New Delhi},
author = {Solanki, Chetan Singh},
booktitle = {Solar Photovoltaics: Fundamentals, Technologies and Applications},
chapter = {12},
edition = {1},
isbn = {9788120337602},
pages = {478},
publisher = {Prentice-Hall of India},
title = {{Solar Photovoltaics: Fundamentals, Technologies and Applications}},
url = {http://books.google.ca/books?id=hdvYA9KsI2YC},
year = {2009}
}

But it has to be encoded in utf-8.

How can I make this setup work?

Best Answer

bibtex cannot handle utf8 characters. With bibtex8 some utf8 characters are possible, eg umlauts. However, you can change the inputencoding:

\documentclass{article}
\usepackage[numbers]{natbib}
\usepackage[latin1]{inputenc}

\begin{document}
\noindent
\cite[voir][chap. 12]{2009solar}

\begingroup
\iputencoding{utf8}
\bibliographystyle{plainnat}
\bibliography{\jobname}
\endgroup
\end{document}
Related Question