4

I have been struggling a lot with this problem now. Hopefully somebody can help me. I want to create a document with chapterwise bibliography, so I use \usepackage{chapterbib} together with \usepackage[sectionbib]{natbib}:

\documentclass{report}

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

\begin{document}

\include{chapter1}

\end{document}

where the file chapter1.tex (in the same folder) is

\chapter{Chapter 1}
this is chapter 1~\cite{Article1}

\bibliographystyle{plain}
\bibliography{references}

and the file references.bib (also in the same folder) reads

@article{Article1,
    author = {Author1},
    journal = {J. Art.},
    pages = {1906--1911},
    title = {{This is the first article}},
    volume = {12},
    number = {3},
    year = {2012}
}

While the second citation (Article2) is displayed as expected, there is a question mark where the first citation should be: https://www.dropbox.com/s/zhtuz9nw0otuw6i/Include.pdf?dl=0

What am I doing wrong?

  • What I forgot to mention: It does work if you substitude \include by \input. But then, chapterbib does not work anymore. – Dietmar Haba Dec 11 '15 at 16:54
  • 1
    you should use \include with all the chapters and run bibtex separately on each chapter to generate the separate bibliographies – David Carlisle Dec 11 '15 at 17:12
  • This is what I have done several times. Does not seem to work. – Dietmar Haba Dec 14 '15 at 11:45
  • If you have a version that you think should work but does not, edit the question above to be that code (so move \chapter out of the main file) and then say exactly how it "does not work" show exactly how you called bibtex and what error log you got – David Carlisle Dec 14 '15 at 11:54
  • So I removed \chapter from the main file and everything that has to do with it. I called bibtex from TeXstudio (via the Tools menu) in both TEX files. I just found that I get an error message already at that point, saying: "Illegal, another \bibdata command". This problem is thus comparable to that given in http://tex.stackexchange.com/questions/17474/multiple-bibliographies. However, other than described there I wasn't able to get to any better result yet. The final pdflatex compilation keeps giving above-mentioned result and the message: Illegal, another \bibdata command I'm workin on it. – Dietmar Haba Dec 14 '15 at 13:29
  • 2
    I found the problem now. I didn't know that TeXstudio uses bibtex always on the main document, even if chapter1.tex is active. I had to run bibtex via the command window to make it work. Strange. Thanks anyway. – Dietmar Haba Dec 14 '15 at 15:55
  • I wonder why i still bother answering questions, when crossposting is so popular. http://golatex.de/fehlermeldung-illegal-another-bibstyle-command-t16494.html – Johannes_B Dec 14 '15 at 16:01
  • This hack lets TexStudio run bibtex on each included file: 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:59

2 Answers2

4

You should use \include with all the chapters and run bibtex separately on each chapter to generate the separate bibliographies, one for each chapter.

David Carlisle
  • 757,742
1

The problem was that my LaTeX editor, TeXstudio, does not run bibtex on the active document, but always on the main document. However, bibtex must be run on the sub-document to generate (what was in my case called) chapter1.bbl. Running bibtex via the command window solved the problem.

  • If you happen to use texlive (and not miktex) then compiling on the code with latexmk - pdf master.tex ought to run bibtex automatically on each separate part – daleif Dec 14 '15 at 16:40
  • Great hint! But not miktex? Is says "because it is part of MacTeX and MikTeX" on https://mg.readthedocs.io/latexmk.html –  Feb 20 '22 at 21:11