[Tex/LaTex] Natbib giving citation undefined

natbib

I have been doing citations using natbib without bibtex and manually entering citations. I keep getting an issue when compiling stating "Citation 'all citations' on page # undefined on input line #"

\documentclass{article}
\usepackage{graphicx}
\usepackage[round]{natbib}
\usepackage{mathtools}
\usepackage{float}

\begin{document}
\bibliographystyle{plainnat}

\title{my title}
\author{my name}
\date{some date}
\maketitle

\section*{section title}
some text some more text and more \citep{hooper05} and then more \citep{hobbs92}. 
And last but not least more and more text \citep{da05}.

\begin{thebibliography}{99}

\bibitem[Daehler,(2005)]{da05} CSE citation here
\bibitem[Hobbs \& Huennke(1992)]{hobbs92} CSE citation here
\bibitem[Hooper et al.(2005)]{hooper05} CSE citation here



\end{thebibliography}

\end{document}

This is an example of the full document used. When I try and place my citations in alphabetical order the output is more and includes "Citation '(all citations)' on page # undefined on input line #". At the moment I only have three citations and am intending on including more and have them in alphabetical order. When i rearrange in the order i placed the citations in the text it compiles just fine.

Best Answer

What you're trying to do is typeset the bibliography manually. This is manageable, but then you have to do all the sorting yourself. Here is the output when compiling a minimal example:

enter image description here

\documentclass{article}
\usepackage[round]{natbib}
\begin{document}

\section*{section title}
some text some more text and more \citep{hooper05} and then more \citep{hobbs92}. 
And last but not least more and more text \citep{da05}.

\begin{thebibliography}{99}
  \bibitem[Daehler,(2005)]{da05} Daehler, CSE citation here
  \bibitem[Hooper et al.(2005)]{hooper05} Hooper, CSE citation here
  \bibitem[Hobbs \& Huennke(1992)]{hobbs92} Hobbs, CSE citation here
\end{thebibliography}

\end{document}

If you now switch around some of the bibliography items, LaTeX will just again typeset it as is:

enter image description here

\documentclass{article}
\usepackage[round]{natbib}
\begin{document}

\section*{section title}
some text some more text and more \citep{hooper05} and then more \citep{hobbs92}. 
And last but not least more and more text \citep{da05}.

\begin{thebibliography}{99}
  \bibitem[Hobbs \& Huennke(1992)]{hobbs92} Hobbs, CSE citation here
  \bibitem[Hooper et al.(2005)]{hooper05} Hooper, CSE citation here
  \bibitem[Daehler,(2005)]{da05} Daehler, CSE citation here
\end{thebibliography}

\end{document}

You mention that you'll be adding references to the bibliography, making it grow. Then I suggest you use the power of BibTeX to actually sort it for you. For that, you can use the following template as a base (I used the following, perhaps fake, references: Hobbs & Huennke, Daehler and Hooper, et al):

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{source.bib}
@article {hobbs92,
  author = {Hobbs, Richard J. and Huenneke, Laura F.},
  title = {Disturbance, Diversity, and Invasion: Implications for Conservation},
  journal = {Conservation Biology},
  volume = {6},
  number = {3},
  publisher = {Blackwell Science Inc},
  issn = {1523-1739},
  url = {http://dx.doi.org/10.1046/j.1523-1739.1992.06030324.x},
  doi = {10.1046/j.1523-1739.1992.06030324.x},
  pages = {324--337},
  year = {1992},
}
@article {da05,
  author = {Daehler, Curtis C. and Goergen, Erin M.},
  title = {Experimental Restoration of an Indigenous Hawaiian Grassland after Invasion by Buffel Grass (Cenchrus ciliaris)},
  journal = {Restoration Ecology},
  volume = {13},
  number = {2},
  publisher = {Blackwell Science Inc},
  issn = {1526-100X},
  url = {http://dx.doi.org/10.1111/j.1526-100X.2005.00047.x},
  doi = {10.1111/j.1526-100X.2005.00047.x},
  pages = {380--389},
  keywords = {Cenchrus ciliaris, grassland, Hawaii, Heteropogon contortus, invasive grasses, priority effects},
  year = {2005},
}
@article{hooper05,
  author = {Hooper, PA and Blackman, BRK and Dear, JP},
  pages = {3564--3576},
  title = {The mechanical behaviour of poly(vinyl butyral) at different strain magnitudes and strain rates},
  volume = {47},
  year = {2012}
}
\end{filecontents*}

\usepackage[round]{natbib}
\begin{document}

\section*{section title}
some text some more text and more \citep{hooper05} and then more \citep{hobbs92}. 
And last but not least more and more text \citep{da05}.

\bibliographystyle{plainnat}
\bibliography{source}

\end{document}

So, instead of manually creating a thebibliography environment with \bibitems, you create a .bib file and input the contents using a specific BibTeX syntax, and include this bibliography using \bibliography{<bib source>}.

Compile the above use pdfLaTeX, followed by a compiling using BibTeX, then twice again using pdfLaTeX and the output would be:

enter image description here

Note how, even though we cited in the order Hooper, Hobbs, Daehler and source.bib has the order Hobbs, Daehler, Hooper, the output has the alphabetical order Dahler, Hobbs, Hooper. That's because BibTeX read the citation information as well as a .bst (referenced using \bibliographystyle{plainnat} - plainnat.bst) and sorted the contents accordingly (outside of LaTeX). BibTeX also created a .bbl file, which is then included with your call to \bibliography{<bib source>}.

Related Question