[Tex/LaTex] chicago.sty and hyperref: hyperlink formatting

bibliographiescitinghyperref

chicago.sty offers a number of citation commands which may output a link to the bibliography if hyperref is used. As long as no page number is given, hyperlink formatting is as expected (cf. last column). However, if a page number is to be displayed, citeN and shortciteN do include it in the hyperlink, whereas the other commands don't.

How could these commands be redefined to let their optional parameter always be formatted as a hyperlink?*

enter image description here

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

*Changing citeN and shortciteN to not apply hyperlink formatting to their optional parameter is not an option. It would lead to the rather unpleasant result that while the parentheses are hyperlinks (which they should be, for the sake of consistency with each command's version without optional page parameter), something inside the parentheses, namely the optional parameter, is not a hyperlink.

Best Answer

First of all I want to recommend to avoid the old package chicago instead use biblatex

The package hyperref has a small support for the package chicago. It redefines some internal commands of chicago.sty to get the correct hyperlink. The internal definition is:

\@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}]%
  }%
}{}

Based on this modification I took the original definition of \citeyearNP and \citeyear and modified them after the scheme of hyperref:

The original definition of 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}

Modified version:

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

With this redefinition you will get:

enter image description here

Here the complete code. Of course the other cite commands must be redefined too. But I think that it can be done easily by you.

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