LaTeX forum ⇒ Text FormattingNatbib 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

Postby Hakarl » Tue May 22, 2018 3:16 am

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:
  1. \documentclass[10pt]{article}
  2. \usepackage[margin=1in]{geometry}
  3. \usepackage[pdftex]{graphicx}
  4. \usepackage{setspace}
  5. \usepackage[round,sort,authoryear]{natbib}
  6. \setlength\parindent{0pt}
  7.  
  8. \begin{document}
  9.  
  10. The book by \cite{znosko1961not} might be the best instructional book ever written for chess.
  11.  
  12. \bibliographystyle{authordate1}
  13. \bibliography{NatbibTest}
  14. \end{document}

Here is the BibTex file:
  1. %Testing refs for natbib
  2. %
  3. @book{znosko1961not,
  4. title={How Not to Play Chess},
  5. author={Znosko-Borovsky, Eugene A and Reinfeld, Fred and others},
  6. year={1961},
  7. publisher={Courier Corporation}
  8. }
  9. @book{murray1913history,
  10. title={A history of chess},
  11. author={Murray, Harold James Ruthven},
  12. year={1913},
  13. publisher={Clarendon Press}
  14. }

The error code says:
  1. Package natbib Warning: Citation `znosko1961not' on page 1 undefined on input l
  2. ine 10.
  3.  
  4. (./TestBib.bbl
  5.  
  6. Package natbib Warning: Empty `thebibliography' environment on input line 3.
  7.  
  8. )
  9.  
  10. Package natbib Warning: There were undefined citations.

Hope you guys can stop the mistake.

Thanks

User avatar
Johannes_B
Site Moderator
Posts: 3854
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Tue May 22, 2018 7:02 am

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: 9102
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Tue May 22, 2018 1:05 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
    pdflatex.png (6.99 KiB) Viewed 404 times

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

  • bibtex.png
    bibtex.png (6.23 KiB) Viewed 404 times

  • Typeset again with pdfLaTeX (switch back to pdfLaTeX)

  • pdflatex.png
    pdflatex.png (6.99 KiB) Viewed 404 times

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

  • pdflatex.png
    pdflatex.png (6.99 KiB) Viewed 404 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
bibliography.png (18.35 KiB) Viewed 404 times

Stefan
Site admin

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

Postby Hakarl » Tue May 22, 2018 3:17 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?

User avatar
Stefan Kottwitz
Site Admin
Posts: 9102
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Tue May 22, 2018 3:27 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
Site admin

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

Postby Hakarl » Wed May 23, 2018 12:49 am

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.


Return to “Text Formatting”

Who is online

Users browsing this forum: Baidu [Spider] and 7 guests