[Tex/LaTex] “! Missing \endcsname inserted” with babel and natbib

babelnatbib

This is puzzling, at least for me. I get a "! Missing \endcsname inserted" error in the following MWE:

\documentclass{article}
\usepackage[UKenglish,italian,french]{babel}
\usepackage{natbib}

\begin{document}
Hello world!~\cite{vim:2008}
\end{document}

If I remove the unbreakable space, or the french option from babel, or the colon from the citation, or the natbib package, everything works fine.

I'm compiling with pdflatex.

What can I do to make them work all together?

Best Answer

Load natbib before babel.

\begin{filecontents*}{\jobname.bib}
@article{vim:2008,
  author={X Y},
  title={Z},
  journal={J},
  year=2008,
}
\end{filecontents*}

\documentclass{article}
\usepackage{natbib}
\usepackage[UKenglish,italian,french]{babel}

\begin{document}

x~\cite{vim:2008}

\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}

enter image description here