problems with package chapterbib to obtain multiple bibliographies

TXS - Help
2014-02-27
2014-02-27
  • Dear developers of this great editor I've been using for 2 years now,
    I'm struggling for 1 day with an issue using the package chapterbib. Since I finally installed also texmaker and everythin worked smoothly there, I suspect something is wrong with my TeXstudio!

    The objective is to obtain multiple bibliographies, e.g. one for each chapter
    An example follows...

    content of the root .tex file:
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%BEGIN CODE
    \documentclass{report}
    \usepackage{chapterbib}
    \begin{document}
    \include{chapter1}
    \include{chapter2}
    \end{document}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%END CODE

    content of chapter1.tex file:
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%BEGIN CODE
    \chapter{Foo}
    Some text and a reference to \cite{goossens93}.
    \bibliographystyle{plain}
    \bibliography{ff}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%END CODE

    content of chapter2.tex file:
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%BEGIN CODE
    \chapter{Bar}
    Some text and a reference to \cite{lamport94}. But also have a look in \cite{knuth79}...
    \bibliographystyle{plain}
    \bibliography{ff2}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%END CODE

    content of both .bib files ff and ff2 (they are the same):
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%BEGIN CODE
    @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"
    }
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%END CODE

    All the file are presently in a single folder (since structuring the project with subfolders seems to introduce additional problems I'm not interested in at the moment :-)...)

    I'm compiling it as suggested, by making:
    LateX (or pdfLateX) on the root
    BibTeX on chapter1
    BibTeX on chapter2
    LateX (or pdfLateX) on the root
    LateX (or pdfLateX) on the root

    With TeXmaker this just works, both using LateX and pdfLateX.

    With TeXstudio I get (starting with a "cleaned folder", i.e. deleting first all the intermediate files...):

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%BEGIN OUT
    Process started: bibtex "test"
    Process started: pdflatex -synctex=1 -interaction=nonstopmode "test".tex
    This is BibTeX, Version 0.99d (MiKTeX 2.9)
    The top-level auxiliary file: test.aux
    A level-1 auxiliary file: chapter1.aux
    The style file: plain.bst
    A level-1 auxiliary file: chapter2.aux
    Illegal, another \bibstyle command---line 4 of file chapter2.aux
    : \bibstyle
    : {plain}
    I'm skipping whatever remains of this command
    Illegal, another \bibdata command---line 5 of file chapter2.aux
    : \bibdata
    : {ff2}
    I'm skipping whatever remains of this command
    Database file #1: ff.bib
    (There were 2 error messages)
    Process exited normally
    Process exited normally
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%END OUT

    and occasionally I get (usually when I try to recompile after BibTeX):
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%BEGIN OUT
    line 3: I can't write on file `test.aux' \begin{document}
    line 3: Emergency stop \begin{document}
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%END OUT

    any help more than welcome!
    thanks

     
  • Marcel
    Marcel
    2014-02-27

    Hey ho!

    I worked with this Minimum Working Example (MWE):
    %BEGIN CODE
    \documentclass{report}
    \usepackage{chapterbib}

    \begin{filecontents}{ff.bib}
    content of both .bib files ff and ff2 (they are the same):
    @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"
    }
    \end{filecontents}

    \begin{filecontents}{ff2.bib}
    content of both .bib files ff and ff2 (they are the same):
    @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"
    }
    \end{filecontents}

    \begin{filecontents}{chapter1.tex}
    \chapter{Foo}
    Some text and a reference to \cite{goossens93}.
    \bibliographystyle{plain}
    \bibliography{ff}
    \end{filecontents}

    \begin{filecontents}{chapter2.tex}
    \chapter{Bar}
    Some text and a reference to \cite{lamport94}. But also have a look in \cite{knuth79}...
    \bibliographystyle{plain}
    \bibliography{ff2}
    \end{filecontents}

    \begin{document}
    \include{chapter1}
    \include{chapter2}
    \end{document}
    %END CODE

    and this runs on a bash:
    pdflatex main
    bibtex chapter1.aux
    bibtex chapter2.aux
    pdflatex main
    pdflatex main

    TeXstudio produces a correct pdf. I think you run bibtex on main.aux and not on chapter1.aux/chapter2.aux

    You can make a user command in TeXstudio:
    txs:///pdflatex | bibtex chapter1.aux | bibtex chapter2.aux | txs:///pdflatex | txs:///pdflatex

    For me it works.