24

I have the following:

\documentclass{report}
\begin{document}
\include{chapter1}
\include{chapter2}
\end{document}

I also have a reference.bib file, with entries book1, book2 and book3.

chapter1.tex:

\chapter{Foo}
Some text and a reference to \cite{book1}. But also have a look in \cite{book2}...
\bibliographystyle{plain}
\bibliography{references}

and chapter2.tex being exactly the same except change book2 to book3. Thus book1 is cited in both, but book2 is only cited in chapter1 and book3 only in chapter2.

This produces "multiply-defined" warnings so I am looking for an easy way to do this properly. Any suggestions greatly appreciated.

EDIT: Bibtex produces this:

This is BibTeX, Version 0.99c (TeX Live 2009/Debian)
The top-level auxiliary file: main.aux
A level-1 auxiliary file: chapter1.aux
The style file: plain.bst
A level-1 auxiliary file: chapter2.aux
Illegal, another \bibdata command---line 4 of file chapter2.aux
 : \bibdata
 :         {references}
I'm skipping whatever remains of this command
Database file #1: references.bib
Warning--empty publisher in book1
(There was 1 error message)

And the output from pdflatex is:

This is pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian)
entering extended mode
(./main.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, ngerman, german, german-x-2009-06-19, ngerman-x-2009-06-19,    loaded.

(/usr/share/texmf-texlive/tex/latex/base/report.cls
Document Class: report 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-texlive/tex/latex/base/size10.clo)) (./main.aux
(./chapter1.aux) (./chapter2.aux

LaTeX Warning: Label `book2' multiply defined.


LaTeX Warning: Label `book1' multiply defined.


LaTeX Warning: Label `book3' multiply defined.

)) (./chapter1.tex
Chapter 1.
(./main.bbl [1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}])) [2]
(./chapter2.tex
Chapter 2.
(./main.bbl [3])) [4] (./main.aux (./chapter1.aux) (./chapter2.aux))

LaTeX Warning: There were multiply-defined labels.

)</usr/share/texmf-texlive/fonts/type1/public/amsfonts/cm/cmbx12.pfb>   </usr/sha
re/texmf-texlive/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/share   /texmf-tex
live/fonts/type1/public/amsfonts/cm/cmti10.pfb>
Output written on main.pdf (4 pages, 38197 bytes).
Transcript written on main.log.
lockstep
  • 250,273
Unapiedra
  • 1,448

3 Answers3

21

It seems that you are using the chapterbib package to produce your multiple bibliographies. The error messages that you are getting suggests that you are not compiling your document correctly.

I'll explain how to compile your document with a simple example; I'll assume that your main document is called test.tex and looks like this:

\documentclass{report}
\usepackage{chapterbib}
\begin{document}

\include{chapter1}
\include{chapter2}

\end{document}

The file chapter1.tex:

\chapter{Foo}
Some text and a reference to \cite{goossens93}. But also have a look in \cite{knuth79}...
\bibliographystyle{plain}
\bibliography{references}

The file chapter2.tex:

\chapter{Bar}
Some text and a reference to \cite{lamport94}. But also have a look in \cite{knuth79}...
\bibliographystyle{plain}
\bibliography{references}

The database references.bib:

@book{goossens93,
    author = "Michel Goossens and Frank Mittlebach and Alexander Samarin",
    title = "The Latex Companion A",
    year = "1993",
    publisher = "Addison-Wesley",
    address = "Reading, Massachusetts"

}

@book{knuth79,
    author = "Donald E. Knuth",
        title = "Tex and Metafont, New Directions in Typesetting",
    year = {1979{(}1950{)}},
    publisher = "American Mathematical Society and Digital Press",
    address = "Stanford"
}

@book{lamport94,
    author = "Leslie Lamport",
    title = "Latex: A Document Preparation System",
    year = "1994",
    edition = "Second",
    publisher = "Addison-Wesley",
    address = "Reading, Massachusetts"
}

You have to compile your document in the following way:

pdflatex test
bibtex chapter1
bibtex chapter2
pdflatex test
pdflatex test

In your actual document, as a first step, you'll need to remove the auxiliary files to prevent possible inherited errors.

Gonzalo Medina
  • 505,128
  • Okay, it works now. – Unapiedra May 05 '11 at 19:26
  • It works now. I found out that I actually want \sections. I used the rootbib option, as documented which then worked. – Unapiedra May 05 '11 at 19:35
  • @Gonzao, Since I have nested tex files, I can't use \include, using input on my case doesn't generate any errors, but in the final test.pdf file, there are no references. See my complete question please: https://tex.stackexchange.com/questions/375642/having-one-bib-file-but-generate-references-per-each-chapter?noredirect=1#comment930001_375642 – Amir Jun 19 '17 at 17:12
  • TexStudio does not run bibtex on included files, so I needed this fix: https://tex.stackexchange.com/questions/297430/how-to-run-bibtex-in-texstudio-or-otherwise-on-included-files – Yan King Yin Nov 27 '17 at 03:58
  • @Gonzalo Medina In my situation, I could only have the bibliography at the end of each chapter, but there is no reference number in the places where I make the citation, do you know the reason for that? thanks! – Ogawa Chen May 22 '19 at 06:13
3

I created a small csh script to do that easily in shell.

First make sure to have csh installed first - sudo apt-get install csh.

Then save your files following the pattern root_chapX.tex where root is the name of your main file (e.g., test) and chapX is anything you want (the important thing is to have an underscore between the two).

#!/bin/csh

set base = "root"

echo " Compiling root tex file"
pdflatex $base
echo "================================================================"

echo " Running bibex on included files"
set pattern = ${base}_*.tex
foreach auxfile ($pattern)
  bibtex `basename $auxfile .tex`
end
echo "================================================================"

echo " Compiling root tex file"
pdflatex $base
pdflatex $base
echo "================================================================"
Victor P.
  • 191
0

You CAN run bibtex on your root *.tex file without a problem.

However, in that case you might encounter the Illegal, another \bibdata command error if you use the \bibliography command more than once with different files.

In this case, instead of:

\bibliography{refs1}
\bibliography{refs2}

Do:

\bibliography{refs1,refs2}

That'll fix it.

Domi
  • 161