## LaTeX forum ⇒ Text Formatting ⇒ Natbib with Latex

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Hakarl
Posts: 14
Joined: Sun Feb 18, 2018 7:59 pm

### Natbib with Latex

I am baffled by the fact that I cannot get natbib to work within a document in TexWorks (but it worked in ShareLatex). Both files are in the same folder.

Here is the Latex code:
\documentclass[10pt]{article}\usepackage[margin=1in]{geometry}\usepackage[pdftex]{graphicx}\usepackage{setspace}\usepackage[round,sort,authoryear]{natbib}\setlength\parindent{0pt} \begin{document} The book by \cite{znosko1961not} might be the best instructional book ever written for chess. \bibliographystyle{authordate1}\bibliography{NatbibTest}\end{document}

Here is the BibTex file:
%Testing refs for natbib%@book{znosko1961not,  title={How Not to Play Chess},  author={Znosko-Borovsky, Eugene A and Reinfeld, Fred and others},  year={1961},  publisher={Courier Corporation}}@book{murray1913history,  title={A history of chess},  author={Murray, Harold James Ruthven},  year={1913},  publisher={Clarendon Press}}

The error code says:
Package natbib Warning: Citation znosko1961not' on page 1 undefined on input line 10. (./TestBib.bbl Package natbib Warning: Empty thebibliography' environment on input line 3. ) Package natbib Warning: There were undefined citations.

Hope you guys can stop the mistake.

Thanks

Johannes_B
Site Moderator
Posts: 3805
Joined: Thu Nov 01, 2012 4:08 pm
You are getting warnings, not errors.
Did you run the additional program to create the bibliography information?
Have a look at this question and answer: https://tex.stackexchange.com/questions ... ion-number
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.

Stefan Kottwitz
Posts: 8980
Joined: Mon Mar 10, 2008 9:44 pm
Hi Hakari!

That code is perfectly ok. And it runs with TeXworks too. ShareLaTeX probably did all the routine for you that you now have to do yourself with TeXworks.

Once you saved .tex and .bib file,

• Typeset with pdfLaTeX

• pdflatex.png (6.99 KiB) Viewed 271 times

• Run with BibTeX (same green "play" button, but choose BibTeX in the dropdown box)

• bibtex.png (6.23 KiB) Viewed 271 times

• Typeset again with pdfLaTeX (switch back to pdfLaTeX)

• pdflatex.png (6.99 KiB) Viewed 271 times

• Typeset again with pdfLaTeX, just to ensure all references with page numbers etc. are updated

• pdflatex.png (6.99 KiB) Viewed 271 times

The error message you get in the first run, go away after you run BibTeX and then pdfLaTeX again. I get this output:

bibliography.png (18.35 KiB) Viewed 271 times

Stefan

Hakarl
Posts: 14
Joined: Sun Feb 18, 2018 7:59 pm
Stefan,

Thanks for your quick response. I am aware of the multiple compilings needed to get things to show. However, the compiling of the BibTex still confuses me. Do I compile the BibTex file itself or the main tex document itself under BibTex? Another thing I am unsure is if I have my BibTex file(s) in a folder (for example in the case of a book with multi-chapters) will the main tex file find the BibTex and compile it?

Stefan Kottwitz
Posts: 8980
Joined: Mon Mar 10, 2008 9:44 pm
Run BibTeX on the main document name (without file name extension). It works with the document and the .aux file (that has the document name).
Put the .bib files in the same folder as the main document, and run bibtex on the main document name (without .tex name extension).

Stefan

Hakarl
Posts: 14
Joined: Sun Feb 18, 2018 7:59 pm
Stefan,

Thanks. I am actually using TeXShop since I have a Mac. Not TexWorks. When I compile the main file under the BibTex I simply get an error message but it seems to work anyway.