# How to write additional content into bbl file?

How can I tell LaTeX to write additional content to bbl file?

Background of my question (see also MWE below): The page number for the bibliography displayed in the table of contents is correct if and only if \addcontentsline{toc}{chapter}{Bibliography} is placed at the beginning of the thebibliography environment. Hence, using bibTeX I need to write \addcontentsline{toc}{chapter}{Bibliography} into the bbl file. If I place it before \begin{thebibliography} the page number is first page of bibliography - 1, if I place it after \end{thebibliography} it is last page of bibliography + 1 (which in the MWE would be correct but not in general).

\documentclass{book}

\begin{document}
\tableofcontents

\begin{thebibliography}{B}
\addcontentsline{toc}{chapter}{Bibliography}
\bibitem[B]{B}
A. Brown
\newblock {\em Mathematics}.
\end{thebibliography}

\end{document}

-
add comment

## 1 Answer

The correct approach to add a bibliography entry to the ToC is not to fiddle with the .bbl file, but a) to add \addcontentsline{toc}{(sectioning level>}{Bibliography} to the (class-dependend!) definition of the thebibliography environment or b) to load packages for this task, e.g., \usepackage[nottoc]{tocbibind}.

See also Bibliography in table of contents; Gonzalo Medina's answer shows how to patch the thebibliography environment for the book class.

-
Apparently tocbibind is incompatible with imakeidx. In particular, including tocbibind results in the loss of \indexprologue{abc}. Therefore I do no like including a package just for this purpose. One never knows what side effects new packages may possibly have ... –  lpdbw Feb 24 '13 at 17:00
@lpdbw Use Gonzalo Medina's approach or try to load imakeidx after tocbibind. –  lockstep Feb 24 '13 at 17:02
Yes, loading imakeidx after tocibind works. I wonder whether there are other unwanted effects due to tocibind which I am still ignoring ... I also tried Gonzalo Medina's second approach (the one with redefining \thebibliography`) ... a remaining issue in combination with hyperref, is that if I click on the ToC entry for the bibliography, I jump to the first bib entry but not (as it should be) to the title of the bibliography ... maybe I will make this a comment of Medina's answer. –  lpdbw Feb 24 '13 at 17:08
add comment