BibTeX, biblatex and biberchapterbib | References by Chapter

Information and discussion about BiBTeX - the bibliography tool for LaTeX documents.
Post Reply
nina.dena
Posts: 3
Joined: Wed Apr 29, 2009 6:32 am

chapterbib | References by Chapter

Post by nina.dena »

I'm compiling a large document (using a main file and several other files using the \include{} command) that requires reference lists at the end of each chapter. I've been attempting to use chapterbib, but something seems to be wrong. I've read posts on the internet which suggest that each chapter needs to be compiled independently, but I'm not sure how to do this in TexnicCenter. There must be an easier way, though. Any help would be appreciated!

Note also, that some of the references overlap between chapters, and so these should be included in more than one list.

Thanks!

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

chapterbib | References by Chapter

Post by localghost »

nina.dena wrote:[...] I've read posts on the internet which suggest that each chapter needs to be compiled independently, but I'm not sure how to do this in TexnicCenter. [...]
You understood something wrong. You have to run BibTeX on the AUX file of every included chapter. These files are generated when using the \include command.

The best way to do that in TeXnicCenter (TXC) would be to copy a predefined build profile, rename it and supplement it in the post-processor section with the appropriate bibtex calls. Press Alt+F7 to get the dialog window "Profiles".

I attached a sample project with all necessary files to show you how this works. After running pdflatex on the main file sample.tex you have to process all the files chp01.aux, chp02.aux and chp03.aux with bibtex. Afterwards run pdflatex twice again to get all references right. In the attached archive you can find also the final output.

Best regards and welcome to the board
Thorsten
Attachments
sample.zip
An example for bibliographies in each chapter.
(125.37 KiB) Downloaded 2691 times
nina.dena
Posts: 3
Joined: Wed Apr 29, 2009 6:32 am

chapterbib | References by Chapter

Post by nina.dena »

Thanks for your help! Finally got it to work!! Just to make it crystal clear for other users, here's what I did:
  1. Delete current .bbl files from the sample file, so that you can see if your compilation works.
  2. Build (ctrl+F7) sample.tex once.
  3. Open chp01.tex, chp02.tex, and chp03.tex.
  4. For each, click "Build" in the top toolbar -> "Current File" -> "Bibtex". This creates the .bbl files again.
  5. Build (ctrl+F7) sample.tex twice.
As an aside: I didn't actually really understand the purpose of copying and changing the "Profile". Perhaps this speeds things up, but, oh well, I have it working now.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

chapterbib | References by Chapter

Post by localghost »

nina.dena wrote:[...] I didn't actually really understand the purpose of copying and changing the "Profile". Perhaps this speeds things up, but, oh well, I have it working now.
Such a profile could provide an automatism for creating documents with bibliographies by chapters. But it would have the disadvantage that the included files always must have the same names. If the work-flow you described is OK for you, just use it.
sivals
Posts: 8
Joined: Mon Jul 27, 2009 6:12 pm

chapterbib | References by Chapter

Post by sivals »

Hello nina.dena,

thank you very much for your help. Finally got it to work! I have problem in typesetting my thesis that bibliography. It is not coming as section, it came in separate page. How to avoid that? I want to put my chapter reference without any page break.

For your clarity, in your sample file also bibliography comes on a separate page. I want to put the reference continuous to the document.


Thank you for your help.
Siva
wololo
Posts: 1
Joined: Tue Apr 06, 2010 3:25 pm

Re: chapterbib | References by Chapter

Post by wololo »

Guys!

Thank you so so much! I was for like three weeks trying to do that without success! I just followed nina's steps and it works like a charm!


Thanks again!
Matheus
colmatrix
Posts: 6
Joined: Tue Oct 27, 2009 11:57 pm

chapterbib | References by Chapter

Post by colmatrix »

Hi guys,

I've been trying to use chapterbib by following the instructions above as best I can, but no luck. The original template I was using would put all the references in one bibliography at the end of the document, but I want separate bibliographies for each chapter. Also, the same reference used in different chapters will be re-numbered for each chapter.

Here's what I've done. In the main document, that calls in all the chapters:
  • I have added the 'sectionbib' option to the natbib package:

    Code: Select all

    \usepackage[square, numbers, comma, sort&compress, sectionbib]{natbib}
  • I include chapterbib:

    Code: Select all

    \usepackage{chapterbib}
  • then I call in the chapters, e.g.:

    Code: Select all

    \include{./Chapters/Chapter1}
In the separate chapter .tex files, I add the bibliographies:

Code: Select all

\section{References}
\label{References:Ch1}
\bibliographystyle{unsrtnat}
\bibliography{Bibliography}
To compile everything I build the main .tex file (using the PDFLaTeX command in TexMaker). I then run BibTeX on each chapter file, then build the main file twice.

I end up with [?] where the references should be, and no sign of any bibliographies anywhere.

Any help as to what I'm doing wrong?


Thanks,
Jonny
fluffy_duck
Posts: 1
Joined: Mon Jan 17, 2011 6:22 am

chapterbib | References by Chapter

Post by fluffy_duck »

localghost had the answer to using the chapterbib package in TeXnicCenter.

In Windows, to automate localghost's suggestion of using the post-processor in the output profile, you can use a .bat file. The batch file applies BibTeX to every file with a .aux extension.
  • to make the batch file
    • Create an empty text file called "bibtex_chapters.bat".
    • Put in the following two lines

      Code: Select all

      @echo off
      for %%X in (*.aux) do BIBTEX_EXEC_PATH "%%X"
      where BIBTEX_EXEC_PATH is the absolute reference to your bibtex executable. For example, in the default MikTeX 2.9 installation replace BIBTEX_EXEC_PATH with
      <"C:\Program Files\MiKTeX 2.9\miktex\bin\bibtex"> (ignore <'s and >'s).
  • to use the batch file in a profile (see attachment).
    • Put your "bibtex_chapters.bat" file in the same directory as your latex project.
    • Press Alt+F7 in Texniccenter.
    • Select the "Postprocessor" tab.
    • Create a new(insert) postprocessor.
    • Call it "Bibtex chapters".
    • In the Executable line type "bibtex_chapters.bat" (see screenshot).
    • Click OK
Bibliographies for chapters should now be fully automated. Ignore the errors if one of your \include[d] files does not have bibliography commands.
Roberto_T
Posts: 3
Joined: Fri Mar 25, 2011 1:04 pm

Re: chapterbib | References by Chapter

Post by Roberto_T »

Dear all,

thank you very much for your answers, they have been very useful for me.

I was following the automation approach proposed by fluffy_duck in the 'sample' project proposed by localghost and found some troubles on my TXC distribution. I was continuously getting messages of the sort :

"I couldn't open file name chp01.aux.aux" ...

and the bibliographies were not generated

The way I circumvented these problems on my TXC distribution was as follows

0) I deleted all files *.aux

1) In the "bibtex_chapters.bat" I slightly modified the instructions given by fluffy_duck to get:

@echo off
for /f %%a in ('dir /b *.aux') do BIBTEX_EXEC_PATH %%~na

(in my case, BIBTEX_EXEC_PATH = "C:\Program Files (x86)\MiKTeX 2.7\miktex\bin\bibtex")

(I got the hint for the modifications from : http://jamesewelch.wordpress.com/2008/0 ... ugh-files/)

2)I pressed Alt+F7 in Texniccenter.
I selected the "Profile" "LaTeX=>PDF" (the profile I'm currently working with).
Within this profile, I inserted a new postprocessor called 'Chapterbib' (the name itselt is not relevant).
In the Executable line I typed "bibtex_chapters.bat" ...

(The difference with fluffy_duck's procedure is that I did not create a new preferred "Profile")

3) I built (Ctrl.+F7) the main '.tex' (sample.tex) 3 times.

The resulting .pdf was OK.

I hope it helps!

Best regards,
-Roberto
Post Reply