Text FormattingNatbib with Latex

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

Natbib with Latex

Post by Hakarl »

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:

Code: Select all

\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:

Code: Select all

%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:

Code: Select all

Package natbib Warning: Citation `znosko1961not' on page 1 undefined on input l
ine 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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Natbib with Latex

Post by Johannes_B »

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.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Natbib with Latex

Post by Stefan Kottwitz »

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
  • [attachment=2]pdflatex.png[/attachment]
  • Run with BibTeX (same green "play" button, but choose BibTeX in the dropdown box)
  • [attachment=1]bibtex.png[/attachment]
  • Typeset again with pdfLaTeX (switch back to pdfLaTeX)
  • [attachment=2]pdflatex.png[/attachment]
  • Typeset again with pdfLaTeX, just to ensure all references with page numbers etc. are updated
  • [attachment=2]pdflatex.png[/attachment]
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
bibliography.png (18.35 KiB) Viewed 11205 times
Stefan
Attachments
bibtex.png
bibtex.png (6.23 KiB) Viewed 11205 times
pdflatex.png
pdflatex.png (6.99 KiB) Viewed 11205 times
LaTeX.org admin
Hakarl
Posts: 14
Joined: Sun Feb 18, 2018 7:59 pm

Natbib with Latex

Post by Hakarl »

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?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Natbib with Latex

Post by Stefan Kottwitz »

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
LaTeX.org admin
Hakarl
Posts: 14
Joined: Sun Feb 18, 2018 7:59 pm

Natbib with Latex

Post by Hakarl »

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.
Post Reply