# Manual citation formatting

First off: I don't want to use bibtex for this; I want to typeset my bibliography myself.

Looking at the source2e.pdf document I found out about redefining \@cite and \@biblabel, and got my citation style pretty much set up with this.

The problem which remains now is this: I'd like to allow for two different ways of citing a person. (This seems to be called “harvard style”.) One would be in the body of the text:

… as John Doe (1900) demonstrated …

while the other one would be parenthesized:

… has already been demonstrated (John Doe 1900).

Now my problem is the different handling of the year, which has to be parenthesized in one form but not in the other. Of course, I'd need two different commands for the different citations. But so far, every attempt at splitting up the citation label has failed, at least if I want to also use hyperref. Without that package, the following seems to satisfy my requirements:

\documentclass{article}
% \usepackage{hyperref}
\makeatletter
\def\@cite#1#2{ ({#1\if@tempswa , #2\fi})}
\def\@biblabel#1{}
\def\@cite@ofmt#1{\edef\my@tmp{#1}\expandafter\my@split\my@tmp}
\def\my@split#1(#2){\hbox{#1#2}}
\def\my@tcite#1#2{{#1\if@tempswa , #2\fi}}
\def\my@tsplit#1(#2){\hbox{#1(#2)}}
\newcommand\tcite[1]{{\let\@cite\my@tcite\let\my@split\my@tsplit\cite{#1}}}
\makeatother
\begin{document}
\ldots has already been demonstrated \cite{JohnDoe}.\par
\ldots as \tcite{JohnDoe} demonstrated \ldots\par
\ldots has already been demonstrated \cite{JohnDoe}.\par
\begin{thebibliography}{1}
\bibitem[John Doe (1900)]{JohnDoe}
John Doe, The famous book, 1900.
\end{thebibliography}
\end{document}


But with hyperref enabled, I get this error message:

! Undefined control sequence.


Looking at the source code of hyperref.sty, I see that it does attempt to support compatibility with the harvard package. So I adjusted my example to this:

\documentclass{article}
\usepackage{harvard}
\usepackage{hyperref}
\begin{document}
\ldots has already been demonstrated \cite{JohnDoe}.\par
\ldots as \citeasnoun{JohnDoe} demonstrated \ldots\par
\ldots has already been demonstrated \cite{JohnDoe}.\par
\begin{thebibliography}{1}
\harvarditem{John Doe}{1900}{JohnDoe}
John Doe, The famous book, 1900.\par
\end{thebibliography}
\end{document}


But I keep getting

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.


no matter how many times I process the document. And I don't get any hyperlinks.

How can I get harvard style citations with a manually set bibliography and with working hyperlinks for my citations?

I'm using texlive 2013, which includes hyperref.sty v6.83m from 2012/11/06 and harvard.sty version 2.0.5 apparently from 1994.

• Load harvard after hyperref. But you won't get hyperlinks. May 16 '14 at 23:22
• @egreg - Better yet, don't load harvard at all; instead, load both natbib and har2nat. Using these two packages enables the hyperlinking of the citation callouts to the corresponding entries in the bibliography, while preserving the ability to use harvard-based macros such as \citeasnoun and \harvarditem.
– Mico
May 17 '14 at 17:56

To achieve full inter-operability between citation commands and the hyperref package, it's advisable to load the natbib and har2nat packages instead of the harvard package. (If you load natbib and har2nat, you should not load the harvard package.)

In the example below, note that \harvarditem and \citeasnoun are harvard-based macros that are "translated" transparently by the har2nat package into instructions that are understood by natbib. The macro \cite, which is also available in "Basic LaTeX" (i.e., without any citation-management packages being loaded), is modified by natbib to be usable for authoryear-style citations. Finally, \citet, \citep, \citealt, \citealp, and \citeauthor are macros provided directly by the natbib package.

\documentclass{article}
\usepackage{natbib,har2nat}
\setlength\parindent{0pt} % just for this example
\begin{document}
\ldots\ has already been demonstrated \cite{JohnDoe}.

\ldots\ as \citeasnoun{JohnDoe} has demonstrated \ldots

\citet{JohnDoe}; \citealt{JohnDoe}

\citep{JohnDoe}; \citealp{JohnDoe}

\citeauthor{JohnDoe}

\begin{thebibliography}{99}
\harvarditem{Doe}{1900}{JohnDoe}
John Doe, {\em The Famous Book}, Forest Glen: The Buck Press. 1900.
\end{thebibliography}
\end{document}


Addendum: If you're building the bibliography entirely by hand anyway, there's no real reason to take a detour via \harvarditem{}{}{}... instructions and have them be "translated" into natbib-equivalent directives. Instead, just use the natbib-based syntax directly. (Doing so will also let you skip having to load har2nat). The preceding code would then look like this -- note the use of \bibitem instead of \harvarditem:

\documentclass{article}
\usepackage{natbib}
\setlength\parindent{0pt} % just for this example
\begin{document}
\ldots\ has already been demonstrated \cite{JohnDoe}.

\ldots\ as \citeauthor{JohnDoe} has demonstrated \ldots

\citet{JohnDoe}; \citealt{JohnDoe}

\citep{JohnDoe}; \citealp{JohnDoe}

\begin{thebibliography}{99}
\bibitem[Doe(1900)]{JohnDoe}
John Doe, {\em The Famous Book}, Forest Glen: The Buck Press. 1900.
\end{thebibliography}
\end{document}

• Looking at the sources, I noticed that while \cite and \citeasnoun come from har2nat, the support for \harvarditem appears to be coded directly into natbib. har2nat.sty is really small. Nevertheless, I do prefer the \bibitem style you used in your example, so I'll stick with that. Thanks a lot!
– MvG
May 17 '14 at 11:28

# Make harvard and hyperref cooperate

harvard will load html (if it exists) which in turn will load hyperref when using pdflatex. So hyperref is loaded before harvard even if you use these packaes in a different order. Therefore hyperred cannot define \harvardcite directly, since otherwise the \newcommand in harvard would complain. Instead, hyperref tries to redefine that macro in its \AtBeginDocument hook. But that is too late: that hook is executed after the jobname.aux file got read in, and it's that aux file which contains the \harvardcite calls where this is needed. So the version from hyperref is never called.

So my workaround at the moment is to unconditionally define \harvardcite the way hyperref defines it, but do so before the jobname.aux file is read:

\documentclass{article}
\usepackage{hyperref}
\usepackage{harvard}

\makeatletter
\gdef\harvardcite#1#2#3#4{%
\global\@namedef{HAR@df@#1}{\csname HAR@fn@#1\endcsname}%
}
\makeatother

\begin{document}
\ldots has already been demonstrated \cite{JohnDoe}.\par
\ldots as \citeasnoun{JohnDoe} demonstrated \ldots\par
\ldots has already been demonstrated \cite{JohnDoe}.\par
\begin{thebibliography}{1}
\harvarditem{John Doe}{1900}{JohnDoe}
John Doe, The famous book, 1900.\par
\end{thebibliography}
\end{document}


In this toy example I still get warnings:

LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
pdfTeX warning (dest): name{cite.JohnDoe} has been referenced but does not exist, replaced by a fixed one


But in the real document where I actually need this, things work out fine. Not sure what's going on here, but I'm happy as long as things work where I really need them. And even the toy looks sane enough, despite the warnings.

• In order to get optimal inter-operability with hyperref, it's actually better to load both the natbib and har2nat packages instead of the harvard package.
– Mico
May 17 '14 at 9:04
• @Mico: That sounds like a good suggestion, and seems to work out of the box. Would you care to post that as an answer in its own right?
– MvG
May 17 '14 at 9:09
• You may want to send a link to this posting to the maintainer(s) of the hyperref package to alert him/them to the problem that that package's harvard-related macros aren't executed at the correct time.
– Mico
May 17 '14 at 18:02