[Tex/LaTex] hyperref and bibunits: link does not work

bibliographiesbibunitshyperrefsubdividing

I often like to use hyperref to make references to theorems and articles in the bibliography clickable. However, I noticed that when I use bibunits, I can only click on links to theorems, not on links to articles in the bibliography.

Here is a minimal example

\documentclass[a4paper,11pt]{article}
\usepackage{bibunits}
\usepackage{hyperref}

\begin{document}

\defaultbibliography{mybib}
\defaultbibliographystyle{plain}

\begin{bibunit}
my reference \cite{book1}.
\putbib
\end{bibunit}

\end{document}

Is there any way to solve this?
Thanks!

Best Answer

A solution was provided comp.text.tex archive at derkeiler. I want to save the solution and so I provided this CW.

% arara: pdflatex 
% arara: bibtex: {files: [bu1,bu2]}
% arara: pdflatex
% arara: pdflatex
% package arara at http://ctan.org/pkg/arara
\documentclass[a4paper,11pt]{article}
\usepackage{bibunits}
\usepackage{hyperref}
 \makeatletter
\def\hyper@natlinkstart#1{%
  \Hy@backout{#1}%
  \hyper@linkstart{cite}{cite.\@bibunitname.#1}%
%                             ^^^^^^^^^^^^^^
  \def\hyper@nat@current{#1}%
}

\def\hyper@natlinkbreak#1#2{%
  \hyper@linkend#1\hyper@linkstart{cite}{cite.\@bibunitname.#2}%
%                                             ^^^^^^^^^^^^^^
}

\def\hyper@natanchorstart#1{%
  \hyper@anchorstart{cite.\@bibunitname.#1}%
%                         ^^^^^^^^^^^^^^
}

\def\bibcite#1#2{%
  \@newl@bel{b}{#1}{\hyper@@link[cite]{}{cite.\@bibunitname.#1}{#2}}%
%                                             ^^^^^^^^^^^^^^
}%

\def\@lbibitem[#1]#2{%
  \@skiphyperreftrue
  \H@item[\hyper@anchorstart{cite.\@bibunitname.#2}%
%                                 ^^^^^^^^^^^^^^
  \@BIBLABEL{#1}\hyper@anchorend\hfill]%
  \@skiphyperreffalse
  \if@filesw
    \begingroup
      \let\protect\noexpand
      \immediate\write\@auxout{%
        \string\bibcite{#2}{#1}%
      }%
    \endgroup
  \fi
  \ignorespaces
}%

\def\@bibitem#1{%
  \@skiphyperreftrue\H@item\@skiphyperreffalse
  \hyper@anchorstart{cite.\@bibunitname.#1}\relax\hyper@anchorend
%                         ^^^^^^^^^^^^^^
  \if@filesw
    \begingroup
      \let\protect\noexpand
      \immediate\write\@auxout{%
        \string\bibcite{#1}{\the\value{\@listctr}}%
      }%
    \endgroup
  \fi
  \ignorespaces
}%

\def\@citex[#1]#2{%
  \let\@citea\@empty
  \@cite{%
    \@for\@citeb:=#2\do{%
      \@citea
      \def\@citea{,\penalty\@m\ }%
      \edef\@citeb{\expandafter\@firstofone\@citeb}%
      \if@filesw
        \immediate\write\@auxout{\string\citation{\@citeb}}%
      \fi
      \@ifundefined{b@\@citeb}{%
        \mbox{\reset@font\bfseries ?}%
        \G@refundefinedtrue
        \@latex@warning{%
          Citation `\@citeb' on page \thepage \space undefined%
        }%
      }{%
        \hyper@natlinkstart{#2}%
%       ^^^^^^^^^^^^^^^^^^^^^^^^
            \hbox{\csname b@\@citeb\endcsname}%
        \hyper@natlinkend%
%       ^^^^^^^^^^^^^^^^^^
      }%
    }%
  }{#1}%
}%

\makeatother

\begin{document}

\defaultbibliography{xampl}
\defaultbibliographystyle{plain}

\begin{bibunit}
my reference \cite{article-full}.
\putbib
\end{bibunit}
\clearpage
\begin{bibunit}
my reference \cite{article-full}.
\putbib
\end{bibunit}

\end{document}
Related Question