TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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> 
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?

share|improve this question
Is switching to biblatex an option? Then read on here: tex.stackexchange.com/questions/26598/… (also notice the linked questions at the right side) – matth May 14 '12 at 14:15
That's a good suggestion, I need to check it out a bit more. The main problem I foresee is that the printer forces use to use the \cite command and if I understand things correctly, I'd have to replace these commands with a different biblatex command right? On the other hand.... I was already kind of doing that when using multibib.... :P – Jakob van Bethlehem May 14 '12 at 14:29
Hmm, the special .bst files from the publisher also seem to give problems with biblatex. That's a bit more cumbersome. – Jakob van Bethlehem May 14 '12 at 14:33
If you rely on a .bst file, biblatex is unfortunately no option. The whole point of biblatex is to get rid of the .bst language and delegate all formatting to style files written in LaTeX. – Simifilm May 14 '12 at 14:38
Consider to switch to biblatex, select a style shippped with it that resembles your style and tweak it with the help of tex.stackexchange.com/questions/12806/…. – lockstep May 14 '12 at 17:57
up vote 4 down vote accepted

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 rather chapterbib.

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' the chapterbib 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 that multibib 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 on chapterbib will be 'switched off' whenever we make multibib 'active'. The consequence is that each citation inside a chapterfile that is processed by multibib 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:

\newcites{com}{Complete Works}

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 the multibib 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':

\def\bibmulti{% switch to multibib-mode

\def\bibchapter{% switch to 'chapterbib'-mode

Towards your document: so how to use all this? This is what your 'main' file could look like using the bibmulti and bibchapter macros:

\documentclass{article} % or whatever class you want

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 by multibib, e.g.:

% etc...
% etc...



Then, after chapter 3 was processed, the bibchapter macro again switches to using the chapterbib version of the citation macros. So when chapter 4 is included, we're back to the original situation and the chapterbib 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 by multibib)

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 by multibib 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.