# Including a .bib file with \input does not work

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,
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}},
year = {2009}
}


But it has to be encoded in utf-8.

How can I make this setup work?

-
it does make sense to input a bib. Put the \inputencoding command before the \bibliography command (which loads the bbl) –  Ulrike Fischer Aug 20 '12 at 21:59
I think I narrowed down the problem : commands like \input{references_utf8} inside the environment filecontents are NOT executed by latex, but simply copied verbatim in the file \jobname.bib. This is not what I want : If the command culd be executed, I think the whole code would work. –  jul059 Aug 20 '12 at 22:38
No. You are on the completly wrong track. You don't need a \jobname.bib. bibtex will use your original references.bib to create a \jobname.bbl. And your document will then input this bbl when you use the \bibliography command. Open the bib and the bbl in your editor to see the differences! –  Ulrike Fischer Aug 21 '12 at 8:03
If your bib file is as you show with all ascii characters you do not need any encoding switch. That file is already ascii, utf8 and latin1: the encodings are identical in that range. What made you think you needed to change the input encoding? –  David Carlisle Aug 21 '12 at 20:55

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}

-
As you can see, the .bib file does not contain any special characters. It seems to be simply a matter of what type of encoding is specified in the file (is this how it works? is there a "specified type"?). In my .bib file, if I have special special characters they will we coded with the latex command. For example, é will be coded \'{e} so this should not be a problem. –  jul059 Aug 20 '12 at 21:01
it should be coded as {\'e} –  Herbert Aug 21 '12 at 5:16