6

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!

2
  • 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
    Commented Feb 20, 2013 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
    Commented May 23, 2019 at 9:40

2 Answers 2

7

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}
3
  • 1
    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
    Commented May 31, 2015 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? Commented Oct 31, 2015 at 3:50
  • It breaks \citep with errormessage ! Argument of \UTFviii@two@octets@combine has an extra }., unfortunately. Commented Oct 27, 2021 at 15:27
3

To make the solution above work for \cite{article1, article2}, replace \hyper@natlinkstart{#2}% in the definition of \@citex by \hyper@natlinkstart{\@citeb}%

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .