使用 hyperref 反向引用参考书目:格式化单独的页码

使用 hyperref 反向引用参考书目:格式化单独的页码

当引用通过自定义命令调用时,我希望将反向引用格式化为斜体(否则则不行)。我在自定义命令中尝试过和\backrefxxx\backrefalt但无济于事。

\documentclass[a4paper,oneside,12pt]{book}
\usepackage[backref=page]{hyperref}

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@book{companion,
  author={Frank Mittelbach and Michel Goossens},
  title={The \LaTeX{} Companion},
  year={2008},
  publisher={Addison-Wesley},
  isbn={0-201-36299-6},
}
\end{filecontents*}

\newcommand{\mycite}[1]{ %%% first version I tried
  \let\oldbackrefxxx\backrefxxx
  \renewcommand{\backrefxxx}[3]{\hyperlink{page.##1}{\textit{##1}}}

  \cite{#1}

  \let\backrefxxx\oldbackrefxxx %%%% If I comment this line, all backreferences are in italics; it I uncomment it, all are in normal font 
}

\renewcommand{\mycite}[1]{  %%% second version I tried, same results
  \let\oldbackref\backref
  \let\oldbackrefalt\backrefalt
  \renewcommand*{\backref}{}
  \renewcommand*{\backrefalt}[4]{\textit{\ifcase ##1 {}\or {\textit{##2}}\else {\textit{##2}}\fi}}

  \cite{#1}

  %\let\backref\oldbackref
  %\let\backrefalt\oldbackrefalt
}


\begin{document}
\cite{companion}      %% the backreference to page 1 should be in normal font
\newpage
\mycite{companion}    %% the backreference to page 2 should be in italics
\newpage
\cite{companion}      %% the backreference to page 3 should be in normal font again

\bibliographystyle{plain}
\bibliography{\jobname.bib}
\end{document}

我看到这意味着反向引用在排版时就被格式化了,而不是在调用引用命令时;并且在排版时,\backrefxxx和每个都\backrefalt只能有一个定义。

有什么方法可以让反向引用列表中的某些项目具有与其他项目不同的样式?

答案1

你可以尝试这个:

\documentclass[a4paper,oneside,12pt]{book}
\usepackage[backref=page]{hyperref}
\usepackage{xpatch,expl3}

\makeatletter
\newcommand\mymarkpage{}
\xpatchcmd\Hy@backout{{\thepage}}{{\mymarkpage\thepage}}{}{\fail}
\xpatchcmd\Hy@backout{{\thepage}}{{\mymarkpage\thepage}}{}{\fail}
\makeatother

\ExplSyntaxOn
\renewcommand{\backrefxxx}[3]{
 \tl_if_head_eq_charcode:nNTF {#1}!
  {
    \hyperlink{page.\tl_tail:n{#1}}{{\textit{\tl_tail:n{#1}}}}
  }
  {
    \hyperlink{page.#1}{#1}
  }}
\ExplSyntaxOff


\newcommand{\mycite}[1]{%%% 
 {{\renewcommand\mymarkpage{!}%
  \cite{#1}}}}


\begin{document}

\cite{companion}      %% the backreference to page 1 should be in normal font
\newpage
\mycite{companion}    %% the backreference to page 2 should be in italics
\newpage
\cite{companion}      %% the backreference to page 3 should be in normal font again


\bibliographystyle{plain}

\bibliography{biblatex-examples}
\end{document}

在此处输入图片描述

相关内容