hyperref 和 bibunits:链接无效

hyperref 和 bibunits:链接无效

我经常喜欢使用 hyperref 来使参考书目中的定理和文章的引用可点击。但是,我注意到当我使用 bibunits 时,我只能点击指向定理的链接,而不能点击指向参考书目中的文章的链接。

这是一个最小的例子

\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}

有什么办法可以解决这个问题吗?谢谢!

答案1

已提供解决方案derkeiler 上的 comp.text.tex 档案。我想保存解决方案,所以我提供了这个 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}

答案2

为了使上述解决方案适用于\cite{article1, article2},将\hyper@natlinkstart{#2}%的定义替换\@citex\hyper@natlinkstart{\@citeb}%

相关内容