7

I get a strange error when I try cite two certain papers in the same document, when I use the natbib package (with numbers option enabled). If I trim the author list or change the year of either paper, then it works.

The error is:

...
Document Class: article 2005/09/16 v1.4f Standard LaTeX document class
(/usr/share/texmf/tex/latex/base/size10.clo))
(/usr/share/texmf/tex/latex/natbib/natbib.sty) (./test.aux)
! Missing = inserted for \ifnum.
<to be read again> 
                   \def 
l.5 ...p{mieghem10assortativity,mieghem10rewiring}
                                                   says

I've confirmed this happens with other people's installations too. So it's not specific to my machine.

What am I doing wrong, or is this a bug in natbib? If a bug, is there a workaround?

Here's a simple test-case:

test.bib:

@article{mieghem10assortativity,
        Month = {{Nov}},
        Numpages = {{11}},
        Publisher = {{American Physical Society}},
        author = {Van Mieghem, P. and Ge, X. and Schumm, P. and Trajanovski, S. and Wang, H.},
        title = {{Spectral graph analysis of modularity and assortativity}},
        journal = {{Physical Review E}},
        volume = {{82}},
        number = {{5}},
        pages = {056-113},
        year = {{2010}},
        doi = {{10.1103/PhysRevE.82.056113}},
}

@article{mieghem10rewiring,
        author = {Van Mieghem, P. and Wang, H. and Ge, X. and Tang, S. and Kuipers, F. A.},
        title = {{Influence of assortativity and degree-preserving rewiring on the spectra of networks}},
        journal = {{European Physical Journal B}},
        volume = {{76}},
        number = {{4}},
        pages = {643-652},
        year = {{2010}},
        doi = {{10.1140/epjb/e2010-00219-x}},
}

test.tex:

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

\begin{document}
blah. \citep{mieghem10assortativity,mieghem10rewiring} says
blah blah

\bibliographystyle{plainnat}
\bibliography{test}

\end{document}
lockstep
  • 250,273
paulj
  • 173
  • 1
  • 6

2 Answers2

9

The error occurs because of the double braces in the bib file (especially in cases, where just a number is expected). Why do you have double braces around nearly every field in the bib file? If I change them to single braces, everything works fine.

\documentclass[a4paper]{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{mieghem10assortativity,
        Month = {Nov},
        Numpages = {11},
        Publisher = {American Physical Society},
        author = {Van Mieghem, P. and Ge, X. and Schumm, P. and Trajanovski, S. and Wang, H.},
        title = {Spectral graph analysis of modularity and assortativity},
        journal = {Physical Review E},
        volume = {82},
        number = {5},
        pages = {056-113},
        year = {2010},
        doi = {10.1103/PhysRevE.82.056113},
}

@article{mieghem10rewiring,
        author = {Van Mieghem, P. and Wang, H. and Ge, X. and Tang, S. and Kuipers, F. A.},
        title = {Influence of assortativity and degree-preserving rewiring on the spectra of networks},
        journal = {European Physical Journal B},
        volume = {76},
        number = {4},
        pages = {643-652},
        year = {2010},
        doi = {10.1140/epjb/e2010-00219-x},
}
\end{filecontents}
\usepackage[numbers]{natbib}

\begin{document}
blah. \citep{mieghem10assortativity,mieghem10rewiring} says
blah blah

\bibliographystyle{plainnat}
\bibliography{\jobname}

\end{document}

(Note: the filecontents package and environment are just for producing the bib file, they are not part of the solution.)

domwass
  • 11,563
  • +1, I was just starting to type the same answer. I think for values with integer numbers, no braces should be used, e.g. simply volume = 76, number = 4, year = 2010 – Martin Scharrer Feb 08 '11 at 12:14
  • @Martin Scharrer: I think it does no harm to use braces around values with integer numbers, though. – domwass Feb 08 '11 at 12:21
  • @Domwass: I remember reading something about it is better to not use braces somehow, but can't remember where and why right now. – Martin Scharrer Feb 08 '11 at 12:27
  • @Martin: defined abbreviations have to be and numbers can be written without braces. See texdoc bibtex –  Feb 08 '11 at 12:37
  • 1
    That fixes it for me! The extra braces were added by my bibliography management tool, to protect capitalisation in titles. It double-braces everything then though. I can tell it to disable that for now. – paulj Feb 08 '11 at 13:40
  • @paulj: Maybe you should consider changing your bib editor. – domwass Feb 08 '11 at 14:11
  • @domwass: nah, it's generally really good - "referencer" - and this option is off by default! I'll patch it to only protect certain fields. Thanks v much for the answer! – paulj Feb 08 '11 at 14:28
  • I submitted a patch for referencer that protects only the 'title' field: bugs.launchpad.net/referencer/+bug/338930/comments/3 – Stephen Mar 01 '11 at 10:47
  • Thank you, domwass, your comment helped solve exactly the same problem in my case! –  Jan 17 '13 at 16:30
-1

I had a similar issue where I was using the inbook template for webpages. To get the format of the reference to appear correctly I had put {[Accessed 22 January 2016]} in the year field. I was referencing two webpages from the same website so the overall references were very similar differing only by title and URL. It would compile when I had one of these references in but when I added the second this error appeared. I found that by changing the date (i.e. {[Accessed 21 January 2016]} it would compile. It doesn't seem to like very similar references.

Stefan Kottwitz
  • 231,401
James
  • 11