似乎 hyperref 创建的引用链接总是指向列出相应条目的第一个参考书目,而不是当前参考书目。有什么方法可以修复此行为吗?
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{MWE.bib}
@article{articleA,
author = {Clark Kent},
title = {On why superman is stronger than batman},
journal = {The daily planet},
year = {2016},
}
\end{filecontents}
\usepackage[backend=biber,style=alphabetic]{biblatex}
\addbibresource{MWE.bib}
\usepackage[colorlinks]{hyperref}
\hypersetup{urlcolor=blue, citecolor=blue, linkcolor=blue}
\begin{document}
\begin{refsegment}
\section{Section Title A}
\cite{articleA}
\printbibliography[segment=\therefsegment]
\end{refsegment}
\newpage
\begin{refsegment}
\section{Section Title B}
This links to the bibliography of section A instead of B: \cite{articleA}
\printbibliography[segment=\therefsegment]
\end{refsegment}
\newpage
\begin{refsegment}
\section{Section Title C}
This links to the bibliography of section A instead of C: \cite{articleA}
\printbibliography[segment=\therefsegment]
\end{refsegment}
\end{document}
答案1
如果您坚持的话,您可以使链接本地化到 refesction 和 refsegment。
\makeatletter
\appto\blx@mkhyperref{%
\let\blx@anchors\@empty
\ifundef\hyper@natanchorstart
{\protected\def\blx@anchor{%
\xifinlist{\the\c@refsection @\the\c@refsegment @\abx@field@entrykey}{\blx@anchors}
{}
{\listxadd\blx@anchors{\the\c@refsection @\the\c@refsegment @\abx@field@entrykey}%
\hypertarget{cite.\the\c@refsection @\the\c@refsegment @\abx@field@entrykey}{}}}}
{\protected\def\blx@anchor{%
\xifinlist{\the\c@refsection @\the\c@refsegment @\abx@field@entrykey}{\blx@anchors}
{}
{\listxadd\blx@anchors{\the\c@refsection @\the\c@refsegment @\abx@field@entrykey}%
\hyper@natanchorstart{\the\c@refsection @\the\c@refsegment @\abx@field@entrykey}%
\hyper@natanchorend}}}}
\appto\blx@mkhyperref{%
\protected\def\blx@imc@bibhyperref{%
\@ifnextchar[%]
{\blx@bibhyperref}
{\blx@bibhyperref[\abx@field@entrykey]}}%
\ifundef\hyper@natanchorstart
{\long\def\blx@bibhyperref[#1]#2{%
\blx@sfsave\hyperlink{cite.\the\c@refsection @\the\c@refsegment @#1}{\blx@sfrest
#2%
\blx@sfsave}\blx@sfrest}%
\protected\long\def\blx@imc@bibhyperlink#1#2{%
\blx@sfsave\hyperlink{cite.\the\c@refsection @\the\c@refsegment:#1}{\blx@sfrest
#2%
\blx@sfsave}\blx@sfrest}%
\protected\long\def\blx@imc@bibhypertarget#1#2{%
\blx@sfsave\hypertarget{cite.\the\c@refsection @\the\c@refsegment:#1}{\blx@sfrest
#2%
\blx@sfsave}\blx@sfrest}}%
{\long\def\blx@bibhyperref[#1]#2{%
\blx@sfsave\hyper@natlinkstart{\the\c@refsection @\the\c@refsegment @#1}\blx@sfrest
#2%
\blx@sfsave\hyper@natlinkend\blx@sfrest}%
\protected\long\def\blx@imc@bibhyperlink#1#2{%
\blx@sfsave\hyper@natlinkstart{\the\c@refsection @\the\c@refsegment:#1}\blx@sfrest
#2%
\blx@sfsave\hyper@natlinkend\blx@sfrest}%
\protected\long\def\blx@imc@bibhypertarget#1#2{%
\blx@sfsave\hyper@natanchorstart{\the\c@refsection @\the\c@refsegment:#1}\blx@sfrest
#2%
\blx@sfsave\hyper@natanchorend\blx@sfrest}}
\let\blx@imc@ifhyperref\@firstoftwo
\def\blx@sf{\spacefactor}%
\def\blx@sfsave{%
\blx@leavevmode
\numgdef\blx@sf{\spacefactor}}%
\def\blx@sfrest{%
\ifhmode\spacefactor\blx@sf\relax\fi
\gdef\blx@sf{\spacefactor}}}
\makeatother
仅仅是从中复制相关宏biblatex_.sty
并\the\c@refsection @
扩展到\the\c@refsection @\the\c@refsegment @
使链接也本地化到 refsegments。
答案2
首先,关于使用refsegment
vs. 的一些说明refsection
。如果您希望在大型作品的不同位置使用不同的参考书目,则可以使用 refsections;例如在每章末尾。生成的标签始终是 refsection 的本地标签。相比之下,refsegments 适用于在末尾有一个参考书目,然后您可以将其分成几部分(例如,针对每个章节)等。引用 biblatex 手册(第 80 页):
关于重新剖析:
环境
refsection
用于在文档主体中标记参考部分。如果您希望在文档的每个章节、部分或任何其他部分中拥有单独的、独立的参考书目和参考书目列表,则此环境非常有用。在参考部分中,所有引用的著作都分配有环境本地的标签。
在 refsegments 上:
该
refsegment
环境用于在文档主体中标记参考段。如果您想要一个按章节,章节或文档的任何其他部分细分的全局参考书目,则此环境很有用。
因此,正如您在示例中所指出的那样,使用 refsegment,引用始终链接回第一个参考书目。但是,如果您使用反射,则会获得本地标签,因此引用会链接到本地参考书目。
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{MWE.bib}
@article{articleA,
author = {Clark Kent},
title = {On why superman is stronger than batman},
journal = {The daily planet},
year = {2016},
}
@article{articleB,
author = {Bruce Wyne},
title = {On why batman is stronger than superman},
journal = {The daily planet},
year = {2016},
}
\end{filecontents}
\usepackage[backend=biber,style=alphabetic]{biblatex}
\addbibresource{MWE.bib}
\usepackage[colorlinks]{hyperref}
\hypersetup{urlcolor=blue, citecolor=blue, linkcolor=blue}
\begin{document}
\begin{refsection}
\section{Section Title A}
\cite{articleA}
\printbibliography[section=\therefsection]
\end{refsection}
\newpage
\begin{refsection}
\section{Section Title B}
This link to the bibliography : \cite{articleA}\\
This link to the bibliography here: \cite{articleB}
\printbibliography[section=\therefsection]
\end{refsection}
\newpage
\begin{refsection}
\section{Section Title C}
This link to the bibliography: \cite{articleA}\\
This link to the bibliography: \cite{articleB}
\printbibliography[section=\therefsection]
\end{refsection}
\end{document}