1

I have started using Latex for a few days, so I'm a beginner. However, I succeeded to set and customize everything I need for my book writing..except for the bibliography. I am very confused about the several ways in which the bibliography can be written and include in a Latex document.

I'm using TexShop on a Mac to write my main file which includes several chapters. I'm trying to use the package natbib and I have a .bib file resulting from the exportation of my bibliography from Mendeley. my file is like this:

\documentclass[a4paper,11pt,  twoside, openright]{book}
\usepackage[T1]{fontenc}                
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
    \usepackage[a4paper,top=3.5cm,bottom=2.5cm,left=3cm,right=3cm]{geometry}
\usepackage{fancyhdr}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{caption}
\captionsetup{font=small}
\usepackage{topfront}

\usepackage{emptypage}
\usepackage{natbib}


\begin{document}
\mainmatter
\input{capitoli/Results1.tex}
\end{document}

and my results1.tex file is:

\begin{document}
\chapter{Results part I}
orem ipsum dolor sit amet, consectetuer adipiscing elit\cite{Author2015a}
\bibliography{library}
\bibliographystyle{plainnat} 

and, finally, my .bib file (one example entry) which is in the same directory of the others

@article{Author2015a,
author = {Author, Elizabeth C},
doi = {10.1016/j.apgeog.2014.12.002},
file = {:Users/Giovanna/Documents/phd/letteratura phd/author 2015           Five decades of neighborhood classifications and their transitions.pdf:pdf},
issn = {0143-6228},
journal = {Applied Geography},
pages = {1--11},
publisher = {Elsevier Ltd},
title = {{Five decades of neighborhood classi fi cations and their transitions : A comparison of four US cities , 1970 e 2010}},
url = {http://dx.doi.org/10.1016/j.apgeog.2014.12.002},
volume = {57},
year = {2015}
},

However, what i get in my final pfd is a "?" instead of the reference. Where is the problem? Now I downloaded also Bibdesk in trying to solve the problem but I cannot understand how. I know that probably is a basic question but I really cannot fix it (even after having read several article and tutorial about that. Thank you

  • Remove \printbibliography. This is not a bibtex command, but from the biblatex package. – user36296 Jul 23 '18 at 20:06
  • @ggg Also don't use \bibliography{library.bib} \bibliographystyle{plainnat} two times. Remove it from your preamble and leave it only where you want to have your bibliography. – user36296 Jul 23 '18 at 20:08
  • @ggg This was the instance of \bibliography{library.bib} \bibliographystyle{plainnat} which was OK, remove the the one before \begin{document}. Also the second \begin{document} in results1.tex looks wrong. – user36296 Jul 23 '18 at 20:12
  • @samcarter got it (hope so) for the \bibliography{library.bib}. what is wrong with the second \begin{document} in results1.tex ? there is not \end{document} because it is inlcude in the main file (the fiirst one i wrote) – ggg Jul 23 '18 at 20:15
  • @ggg one document typically only has one \begin{document} in the main file, not in the sub files. There is also a ] missing before {geometry} – user36296 Jul 23 '18 at 20:17
1

This is a combination of several problems:

  • \bibliography{library} should be called without file extension -> remove the .bib

  • \bibliography{library} \bibliographystyle{plainnat} are only to be used once at the location where the location where the bibliography should be inserted.

  • the closing ] is missing in \usepackage[a4paper,top=3.5cm,bottom=2.5cm,left=3cm,right=3cm]{geometry}

  • \begin{document} must be written only once, at the start of the document and not in the included files (there are exceptions, but they don't apply here)

  • compilation should be (pdf)latex, bibtex, (pdf)latex, (pdf)latex and it is important to check that the document compiles without errors, which some of the problems above surly caused.


Minimal working example

\documentclass[a4paper,11pt,  twoside, openright]{book}
\usepackage[T1]{fontenc}                
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[a4paper,top=3.5cm,bottom=2.5cm,left=3cm,right=3cm]{geometry}
\usepackage{fancyhdr}
\usepackage{setspace}
\usepackage{graphicx}
\usepackage{caption}
\captionsetup{font=small}
\usepackage{topfront}
%
\usepackage{emptypage}
\usepackage{natbib}

\usepackage{filecontents} % <- Just for the MWE, in real live have a seperate .bib file
\begin{filecontents*}{\jobname.bib}% <- Just for the MWE, in real live have a seperate .bib file
@article{Author2015a,
author = {Author, Elizabeth C},
doi = {10.1016/j.apgeog.2014.12.002},
file = {:Users/Giovanna/Documents/phd/letteratura phd/author 2015           Five decades of neighborhood classifications and their transitions.pdf:pdf},
issn = {0143-6228},
journal = {Applied Geography},
pages = {1--11},
publisher = {Elsevier Ltd},
title = {{Five decades of neighborhood classi fi cations and their transitions : A comparison of four US cities , 1970 e 2010}},
url = {http://dx.doi.org/10.1016/j.apgeog.2014.12.002},
volume = {57},
year = {2015}
},
\end{filecontents*}% <- Just for the MWE, in real live have a seperate .bib file


\begin{document}
\mainmatter

\chapter{Results part I}
orem ipsum dolor sit amet, consectetuer adipiscing elit\cite{Author2015a}
\bibliography{\jobname}
\bibliographystyle{plainnat} 


\end{document}
  • yes it perfectly works. Are you suggesting that the problem, and so the solution, is in the .bib file? – ggg Jul 23 '18 at 20:22
  • @ggg The bib file is the only part I did not touch. I'll make a list with the problems. – user36296 Jul 23 '18 at 20:23
  • i guess i have a problem with the .bib file because everything is ok when i use your mwe but when i pass to my .bib file and i complete compilation bibtex i get this error message: "This is BibTeX, Version 0.99d (TeX Live 2017) The top-level auxiliary file: tesi.aux I couldn't open database file library.lib.bib ---line 15 of file tesi.aux : \bibdata{library.lib : } I'm skipping whatever remains of this command" – ggg Jul 23 '18 at 20:39
  • @ggg You have to write \bibliography{library} (without ending) not \bibliography{library.lib} – user36296 Jul 23 '18 at 20:41
  • yes i did it i change it. in the line 15 (mentioned in the error message there is just \usepackage{natbib} – ggg Jul 23 '18 at 20:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.