4

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!

  • When you use bibunits, it is possible for one unique bibliography entry to appear more than once in different bibliography lists. So there is a possibility of having two separate destinations for a single link. In this case that the destination is not unique, Hyperref simply gaves up and does not create any link for bibliography. – Aydin Feb 20 '13 at 14:32
  • @Aydin but this case does not happen in the MWE, and it also does not happen when simply each chapter has its own bibliography. – user87690 May 23 at 9:40
4

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}
  • Is this solution compatible with natbib and any of the other means of generating citation links such as citetor citep? To clarify, I think I recognize that the cite defs above will not extend automatically to cover citet or citep but I am not sure which ones I would duplicate and modify, particularly because I don't understand the origins of citea, citeb, and citex. – EngBIRD May 31 '15 at 19:21
  • 1
    This solution does not work with multiple citations, e.g. \cite{article1, article2}. Do you know of a fix for that? – arunchaganty Oct 31 '15 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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