Text Formattingquestion about natbib

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
lynnlee
Posts: 50
Joined: Fri Jan 04, 2013 10:15 am

question about natbib

Post by lynnlee »

Hello LaTeX Community,

I am trying to use natbib but I did not get desired results. The commands I used before \documentclass are the following:

Code: Select all

\begin{filecontents*}{bibfile.bib}
@book{goossens93,
        author = "Michel Goossens and Frank Mittlebach and Alexander Samarin",
        title = "The Latex Companion",
        year = "1993",
        publisher = "Addison-Wesley",
        address = "Reading, Massachusetts"
}

@article{lamport94, 
      author="Leslie Lamport",
      title="\LaTeX: A Document Preparation System",
      year="1994",
      journal = "Addison Wesley, Massachusetts",
}
........
\end{filecontents*}
Then, I write these two commands just before \end{document}.

Code: Select all

\bibliographystyle{plainnat}
\bibliography{bibfile}
I actually have 50 references, I just write two here. I also write \usepackage[round]{natbib} in the preamble.

The problem is: Latex produce nothing under these commands.

Is that because I have too much references? If so, how to set the limited number of references in natbib? Or, is there anything wrong with my commands?

Any suggestion is appreciated.

Lynn Lee
Last edited by cgnieder on Fri Jan 04, 2013 11:15 am, edited 1 time in total.

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

question about natbib

Post by Stefan Kottwitz »

Hi Lynnlee,

welcome to the forum!
lynnlee wrote:Latex produce nothing under these commands.
You need to run also BibTeX. Did you do this?

Stefan
LaTeX.org admin
lynnlee
Posts: 50
Joined: Fri Jan 04, 2013 10:15 am

question about natbib

Post by lynnlee »

Thank you, Stefan.

I did not run BibTex before. I try it now. I copy all the references in a separate tex file, then I run the file, the reminder I got is the following:

Code: Select all

This is pdfTeX, Version 3.1415926-1.40.10 (MiKTeX 2.8)
entering extended mode
("C:/bibfile.bib" [1{C:/ProgramD
ata/MiKTeX/2.8/pdftex/config/pdftex.map}])
*
I can not figure out why. I did not get the PDF version of bibfile. In this separate file, I did not write any preamble, begining and ending commands. Is it right?

I appreciate for your help and suggestion.

Lynn
Last edited by cgnieder on Fri Jan 04, 2013 7:23 pm, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

question about natbib

Post by Stefan Kottwitz »

Hi Lynn,

the way in your first post using the filecontents environment is a good way for posting minimal examples when having problems. For the real work,
  • put all the LaTeX code in the .tex file,
  • put the BibTeX entries into a .bib file, without filecontents there, just the @book, @article etc. entries.
Compile with pdfLaTeX, then run BibTeX, compile again with pdfLaTeX (twice, to ensure correct references finally).

Just don't compile the .bib file, neither with pdfLaTeX nor BibTeX. If you run BibTeX at the command line, run it without a file name extension, just with the document name, so it automatically takes the correct .aux and .bib file.

Stefan
LaTeX.org admin
lynnlee
Posts: 50
Joined: Fri Jan 04, 2013 10:15 am

question about natbib

Post by lynnlee »

Thank you, Stefan.

I got the PDF file of bib, and .aux file as you suggested. I did it with a separate .bib file, with \documentclass commands.

I then include all references within command \begin{filecontents*}{bibfile.bib} just as before, and run pdfLaTeX+MakeIndex+BibTeX. But LaTeX stopped working, the reminder I got is as follows:

Code: Select all

! Package natbib Error: Bibliography not compatible with author-year citations.

See the natbib package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.65 ...mand\NAT@force@numbers{}\NAT@force@numbers
I can not figure out the reason.

I am beginner of LaTex user, and I am sorry for any inconvenience.

Thank you for suggestion and help.

Lynn
Last edited by cgnieder on Fri Jan 04, 2013 7:24 pm, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

question about natbib

Post by Stefan Kottwitz »

lynnlee wrote: ! Package natbib Error: Bibliography not compatible with author-year citations.

See the natbib package documentation for explanation.
This can occur if one of the entries has no "year" field. You could check that. Otherwise the pointer to the documentation is useful, you can read it here: natbib manual.

More can be said, if necessary, if we would get more complete information.

Stefan
LaTeX.org admin
lynnlee
Posts: 50
Joined: Fri Jan 04, 2013 10:15 am

question about natbib

Post by lynnlee »

Thank you, Stefan.

I checked my references, no missing years.

I first compile .bib file (.bib file name is bibfile) twice with pdfLaTeX, the code I write is

Code: Select all

\documentclass[a4paper,10pt]{article}
\begin{document}
@article...
....
\end{document}
Then, I got .aux file, pdf file,and bibfile.synctex.

Then, I run my .tex file with pdfLaTeX+MakeIndex+BibTeX, under commands:

Code: Select all

\begin{filecontents*}{bibfile.bib}
@article...%(same contents as in .bib file)
........
\end{filecontents*}

\documentclass[a4paper,10pt]{article}
\usepackage[round]{natbib}
\begin{document}
.....
\bibliographystyle{plainnat}
\bibliography{bibfile}
\end{document}
But I still get the error reminder as I mentioned in last post.

Is it because I got bibfile.synctex?

I appreciate for your help.

Lynn
Last edited by Stefan Kottwitz on Fri Jan 04, 2013 5:28 pm, edited 1 time in total.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

question about natbib

Post by Stefan Kottwitz »

The .bib file doesn't have correct syntax. It's not a LaTeX file, so there should not be \documentclass, \begin{document} and \end{document}. Only @article{...}, @book{...}, and similar.

Btw. please always use the Code button when you insert a multi-line code snippet. This makes it better readable. I did it for you now and edited it above, so you can see it.

Stefan
LaTeX.org admin
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

question about natbib

Post by cgnieder »

Maybe it helps if you see a complete example:

The following tex file

Code: Select all

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

\begin{document}
\cite{article13,book13}

\bibliographystyle{plainnat}
\bibliography{\jobname.bib}

\end{document}
works nicely together with a bib file that contains only this:

Code: Select all

@article{article13,
  author  = {A. Author},
  title   = {An amazing example},
  journal = {Alpha Journal},
  year    = {2013},
  volume  = {1},
  pages   = {1--10}
}
@book{book13,
  author  = {B. Buthor},
  title   = {'bout something stupid},
  editor  = {Beta Publishing},
  year    = {2013}
}
Regards
site moderator & package author
lynnlee
Posts: 50
Joined: Fri Jan 04, 2013 10:15 am

Re: question about natbib

Post by lynnlee »

Thank you Stefan, and Cgnieder.

I tried to write all 50 references in bibfile.bib, with @article{}, etc, only. But when I run pdfLaTeX, the error is \begin{document} is missing. And when I run BibTex, nothing produced. I do not know why.

Is it necessary to write all these references in tex file within \begin{filecontents*} ?

Thank you in advance for suggestion.

Lynn
Post Reply