# chicago.sty and hyperref: hyperlink formatting

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?*

\documentclass{article}
\usepackage{chicago}
\usepackage{filecontents}

\begin{filecontents*}{references.bib}
@book{ref,
author    = {Donald E. Knuth},
title     = {The TeXbook},
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.

• Do you mean the chicago.sty file from 1992 (i.e., from before there was even a LaTeX2e)? Surely whatever 'Chicago' guidelines it implements, it is massively out of date. The 16th ed. came out in 2010, the 14th in 1993, and the 13th in 1982! A better bet would be to use biblatex-chicago with bibiatex and (ideally) biber. – jon May 31 '12 at 23:58
• Indeed, that's the one I mean. And true, it is out of date. I have considered switching to biblatex and certainly will one day, but currently I'm locked into chicago.sty. – dgs Jun 1 '12 at 0:23
• @jon: Just to clarify, in case any confusion arises: The file chicago.sty provides various citation commands but doesn't implement the BibTeX-related matter. That's left to chicago.bst -- which, as you note, is also massively out of date since it implements the guidlines of the 13th ed of the CMoS whereas we're now at the 16th ed. – Mico Jun 1 '12 at 2:05
• @Mico -- Right! I wrote too quickly (as usual). – jon Jun 1 '12 at 4:19
• @dgs -- There is also the 'achicago' bundle, which is more up to date than chicago. No idea how useful it is. From the look of chicago.sty no provision is made to worry about what hyperref may or may not be doing, and the way parentheses are used in \citeN and \shortciteN seems very much hard-coded into the command definitions. – jon Jun 1 '12 at 4:51

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:

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

• Thanks! I've added the complete list of redefinitions. How could it be sent to the hyperref maintainer (as a feature request)? I did not see any contact information neither on CTAN nor in the manual. – dgs Jun 4 '12 at 19:13
• @dgs: Type texdoc oberdiek and you will find the contact. – Marco Daniel Jun 4 '12 at 19:14

For the record, here's the complete list. It is tested to work even in the rare case that multiple references should share the same page number. All credit goes to @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}

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

\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