[Tex/LaTex] Multibib bibliographies as subsections

bibtexmultibibsubdividing

The reason why I need this modification is that I want to have a general 'Bibliography' section in which all the bibliographies created with multibib are included. At the moment my code (narrowed down to a minimal working example) looks like this:

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
  @BOOK{Doe2013,
  title = {The concept of anonymity},
  author = {Doe, John},
  publisher = {Void},
  year = {2013}
  }
\end{filecontents*}

\documentclass{article}
\usepackage{multibib}
\newcites{ads}{Advertisments}

\begin{document}
\tableofcontents
\nocite{Doe2013}
\nociteads{Doe2014}
\clearpage
\section*{Bibliography}
\bibliographystyleads{plain}
\bibliographyads{ads}
\renewcommand{\refname}{Books and Articles}
\bibliographystyle{plain}
\bibliography{\jobname}
\end{document}

This (obviously) will create three sections in the end, which is not what I intended for I wish to have one section ("References") with two subsections ("Advertisements" and "Books and Articles"). How can I obtain that the \bibliography'ish macros call \subsection* instead of \section*?

Addendum

Here is a sample ads.bib:

@BOOK{Doe2014,
  title = {The concept of anonymity 2},
  author = {Doe, John},
  publisher = {Void},
  year = {2014}
  }

Edit

I forgot to mention that I want the bibliographies both automatically added to the TOC.

Best Answer

Add this to your example preamble:

\usepackage{etoolbox}

\ifdefined\chapter
  \newcommand{\refname}{References}
  \patchcmd{\thebibliography}{\chapter*{\bibname}}{%
    \section*{\refname}
    \addcontentsline{toc}{section}{\refname}
    }{}{}
  \newcommand{\bibliographies}{%
    \chapter*{\bibname}
    \addcontentsline{toc}{chapter}{\bibname}
  }
\else
  \newcommand{\bibname}{Bibliography}
  \patchcmd{\thebibliography}{\section*{\refname}}{%
    \subsection*{\refname}
    \addcontentsline{toc}{subsection}{\refname}
    }{}{}
  \newcommand{\bibliographies}{%
    \section*{\bibname}
    \addcontentsline{toc}{section}{\bibname}
  }
\fi

and \bibliographies (which is defined in my code snippet) right before the bibliographies start.

As you can see I expanded the functionality to classes with \chapters.

Edit

You can't use the above solution with natbib because it redefines the thebibliography environment so that the etoolbox patch won't be able to find what he is looking for. This code should do the job:

\usepackage{etoolbox}

\makeatletter
\providecommand{\bibname}{Bibliography}
\providecommand{\refname}{References}
\@ifpackageloaded{natbib}
  {\renewcommand{\bibsection}{%
    \@ifundefined{chapter}
    {\subsection*{\refname \markboth{\refname}{\bibname}%
    \addcontentsline{toc}{subsection}{\refname}}
    }
    {\section*{\refname \markboth{\refname}{\bibname}%
    \addcontentsline{toc}{section}{\refname}}
    }
  }}
  {\@ifundefined{chapter}
    {\patchcmd{\thebibliography}{\section*{\refname}}{%
      \subsection*{\refname}
      \addcontentsline{toc}{subsection}{\refname}
      }{}{}
    }
    {\patchcmd{\thebibliography}{\chapter*{\bibname}}{%
      \section*{\refname}
      \addcontentsline{toc}{section}{\refname}
      }{}{}
    }
  }
\@ifundefined{chapter}
  {\newcommand{\bibliographies}{%
  \section*{\bibname}
  \if@FMB@addtotoc\addcontentsline{toc}{section}{\bibname}\fi}}
  {\newcommand{\bibliographies}{%
  \chapter*{\bibname}
  \if@FMB@addtotoc\addcontentsline{toc}{chapter}{\bibname}\fi}}
\makeatother