5

Using hyperref and beamer together, I encounter the following problem. Command \autoref which is supposed to add the name of the referenced item, does not work.

Here is a minimal example that demonstrates the problem

\PassOptionsToPackage{naturalnames}{hyperref}
\documentclass{beamer}
\usepackage[naturalnames]{hyperref}
\hypersetup{naturalnames}
\renewcommand{\sectionname}{Unit}
\begin{document}
  \section{My first section} \label{first}
  \begin{frame}
    See \autoref{second}.
  \end{frame}
  \section{My second section} \label{second}
  \begin{frame}
    See \autoref{first}.
  \end{frame}
\end{document}

Which produces the following output

enter image description here

enter image description here

Notice that that the name "Unit" does not appear in the generated reference.

2
  • I suspect the 'new' labelling system inside of beamer. It leaves no hook which can \autoref jump to. If one introduces a dummy counter foo and uses \refstepcounter and \label, \autoref, there is no warning about a missing autoref name for foo, which indicates that autoref is not in action at all
    – user31729
    Apr 25 '15 at 9:25
  • \usepackage{cleveref}\crefname{section}{Unit}{Units}; then \cref{first} will print Unit 1.
    – egreg
    Apr 25 '15 at 10:00
5

If we look at the .aux file generated by your code, we find

\newlabel{first}{{1}{1}{My first section}{Doc-Start}{}}

Removing the naturalnames will not cure the problem.

On the other hand, the document

\documentclass{article}
\usepackage{hyperref}
\renewcommand{\sectionautorefname}{Unit}

\begin{document}

\section{First}\label{first}

\autoref{first}

\end{document}

will produce

\newlabel{first}{{1}{1}{First}{section.1}{}}

in the .aux file and then print “Unit 1”.

Using cleveref seems much easier:

\documentclass{beamer}
\usepackage{cleveref}
\crefname{section}{Unit}{Units}

\begin{document}

\section{My first section}\label{first}

\begin{frame}

See \cref{first}.

\end{frame}

\end{document}

enter image description here

4
  • That's basically the same answer I wanted to add, but you were quicker. Nevertheless, I could backtrace the Doc-Start countername to \@currentHref{Doc-Start} within hyperref.sty, but I have no idea where it comes into action.
    – user31729
    Apr 25 '15 at 12:43
  • @ChristianHupfer It basically means that hyperref finds nothing better to hook to.
    – egreg
    Apr 25 '15 at 12:44
  • 1
    Well, I wonder, if this can be cured, however, your answer with cleveref is perhaps really the shortest and best way
    – user31729
    Apr 25 '15 at 12:47
  • Do note that the cleveref references aren't click-able (i.e.) it is plain text.
    – sotmot
    May 20 '21 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.