chicago.sty
提供了许多引用命令,如果hyperref
使用,这些命令可能会输出参考书目的链接。只要没有给出页码,超链接格式就会符合预期(参见最后一列)。但是,如果要显示页码,citeN
请将shortciteN
其包含在超链接中,而其他命令则不会。
如何重新定义这些命令以使其可选参数始终被格式化为超链接?*
\documentclass{article}
\usepackage{chicago}
\usepackage{filecontents}
\usepackage[colorlinks=true,citecolor=red]{hyperref}
\begin{filecontents*}{references.bib}
@book{ref,
author = {Donald E. Knuth},
title = {The TeXbook},
publisher = {Addison-Wesley},
year = {1986}
}
\end{filecontents*}
\begin{document}
\begin{tabular}{llll}
& cite & \cite[p.\,1]{ref} & \cite{ref} \\
& citeNP & \citeNP[p.\,1]{ref} & \citeNP{ref} \\
& citeA & \citeA[p.\,1]{ref} & \citeA{ref} \\
& citeANP & \citeANP[p.\,1]{ref} & \citeANP{ref} \\
$\rightarrow$ & citeN & \citeN[p.\,1]{ref} & \citeN{ref} \\
& shortcite & \shortcite[p.\,1]{ref} & \shortcite{ref} \\
& shortciteNP & \shortciteNP[p.\,1]{ref} & \shortciteNP{ref} \\
& shortciteA & \shortciteA[p.\,1]{ref} & \shortciteA{ref} \\
& shortciteANP & \shortciteANP[p.\,1]{ref} & \shortciteANP{ref}\\
$\rightarrow$ & shortciteN & \shortciteN[p.\,1]{ref} & \shortciteN{ref} \\
& citeyear & \citeyear[p.\,1]{ref} & \citeyear{ref} \\
& citeyearNP & \citeyearNP[p.\,1]{ref} & \citeyearNP{ref} \\
\end{tabular}
\bibliographystyle{chicago}
\bibliography{references}
\end{document}
*改变citeN
和shortciteN
不是对其可选参数应用超链接格式不是一个选项。这会导致一个相当不愉快的结果,即虽然括号是超链接(为了与没有可选页面参数的每个命令的版本保持一致,它们应该是超链接),括号内的内容,即可选参数,不是超链接。
答案1
首先,我想建议避免使用旧包,chicago
而是使用biblatex
该软件包hyperref
对软件包有少量支持chicago
。它重新定义了一些内部命令以chicago.sty
获取正确的超链接。内部定义是:
\@ifpackageloaded{chicago}{%
\def\citeN{%
\def\@citeseppen{-1000}%
\def\@cite##1##2{##1}%
\def\citeauthoryear##1##2##3{##1 (##3\@cite@opt)}%
\@citedata@opt
}%
\def\shortciteN{%
\def\@citeseppen{-1000}%
\def\@cite##1##2{##1}%
\def\citeauthoryear##1##2##3{##2 (##3\@cite@opt)}%
\@citedata@opt
}%
\def\@citedata@opt{%
\let\@cite@opt\@empty
\@ifnextchar [{%
\@tempswatrue
\@citedatax@opt
}{%
\@tempswafalse
\@citedatax[]%
}%
}%
\def\@citedatax@opt[#1]{%
\def\@cite@opt{, #1}%
\@citedatax[{#1}]%
}%
}{}
基于此修改,我采用了\citeyearNP
和的原始定义,\citeyear
并按照以下方案对其进行了修改hyperref
:
的原始定义chicago.sty
:
\def\citeyear{\def\@citeseppen{-1000}%
\def\@cite##1##2{(##1\if@tempswa , ##2\fi)}%
\def\citeauthoryear##1##2##3{##3}\@citedata}
\def\citeyearNP{\def\@citeseppen{-1000}%
\def\@cite##1##2{##1\if@tempswa , ##2\fi}%
\def\citeauthoryear##1##2##3{##3}\@citedata}
修改版本:
\def\citeyear{\def\@citeseppen{-1000}%
\def\@cite##1##2{(##1)}%
\def\citeauthoryear##1##2##3{##3\@cite@opt}\@citedata@opt}
\def\citeyearNP{\def\@citeseppen{-1000}%
\def\@cite##1##2{##1}%
\def\citeauthoryear##1##2##3{##3\@cite@opt}\@citedata@opt}
通过重新定义,您将获得:
这是完整的代码。当然,其他引用命令也必须重新定义。但我认为你可以轻松完成。
\documentclass{article}
\usepackage{chicago}
\usepackage{filecontents}
\usepackage[colorlinks=true,citecolor=red]{hyperref}
\makeatletter
\def\citeyear{\def\@citeseppen{-1000}%
\def\@cite##1##2{(##1)}%
\def\citeauthoryear##1##2##3{##3\@cite@opt}\@citedata@opt}
\def\citeyearNP{\def\@citeseppen{-1000}%
\def\@cite##1##2{##1}%
\def\citeauthoryear##1##2##3{##3\@cite@opt}\@citedata@opt}
\makeatother
\begin{filecontents*}{references.bib}
@book{ref,
author = {Donald E. Knuth},
title = {The TeXbook},
publisher = {Addison-Wesley},
year = {1986}
}
\end{filecontents*}
\begin{document}
\begin{tabular}{llll}
& cite & \cite[p.\,1]{ref} & \cite{ref} \\
& citeNP & \citeNP[p.\,1]{ref} & \citeNP{ref} \\
& citeA & \citeA[p.\,1]{ref} & \citeA{ref} \\
& citeANP & \citeANP[p.\,1]{ref} & \citeANP{ref} \\
$\rightarrow$ & citeN & \citeN[p.\,1]{ref} & \citeN{ref} \\
& shortcite & \shortcite[p.\,1]{ref} & \shortcite{ref} \\
& shortciteNP & \shortciteNP[p.\,1]{ref} & \shortciteNP{ref} \\
& shortciteA & \shortciteA[p.\,1]{ref} & \shortciteA{ref} \\
& shortciteANP & \shortciteANP[p.\,1]{ref} & \shortciteANP{ref}\\
$\rightarrow$ & shortciteN & \shortciteN[p.\,1]{ref} & \shortciteN{ref} \\
& citeyear & \citeyear[p.\,1]{ref} & \citeyear{ref} \\
& citeyearNP & \citeyearNP[p.\,1]{ref} & \citeyearNP{ref} \\
\end{tabular}
\bibliographystyle{chicago}
\bibliography{references}
\end{document}
答案2
为便于记录,以下是完整列表。经过测试,即使在多个参考文献共享相同页码的罕见情况下,该列表也能正常工作。所有荣誉均归于@MarcoDaniel。
\makeatletter
\def\cite{\def\@citeseppen{-1000}%
\def\@cite##1##2{(##1)}%
\def\citeauthoryear##1##2##3{##1 ##3\@cite@opt}\@citedata@opt}
\def\citeNP{\def\@citeseppen{-1000}%
\def\@cite##1##2{##1}%
\def\citeauthoryear##1##2##3{##1 ##3\@cite@opt}\@citedata@opt}
%\citeN already modified by hyperref
\def\citeA{\def\@citeseppen{-1000}%
\def\@cite##1##2{(##1)}%
\def\citeauthoryear##1##2##3{##1\@cite@opt}\@citedata@opt}
\def\citeANP{\def\@citeseppen{-1000}%
\def\@cite##1##2{##1}%
\def\citeauthoryear##1##2##3{##1\@cite@opt}\@citedata@opt}
\def\shortcite{\def\@citeseppen{-1000}%
\def\@cite##1##2{(##1)}%
\def\citeauthoryear##1##2##3{##2 ##3\@cite@opt}\@citedata@opt}
\def\shortciteNP{\def\@citeseppen{-1000}%
\def\@cite##1##2{##1}%
\def\citeauthoryear##1##2##3{##2 ##3\@cite@opt}\@citedata@opt}
%\shortciteN already modified by hyperref
\def\shortciteA{\def\@citeseppen{-1000}%
\def\@cite##1##2{(##1)}%
\def\citeauthoryear##1##2##3{##2\@cite@opt}\@citedata@opt}
\def\shortciteANP{\def\@citeseppen{-1000}%
\def\@cite##1##2{##1}%
\def\citeauthoryear##1##2##3{##2\@cite@opt}\@citedata@opt}
\def\citeyear{\def\@citeseppen{-1000}%
\def\@cite##1##2{(##1)}%
\def\citeauthoryear##1##2##3{##3\@cite@opt}\@citedata@opt}
\def\citeyearNP{\def\@citeseppen{-1000}%
\def\@cite##1##2{##1}%
\def\citeauthoryear##1##2##3{##3\@cite@opt}\@citedata@opt}
\makeatother