6

When I am trying to compile my document I get the following error ! Missing \endcsname inserted. if there's a ":" in my cite key. This is my MWE:

\documentclass[12pt,a4paper,twoside]{article}
\usepackage[utf8x]{inputenc}
\usepackage{ucs}
\usepackage[francais,french]{babel}
\usepackage[T1]{fontenc}\usepackage{amsmath}
\usepackage[authoryear]{natbib}
\setlength{\bibsep}{0pt}
\begin{document}
Blablablabla \citep{Organization:2003aa}.
\bibliographystyle{biblio}
\bibliography{Biblio}
\end{document}

The error only appears when the bibdex cite key contains ":" if I replace the ":" by a dash it works fine. The bst file I used was customized by myself last year, I used it for another paper it worked fine.

Thanks in advance for your help.

4
  • 5
    It's a known problem: with the French babel language colons are treated in a way that makes them problematic in \cite keys.
    – egreg
    Aug 27, 2013 at 17:00
  • 1
    Duplicate? tex.stackexchange.com/q/89016/586 Aug 27, 2013 at 17:01
  • the problem is not that the citation is not found it tells me "! Missing \endcsname inserted." by the way I will remove french babel. It's weird, I think in the previous document I wrote I used it as well and it didn't cause any error.
    – esmitex
    Aug 27, 2013 at 17:15
  • 1
    If I remove the babel package, I cannot use french quotes anymore and I get a bunch of errors linked to the fact that I am using french in the document and adding \shorthandoff{:} in my preamble didn't fix the problem.
    – esmitex
    Aug 27, 2013 at 17:17

1 Answer 1

7

The problem is that the commands \cite and friends don't activate any protection about colons when the language is French, where the colon has a special meaning.

Workaround: modifying what \NAT@sort@cites does

\begin{filecontents*}{\jobname.bib}
@article{x:y,
 author={A. U. Thor},
 title={Title},
 journal={Journal},
 year=2013,
}
\end{filecontents*}

\documentclass[12pt,a4paper,twoside]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{amsmath}
\usepackage[authoryear]{natbib}

\makeatletter
\let\ORG@NAT@sort@cites\NAT@sort@cites
\def\NAT@sort@cites#1{%
  \edef\@tempa{\detokenize{#1}}%
  \ORG@NAT@sort@cites\@tempa
}
\makeatother

\begin{document}

Blablablabla \citep{x:y}.
\bibliographystyle{plainnat}
\bibliography{\jobname}
\end{document}

Note that filecontents* is just to provide a self contained example.

Note also that it's useless to load both francais and french, which do the same thing and may confuse babel. In general I prefer utf8 to utf8x. Loading ucs is not legal with the utf8 option; it's unnecessary with the utf8x option, unless some option is passed to it, in which case it should be loaded before inputenc.

3
  • OK I took off the french and "ucs". I use utf8x because with utf8 you have to write accents like \'eand it is kind of time consuming in french. I will try what you just told me.
    – esmitex
    Aug 27, 2013 at 19:18
  • @esmitex You can also with utf8.
    – egreg
    Aug 27, 2013 at 19:26
  • Usually when I do with "utf8" only it triggers some error and I have to place \'e
    – esmitex
    Aug 27, 2013 at 22:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .