josephwright / beamer

A LaTeX class for producing presentations and slides
Other
1.38k stars 140 forks source link

hyperlinks do not work with natbib citations (hyperref) #114

Closed josephwright closed 7 years ago

josephwright commented 13 years ago

Originally reported by: Anonymous


I am sure this is a known issue but I cannot find it in the tracker.

When using natbib and beamer, citations are not hyperlinked.

A workaround is to use:

\let\oldbibitem=\bibitem
\renewcommand{\bibitem}[2][]{\label{#2}\oldbibitem[#1]{#2}}
\let\oldcite=\cite
\renewcommand\cite[1]{\hyperlink{#1}{\oldcite{#1`
\let\oldcitep=\citep
\renewcommand\citep[1]{\hyperlink{#1}{\oldcitep{#1`
\let\oldciteauthor=\citeauthor
\renewcommand\citeauthor[1]{\hyperlink{#1}{\oldciteauthor{#1`
\let\oldbibitem=\bibitem

and so on for all natbib commands.


josephwright commented 8 years ago

Original comment by manulopezibanez (Bitbucket: manulopezibanez, GitHub: Unknown):


It still works for me. Small reproducer with a more complete workaround (surprisingly, inlining the content of the *.bbl file leads to error: ! Illegal parameter number in definition of \test). This does not seem to work when using pgfpages, but that is just another well-known bug in beamer (or pgfpages) with all hyperlinks.

#!latex
\documentclass[hyperref={pdfpagelabels=false}]{beamer}
\usepackage{ifpdf}
\usepackage{relsize}
\usepackage[authoryear,square]{natbib}
\bibliographystyle{abbrvnat}

%% FIXME: This is not an optimal solution because starred versions cannot be
%% easily overriden, thus we need the xxxfull variants.  Optional parameters
%% don't work? It also requires to add manually every cite variant.
\let\beameroldcite=\cite
\renewcommand\cite[1]{\hyperlink{#1}{\beameroldcite{#1`
\let\beameroldcitet=\citet
\renewcommand\citet[1]{\hyperlink{#1}{\beameroldcitet{#1`
\newcommand\citetfull[1]{\hyperlink{#1}{\beameroldcitet*{#1`
\let\beameroldcitep=\citep
\renewcommand\citep[1]{\hyperlink{#1}{\beameroldcitep{#1`
\newcommand\citepfull[1]{\hyperlink{#1}{\beameroldcitep*{#1`
\let\beameroldciteyear=\citeyear
\renewcommand\citeyear[1]{\hyperlink{#1}{\beameroldciteyear{#1`
\let\beameroldciteauthor=\citeauthor
\renewcommand\citeauthor[1]{\hyperlink{#1}{\beameroldciteauthor{#1`
\let\beameroldcitepalias=\citepalias
\renewcommand\citepalias[1]{\hyperlink{#1}{\beameroldcitepalias{#1`
\newcommand{\citepsmall}[1]{{\smaller\citep{#1`
\newcommand{\citepsmallfull}[1]{{\smaller\citepfull{#1`
\newcommand{\citeptitle}[1]{\hfill{\smaller[2]\citep{#1`

\let\beameroldbibitem=\bibitem
\renewcommand{\bibitem}[2][]{\label{#2}\beameroldbibitem[#1]{#2}}
\providecommand{\newblock}{}

\title{Issue 114: hyperlinks do not work with natbib citations (hyperref)
}
\author{Manuel Lopez-Ibanez}
\titlegraphic{}%

\begin{document}

\begin{frame}[b,plain]
\vfill\vfill
\titlepage
\vfill
\end{frame}

\begin{frame}[t]
\frametitle{a}
\begin{itemize}
\item \citet{LopPaqStu2010:eaftools}
\item \citetfull{LopPaqStu2010:eaftools}
\item \citepfull{LopPaqStu2010:eaftools}
\item \citeyear{LopPaqStu2010:eaftools}
 \item \citeauthor{LopPaqStu2010:eaftools}
 \item \citepsmall{FonPaqLop06:hypervolume}
\end{itemize}
\end{frame}

\begin{frame}[t,allowframebreaks]
\frametitle{References}
\begin{smaller}[3]
\bibliography{test}
\end{smaller}
\end{frame}

\end{document}

%%%%%%%%%%%%%%% test.bib:
@incollection{FonPaqLop06:hypervolume,
  address = {Piscataway, NJ},
  publisher = {IEEE Press},
  month = jul,
  year = 2006,
  booktitle = {Proceedings of the 2006 Congress on Evolutionary
                  Computation (CEC 2006)},
  author = { Carlos M. Fonseca  and  Lu{\'i}s Paquete  and  Manuel L{\'o}pez-Ib{\'a}{\~n}ez },
  title = {An improved dimension\hspace{0pt}-\hspace{0pt}sweep
                  algorithm for the hypervolume indicator},
  pages = {1157--1163},
  doi = {10.1109/CEC.2006.1688440},
}

@misc{LopPaqStu2010:eaftools,
  author = { Manuel L{\'o}pez-Ib{\'a}{\~n}ez  and  Lu{\'i}s Paquete  and  Thomas St{\"u}tzle },
  title = {{EAF} Graphical Tools},
  year = 2010,
  url = {http://lopez-ibanez.eu/eaftools},
  note = {These tools are described in the book chapter
                  ``\emph{Exploratory analysis of stochastic local
                  search algorithms in biobjective
                  optimization}''. Please cite
                  the book chapter, not this.}
}
josephwright commented 8 years ago

Original comment by Halil Şen (Bitbucket: halilsen, GitHub: halilsen):


It seems that this workaround does not work anymore. More precisely, all the citations are hyperlinked to the title page (as if the label is created there...). Maybe \renewcommand{\bibitem}[2][]{\label{#2}\beameroldbibitem[#1]{#2}} does not work as expected...

josephwright commented 8 years ago

Original comment by manulopezibanez (Bitbucket: manulopezibanez, GitHub: Unknown):


A more complete work-around:

#!latex
%% FIXME: This is not an optimal solution because starred versions cannot be
%% easily overriden, thus we need the xxxfull variants.  Optional parameters
%% don't work? It also requires to add manually every cite variant.
\let\beameroldcite=\cite
\renewcommand\cite[1]{\hyperref{#1}{\beameroldcite{#1`
\let\beameroldcitet=\citet
\renewcommand\citet[1]{\hyperref{#1}{\beameroldcitet{#1`
\newcommand\citetfull[1]{\hyperref{#1}{\beameroldcitet*{#1`
\let\beameroldcitep=\citep
\renewcommand\citep[1]{\hyperlink{#1}{\beameroldcitep{#1`
\newcommand\citepfull[1]{\hyperlink{#1}{\beameroldcitep*{#1`
\let\beameroldciteyear=\citeyear
\renewcommand\citeyear[1]{\hyperref{#1}{\beameroldciteyear{#1`
\let\beameroldciteauthor=\citeauthor
\renewcommand\citeauthor[1]{\hyperref{#1}{\beameroldciteauthor{#1`
\let\beameroldcitepalias=\citepalias
\renewcommand\citepalias[1]{\hyperref{#1}{\beameroldcitepalias{#1`
\newcommand{\citepsmall}[1]{{\smaller\citep{#1`
\newcommand{\citepsmallfull}[1]{{\smaller\citepfull{#1`
\newcommand{\citeptitle}[1]{\hfill{\smaller[2]\citep{#1`

\let\beameroldbibitem=\bibitem
\renewcommand{\bibitem}[2][]{\label{#2}\beameroldbibitem[#1]{#2}}
\providecommand{\newblock}{}
josephwright commented 13 years ago

Original comment by manulopezibanez (Bitbucket: manulopezibanez, GitHub: Unknown):


Fix formatting:

#!latex
\let\oldbibitem=\bibitem
\renewcommand{\bibitem}[2][]{\label{#2}\oldbibitem[#1]{#2}}
\let\oldcite=\cite
\renewcommand\cite[1]{\hyperlink{#1}{\oldcite{#1}}}
\let\oldcitep=\citep
\renewcommand\citep[1]{\hyperlink{#1}{\oldcitep{#1}}}
\let\oldciteauthor=\citeauthor
\renewcommand\citeauthor[1]{\hyperlink{#1}{\oldciteauthor{#1}}} 
josephwright commented 13 years ago

Original comment by Vedran Miletić (Bitbucket: rivanvx, GitHub: Unknown):


Joseph, are you willing to take this?

josephwright commented 7 years ago

I guess this is a significant issue for some people: I'll log it for the next release.