BibTeX, biblatex and biberBibliography at the end of each chapter

Information and discussion about BiBTeX - the bibliography tool for LaTeX documents.
Post Reply
gingerella
Posts: 3
Joined: Fri Nov 06, 2009 6:11 pm

Bibliography at the end of each chapter

Post by gingerella »

Hi all,

I know similar (infact, probably identical) problems have already been posted here, but I have scoured the threads and the suggested solutions do not seem to work for me. So here goes...

It's time for me to start thinking about writing my PhD thesis and, as with my first year transfer report, I shall be doing it in LaTeX. The main difference will be that I want to have a list of references (bibliography) at the end of each chapter.

I have a main file; thesis.tex, which includes the preamble, the first few compulsary pages (ToC, List of Figures/Tables, Abstract, etc.) and then calls each of the sections using the following packages and command;

Code: Select all

\usepackage[numbers, super, comma, sort&compress, sectionbib]{natbib}
\usepackage{chapterbib}

-------------------

\include{Chapter#/chap#}
Each chap#.tex file (which is in folder Chapter#) looks something like this;

Code: Select all

\bibliographystyle{plain}
\renewcommand{\bibname}{References to Chapter 1}

.... text .....

\clearpage
\phantomsection
\begin{singlespace}
\addcontentsline{toc}{section}{References to Chapter#}
\bibliography{Chapter#/ch#refs}
But once I \include{} more than one chapter, the bibliographies don't work correctly.

Sometime, it correctly generates references for Chapter 1 but not for subsequent chapters. Any references it does show in Chapter 2, for example, are only those that have also appeared in Chapter 1, but the Bibliography at the end of Chapter 2 is just a repeat of that printed at the end of Chapter 1.

It is important to note that I have:
  1. the ch#refs.bib files for each chapter located in the folder with its associated chap#.tex file
  2. ch#refs.bib which contain only the references used in that chapter
  3. the plain.bst file in the main folder with thesis.tex file created this all as a project file (using TeXniCenter) with thesis.tex as the main file
  4. the .bst file located in the main folder with thesis.tex
  5. executed the build process in the correct order: LaTeX(main)-BibTeX(each chapter individually)-LaTeX(main)-LaTeX(main)
  6. tried deleting thesis.bbl, thesis.aux, chap#.aux and starting again from scratch, to no avail.
So, with >1 .tex files included (i.e. >1 .bib files), no matter which chap#.tex I perform BibTeX on, I get the same error(s);
-----------------Output Profile: LaTeX > PDF-------------------
This is BibTeX, Version 0.99c (MiKTeX 2.7)
The top level auxiliary file: thesis.aux
A level-1 auxiliary file: Chapter1/chap1.aux
The style file: Plain.bst
A level-1 auxiliary file: Chapter2/chap2.aux
Illegal, another \bibstyle command---line 2 of file Chapter2/chap2.aux
: \bibstyle
: {plain}
I'm skipping whatever remains of this command
Illegal, another \bibdata command---line 113 of file Chapter2/chap2.aux
: \bibdata
: {Chapter2/ch2refs}
I'm skipping whatever remains of this command
Database file #1: Chapter1/ch1refs.bib
Warning--I didn't find a database entry for "<a-reference-that-appears-only-in-ch2refs.bib>"
<repeats several times>
(There were 2 error messages)
which implies that BibTeX is not treating the .bib files exclusively.

I have quickly thrown together a MWE, which I have attached in a .rar file.

Any ideas on why it doesn't work?

Thanks,

Gingerella
Attachments
thesisgingerella.rar
(38.91 KiB) Downloaded 318 times

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

Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Re: Bibliography at the end of each chapter

Post by Juanjo »

Since ch#refs.bib and chap#.tex are located in the same folder, at the end ot the latter you should simply write \bibliography{ch#refs} instead of \bibliography{Chapter#/ch#refs}. Doing this trivial change, I've been able to compile your files. By the way, revise the preamble: keep \usepackage{graphicx} and remove \usepackage{graphics} (redundant) and the last instance of \usepackage{epstopdf}.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
gingerella
Posts: 3
Joined: Fri Nov 06, 2009 6:11 pm

Bibliography at the end of each chapter

Post by gingerella »

Excellent! Thanks for that Juanjo! Once I changed what you said, it compiled for me too and the references seemed to generate correctly.

However, when TeXniCenter tried to read a reference for chapter 2 from the ch1.bib file; which obviously isn't there, I was still getting similar errors as before e.g.;
Warning--I didn't find a database entry for "<a-reference-that-appears-only-in-ch2refs.bib>"
<repeats several times>
I tried various different methods, but finally stopped the above by having a single thesis.bib file, with every single reference in, placed in all chapter folders, e.g. in the folder with chap1.tex as well as in the folder with chap2.tex.

It does generate the references correctly, but it also still generates the following errors;
...
This is BibTeX, Version 0.99c (MiKTeX 2.7)
The top-level auxiliary file; F:\Thesis.aux
A level-1 auxiliary file: Chapter1/chap1.aux
The style file: plain.bst
A level-1 auxiliary file: Chapter2/chap2.aux
Illegal, another \bibstyle command---line 2 of file Chapter2/chap2.aux
: \bibstyle
: {plain}
I'm skipping whatever remains of this command
Illegal, another \bibdata command---line 113 of file Chapter2/chap2.aux
: \bibdata
: {thesisrefs}
I'm skipping whatever remains of this command
Database file #1: thesisrefs.bib
(There were 2 error messages)
So it's not perfect but at the moment it seems to be "working" (?!)

Now what I want to do is have the reference numbers not be reset for each chapter i.e. if there are 11 references in chapter 1, I want the first reference in chapter 2 to be #12.
Post Reply