12

I am writing a document in latex and I have a big .bib file and a large number of citations. I want to have citations in the form [Author, year] format and am using the package natbib, but can't get citep or citet working, though plain cite is working fine. The error I get is:

! Undefined control sequence.
l.3 lets cite \citet{cayton05}

I am using Ubuntu texlive package and use \input{<file>} latex command to input the chapters to the main .tex file.

What's surprising is that instead of using \input{<file>} if I just have text in the main .tex file then all the cite commands are working.

Any help would be highly appreciated.

The working version is like this:

\usepackage{cite} 
\usepackage[square,sort]{natbib}
%% lot of other packages and formatting %%

\begin{document}

\chapter{Testing citations}

\begin{enumerate}
  \item this is the first citation \cite{belkin02}.
  \item this is the second citation \citep{belkin02}.
  \item this is the third citation \cite{shlens03}.
\end{enumerate}



\phantomsection\addcontentsline{toc}{chapter}{Bibliography}
\begin{spacing}{1.5}
\nocite{*}
\bibliographystyle{apalike}
\bibliography{testnb.bib}
\end{spacing}

\end{document}

In the real .tex file, I input the chapter text from another .tex file, and citep and citet won't work in that giving the aforesaid error, though plain cite will work fine.

I forgot to mention earlier I was using plain numbered bibliography style and everything was working, so there is no error in the input .tex files.

Dronacharya
  • 471
  • 1
  • 4
  • 15
  • 1
    Just in case you arent aware, there is a more focussed Q&A site for Tex / latex - http://tex.stackexchange.com/ – Jagmag Dec 09 '10 at 01:49

2 Answers2

19

If \citep and \citet do not work, then you probably did not load natbib.

From a document I currently work on:

 \usepackage[authoryear,round,longnamesfirst]{natbib}

You may want different options -- see the handy reference sheet for natbib for details.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Can you post a small self-contained example which fails to illustrate the issue? – Dirk Eddelbuettel Dec 09 '10 at 02:22
  • I have loaded the natbib package like this: \usepackage[square,sort]{natbib}. I copied the same .tex and .bib file to a different directory and wrote some citations (citep and citet) in the .tex file itself (instead of using \input{}), and they are working fine. Thanks for answering. – Dronacharya Dec 09 '10 at 02:27
  • Never mind ... the problem fixed itself. I never got to know what was wrong. – Dronacharya Dec 20 '10 at 10:10
5

You should only include \usepackage[square,sort]{natbib}.

It will work after deleting \usepackage{cite}.

Werner
  • 14,324
  • 7
  • 55
  • 77
jjjjjj
  • 51
  • 1
  • 1