1. Vedran Miletić
  2. beamer
  3. Issues
Issue #114 open

hyperlinks do not work with natbib citations (hyperref)

Anonymous created an issue

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.

Comments (6)

  1. manulopezibanez

    Fix formatting:

    \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}}} 
    
  2. manulopezibanez

    A more complete work-around:

    %% 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}{}
    
  3. Halil Şen

    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...

  4. manulopezibanez

    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.

    \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.}
    }
    
  5. Log in to comment