16

I tried to go through already posted solutions but I was not able to find one working for my case. I am compiling a ph.d. thesis with one main file, by including chapters. The format is the following

\documentclass[12pt, twoside]{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage[pagestyles]{titlesec}
\titleformat{\chapter}[display]{\normalfont\bfseries}{}{0pt}{\Huge}
\newpagestyle{mystyle}
{\sethead[\thepage][][\chaptertitle]{}{}{\thepage}}
\pagestyle{mystyle}
\usepackage[semicolon,round,sort&compress]{natbib}
\usepackage[sectionbib]{chapterbib}
\usepackage{hyperref}
\usepackage{epstopdf}
\usepackage{rotating}
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{calc}
\usepackage{float}
\usepackage{indentfirst}
\usepackage{chronology}
\usepackage[toc,page]{appendix}
\usepackage{graphics}
\usepackage{color,soul}
\usepackage{tablefootnote}
\usepackage{epsfig}         
\usepackage{subfigure}
\usepackage{grffile}        
\usepackage{soul}
\usepackage{longtable}
\usepackage{lscape}
\usepackage{url}
\usepackage{epsfig} 
\graphicspath{ {images/} }
\usepackage{caption}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm

\begin{document}
\input{chapters/titlepage}

\mainmatter
\tableofcontents
\listoffigures
\listoftables

\chapter{Introduction}
\input{chapters/chap0}

\chapter{chap1}
\input{chapters/chap1}

\chapter{chap2}
\input{chapters/chap2}

\end{document}

Each chapter has its respective bibliography at the end, as follows

\bibliographystyle{apalike}
\bibliography{chapters/bib0}

in the case of chap0. Note that each chapter cannot be compiled alone, since it starts with \section{}, and no \begin{document}. However, things work well only for the first \input{ }, i.e. only for chapter 0. From chapter1 onwards I get just the bibliography of chapter0 repeating. THerefore I get ?? as output in the text for new references. Warnings say that ref'x' is multiple defined and, later, that refx is not defined. How can I fix that ?

Bibtek files are as follows:

bib0

@article{acemoglu2000,
title={The colonial origins of comparative development: An empirical investigation},
author={Acemoglu, Daron and Johnson, Simon and Robinson, James A},
year={2000},
institution={National bureau of economic research}
}

@book{acemoglu2012,
title={Why nations fail: the origins of power, prosperity and poverty},
author={Acemoglu, Daron and Robinson, James A and Woren, Dan},
volume={4},
year={2012},
publisher={SciELO Chile}
}

bib1

@article{acemoglu2000,
title={The colonial origins of comparative development: An empirical investigation},
author={Acemoglu, Daron and Johnson, Simon and Robinson, James A},
year={2000},
institution={National bureau of economic research}
}
@article{ackerberg2006,
title={Structural identification of production functions},
author={Ackerberg, Daniel and Caves, Kevin and Frazer, Garth},
year={2006}
}

Compile goes as follow: pdflatek -> biblatek -> pdflatek(x2). Looks like it is the only compiling solution working

  • You must use \include and not \input when using chapterbib (move the chapter commands in the files) or add a cbunit environment, see the documentation. Another solution is to switch to biblatex/biber. tex.ac.uk/cgi-bin/texfaq2html?label=chapbib – Ulrike Fischer Feb 24 '15 at 9:58
  • whenever I use \include it compiles but I get no bibliography at all – Bob Feb 24 '15 at 10:19
  • 2
    Did you run bibtex on every included file? (biblatex/biber is naturally much more confortable and powerful). – Ulrike Fischer Feb 24 '15 at 10:34
  • I did, I get a lot of warnings telling me that it does not find any database for almost all entries, even the ones of chapter0 which is the one working (apparently) properly. ANd I still get multiply defined warnings – Bob Feb 24 '15 at 10:49
  • Then you probably got confused because of the relative pathes. Did you call bibtex as bibtex chapters/chap0 from the location of the main file or as bibtex chap0? – Ulrike Fischer Feb 24 '15 at 10:52
12

References will not be generated as required because of the incorrect usage of \chapterbib with natbib. The correct usage is:

\usepackage[sectionbib]{natbib}
\usepackage{chapterbib}  

When natbib is not being used as the citation manager, the usage of \chapterbib for references at the end of each chapter is:

\usepackage[sectionbib]{chapterbib}

This is the complete file to generate the list of references at the end of each chapter based on the code that was uploaded. A few commands from the original file are suppressed for convenience. To avoid getting orphan chapter headings I moved the \chapter commands inside the included files. I also deleted the paths to the included and bib files for simplicity.

Remember to run the compiler (PDFLaTeX) on the main file which will generate auxiliary (aux) files for each included file. Then open each auxiliary file and run bibtex on each of those files. This will generate bbl files for each chapter. Then go back to the main file and rerun the compiler twice.

\documentclass[12pt, twoside]{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage[pagestyles]{titlesec}
\titleformat{\chapter}[display]{\normalfont\bfseries}{}{0pt}{\Huge}
%\newpagestyle{mystyle}
%{\sethead[\thepage][][\chaptertitle]{}{}{\thepage}}
%\pagestyle{mystyle}\
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Don't use this                                               %
%\usepackage[semicolon,round,sort&compress,sectionbib]{natbib} %
%\usepackage[sectionbib]{chapterbib}                           %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Replacement                                                  %
\usepackage[semicolon,round,sort&compress,sectionbib]{natbib}  %
\usepackage{chapterbib}                                        %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{hyperref}
\usepackage{epstopdf}
\usepackage{rotating}
\usepackage{amsmath}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{calc}
\usepackage{float}
\usepackage{indentfirst}
\usepackage{chronology}
\usepackage[toc,page]{appendix}
\usepackage{graphics}
\usepackage{color,soul}
\usepackage{tablefootnote}
\usepackage{epsfig}         
\usepackage{subfigure}
\usepackage{grffile}        
\usepackage{soul}
\usepackage{longtable}
\usepackage{lscape}
\usepackage{url}
\usepackage{epsfig} 
\graphicspath{ {images/} }
\usepackage{caption}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry} % this was incomplete
\usepackage{filecontents}
% Create bib file for Introduction chapter
\begin{filecontents*}{bib0.bib}
@article{acemoglu2000,
    title={The colonial origins of comparative development: An empirical investigation},
    author={Acemoglu, Daron and Johnson, Simon and Robinson, James A},
    year={2000},
    institution={National bureau of economic research}
}
@book{acemoglu2012,
    title={Why nations fail: the origins of power, prosperity and poverty},
    author={Acemoglu, Daron and Robinson, James A and Woren, Dan},
    volume={4},
    year={2012},
    publisher={SciELO Chile}
}
\end{filecontents*}
%
% Create bib file for chapter 1. Note that it is not a requirement to have different bib files for each chapter.
\begin{filecontents*}{bib1.bib}
@article{acemoglu2000,
    title={The colonial origins of comparative development: An empirical investigation},
    author={Acemoglu, Daron and Johnson, Simon and Robinson, James A},
    year={2000},
    institution={National bureau of economic research}
}
@article{ackerberg2006,
    title={Structural identification of production functions},
    author={Ackerberg, Daniel and Caves, Kevin and Frazer, Garth},
    year={2006}
}
%
%Create Introduction
\end{filecontents*}
\begin{filecontents*}{chap0.tex}
    \chapter{Introduction}
    This is Chapter ``Introduction'' from included file chap0.tex. \\
    This is a citation for \cite{acemoglu2000} from bib0. \\
    \citep{acemoglu2012} is a citation for the second reference. \\
    The Reference list for introductory chapter appears next. \\
    \bibliographystyle{apalike}
    \bibliography{bib0}
\end{filecontents*}
%
% Create Chapter 1
\begin{filecontents*}{chap1.tex}
    \chapter{chap1}
    This is Chapter 1 from included file chap1.tex. \\
    This is a citation for \cite{acemoglu2000} from bib1. \\
    \citep{ackerberg2006} is a citation for the second reference. \\
    The Reference list for the chapter appears next. \\
    \bibliographystyle{apalike}
    \bibliography{bib1}
\end{filecontents*}
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Suppress content not required for this solution %  
%\include{chapters/titlepage}                    %
%                                                %
%\mainmatter                                     %
%\tableofcontents                                %
%\listoffigures                                  %
%\listoftables                                   %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\include{chap0}
\include{chap1}
\end{document}

This is the output for Chapter Introduction

This is the output for Chapter 1

  • I tried with Texmaker, Texstudio but still, I don't get the aux file. it says chapterbib.sty bot found. – Ajith Sep 25 at 15:01
0

Replace the TeX primitive input with the LaTeX command \include. Then you can select the sections to compile with the LaTeX command \includeonly{chapters/chap0}. The LaTeX include mechanism automatically takes care of cross references.

You will have to re-organise your input a little, because \include forces a page break (and you don't want a page break immediately after a chapter heading).

  • 2
    thanks for the answer. whenever I use \include it compiles but I get no bibliography at all – Bob Feb 24 '15 at 10:11
  • 3
    Make sure that you run BibTeX on the right files; when you \include{chapters/chap1}, run bibtex chapters/chap1 &c. – jknappen Feb 24 '15 at 13:00
  • 1
    @Bob: it's TexStudio's problem. This hack lets TexStudio run bibtex on each included file: tex.stackexchange.com/questions/297430/… – Yan King Yin Nov 27 '17 at 4:02
  • @jknappen I have the same issue as Bob - compiles but no bibliography at all. I receive a warning of undefined citation for all references. I am using Overleaf and not sure if and how bibtex should be run there – Andreuccio Dec 31 '18 at 8:53

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.