I want to generate the bibliography for each section, and have it at the end of the section. When I do this at the moment it generates the full bibliography and places it after each section.
Is there a way that this can be done?
The advice here says
"The chapterbib package provides an
option sectionbib that puts the
bibliography in a \section* instead of
\chapter*, something that makes sense
if there is a bibliography in each
chapter. This option will not work
when natbib is also loaded; instead,
add the option to natbib. "
I don't understand what this means, and I've tried experimenting with what I thought the options are. Specifically, what does "add the option to natbib" mean?
My subsequent question (which evolved after my first one was solved) is to not have pagebreaks between the references, and the next section.
Thank you for your help.
If you are using Biblatex, as for citing article titles, you can use it to produce bibliographies at the end of sections or chapters, or even have a combined bibliography where they are separated by chapter/section. As a package, it is intended to replace "babelbib, bibtopic, bibunits, chapterbib, cite, inlinebib, mlbib, multibib, splitbib."
You can put a bibliography after each section, in one of three ways. First, wrap the text of your section in a \begin{refsection}
/\end{refsection}
pair, as such
\section{SomeSectionName}
\begin{refsection}
% your text goes here
\printbibliography
\end{refsection}
\section{NextSection}
Second, after each \section
statement you put a \newrefsection
statement which ends the previous section and begins the new one. And, you precede the next \section
with a \printbibliography
statement, again. Finally, there is a refsection
package option that takes either none
, part
, chapter
, section
, or subsection
as an argument. To group your bibliographic entries per section in a global bibliography you use refsegment
instead, using \bibbysegment
to print all the segments in order. (\bibbysection
can be used in the same manner for ref-sections, too.)
I don't know how much you'll have to split up your text, as per @Norman's answer, but with a little experimentation you can figure it out.
In addition to
\usepackage[sectionbib]{natbib}
\usepackage{chapterbib}
You will have to put each section in a separate .tex file which you then \include
. You will have to run bibtex
on each .tex file separately.
N.B. Using \input
rather than \include
avoids unwanted page breaks, but it will not create the .aux file that BibTeX needs to do its work. I looked at the definition of \include
, and I don't see how to disable the page-breaking function except by disabling \clearpage
entirely. You could try
\let\originalclearpage=\clearpage
\def\clearpage{\relax}
right after your \begin{document}
, but you may have to put some \originalclearpage
in by hand.
@celenius - if you really want to get rid of that pagebreak, here's a very dirty trick to do it...
\makeatletter
\let\O@@input@\@input@
\def\@noclearpage{\@ifnextchar\clearpage\@gobble\relax}
\def\@input@#1{\O@@input@{#1}\@noclearpage}
\let\O@@include\@include
\def\@include{\expandafter\@noclearpage\O@@include}
\let\O@include\include
\def\include{\expandafter\@noclearpage\O@include}
\makeatother
Basically we perform surgery on the \include
macro to get rid of all the \clearpage
instances, but the cleanest way to do this, as you can see, is still really dirty. This is horribly brittle and will likely only work for the article
class, so if you're using a different \documentclass
, you're out of luck. I basically derived this by enabling \tracingcommands=1
and \tracingmacros=1
and grepping the .log
file for \clearpage
so that I could hack whatever gets called before it to insert a \@noclearpage
.
I don't recommend this solution - it would be much better to look into how chapterbib
works and fix it the right way, without depending on \include
and the separate .aux
files it generates... but I'm positive that would be a pretty difficult task. I guess another workaround would be to write a command to emulate \include
's breaking up of .aux
files, without actually doing the includes...
EDIT: okay, here's a quickie
\makeatletter
\newenvironment{auxfile}[1]{\relax
\ifnum\@auxout=\@partaux
\@latex@error{auxfile environments cannot be nested or \string\include d}
\@eha
\else\@changeaux{#1}\fi
}{\immediate\closeout\@partaux\let\@auxout\@mainaux}
\def\@changeaux#1{%
\immediate\write\@mainaux{\string\@input{#1.aux}}%
\let\@auxout\@partaux
\immediate\openout\@partaux#1.aux%
\immediate\write\@partaux{\relax}}
\makeatother
Then you can just insert \begin{auxfile}{foo}...\end{auxfile}
and it will use foo.aux
instead of the normal .aux
file. This is fully compatible with chapterbib
. I don't think CTAN has anything like this, so maybe I'll submit it as a mini-package.
I haven't tried it but as I read that it suggests:
\usepackage[sectionbib]{natbib} % Note the option in the optional argument
\usepackage{chapterbib}
though I'm only guessing at the correct order of those lines.