I'm typesetting a contributed book, which has a whole bunch of chapters written by a different author each. My job is make sure all contributions use more or less the same typesetting conventions and select index words.
For the references we wish to create a separate list for each chapter. Originally I was doing this using multibib
, but it seems that package actually keeps each .aux file open while running pdflatex, hence now that I've finished editing a bunch of chapters, I'm suddenly running into the limited write-stack.
So I switched to bibunits
, which is better suited for the job anyway.
However……. one of the contributions actually has four separate bibliographies that go with it. This is again precisely the problem multibib
tries to solve and I happened to start with this contribution, which explains my original choice for that package.
So what I would like to do, is to use bibunits
for all contributions and use multibib
to split the references in this one special contribution. Since bibunits
closes each unit before continuing to the next unit, I should be safe then wrt the limited write stack. Unfortunately these packages don't work well together, so it seems. I guess this has to do with the fact that both of these try to redefine similar same commands (although, since multibib
explicitly defines \citeXXXX
commands for each bibliography unit XXXX
I kind of expected things to be allright)
The error I'm getting, is the standard, infamous:
! TeX capacity exceeded, sorry [input stack size=5000].
<inserted text>
}\endwrite
l.901 ...liographysyta{syta_vdweygaert-references}
! ==> Fatal error occurred, no output PDF file produced!
What also strikes the eye, is that at some point I get an enormous long list of lines saying:
(./bu.aux) (./bu.aux) (./bu.aux) (./bu.aux) (./bu.aux) (./bu.aux) (./bu.aux)
Allright… back to what I guess is my question: I tried to get separate reference lists for a single chapter, while also creating references for individual chapters and failed. How can I succeed in doing this?
Best Answer
So after some hacking, I actually found a (IMO rather dirty) hack that actually makes things work for me, although with a minor modification: I don't use
bibunits
, but ratherchapterbib
.The basic reason why they couldn't work together, is that they redefine a common set of commands. Hence the basic idea of my solution: make sure they are never, say 'active', simultaneously. For future reference, let me spill out my solution and the limitations (I'm aware of). All the following should be put in the header of your document.
The solution is designed for a setup with one main file, that uses
\include
to include a file for each chapter. The aim is to 'switch off' thechapterbib
package before including a chapterfile that needs to have separate bibliographies. Notice that this means that this particular chapterfile can never have the bare\cite
command. Any citation must be part of some subset thatmultibib
deals with(the reason is that when 'switching off' the
chapterbib
package, the\cite
command works in the standard way, meaning that the\bibliography
command corresponding to any\cite
command in the chapterfile is expected in the main file.... hopefully this rather long explanation makes sense.. :P)Step 1: create a backup of the commands that will be overwritten by loading
multibib
/chapterbib
:Step 2: load
multibib
and define the required bibliography groups you need. Let me remind you again, that later onchapterbib
will be 'switched off' whenever we makemultibib
'active'. The consequence is that each citation inside a chapterfile that is processed bymultibib
must be part of some group, ie you can only use\citeXXX
commands for groups you created using\newcites{XXX}{Some title}
. So e.g. one could have:Step 3: the
multibib
package actually only rewrites the\bibliography
and\thebibliography
command. Next store these rewritten versions and move back to the original versions:Step 4: as far as the
chapterbib
package is concerned, it is as if themultibib
was never loaded, so we can safely load the former package and store the changes it made:Step 5: this step is at your own convenience and mainly safes typing - it entails creating a set of macros that allow easily switching between '
chapterbib
-mode' and 'multibib
-mode':Towards your document: so how to use all this? This is what your 'main' file could look like using the
bibmulti
andbibchapter
macros:This assumes the above described header, where indeed
chapterbib
is loaded second. That package will kick in for the first two chapters, each of which should have commands:Then, just before including chapter three, we 'switch off'
chapterbib
and 'switch on'multibib
; this file should use the special citation commands created bymultibib
, e.g.:Then, after chapter 3 was processed, the
bibchapter
macro again switches to using thechapterbib
version of the citation macros. So when chapter 4 is included, we're back to the original situation and thechapterbib
package will again make sure that a separate reference list is created for that chapter.I hope this explains covers enough for others. Maybe for reference I should mention that after TeXing this document, you'll need to run
bibtex
on the chapter files for chapters 1,2 and 4 (chapterbib
writes citations inside the '.aux' file for the separate chapters) and on the files main.aux, man.aux and com.aux (these are the files created bymultibib
)Limitations Each time you call
\newcite
, an element is pushed to the write-stack (I think). By using this setup you prevent having to do that for each chapter, but still if you have many chapters that need to be dealt with bymultibib
you'll likely still hit the limit of the write stack. In other words: this setup is designed for the case where the situation of multiple sets of references per chapter is rare (actually, in my particular case there is only one such chapter)There may be other limitations I'm not aware of. I'm just a newbie at writing TeX for my LaTeX documents, so I really can't give guarantees about the applicability of this solution to other systems and related situations.