josephwright / beamer

A LaTeX class for producing presentations and slides
Other
1.35k stars 139 forks source link

autoref and nameref seem not to work as exspected (i.e work like in article mode) #865

Open ouboub opened 8 months ago

ouboub commented 8 months ago

Hi

A while ago in issue 750 I wrote that cleverref and beamer do not work together well, but also found a sort of fix.

Now I am facing the same problem with autoref and nameref. I attach a minimal example and would appreciate any advice

\documentclass{beamer}
\usepackage[spanish]{babel}
\makeatletter
\Hy@AtBeginDocument{%
  \def\@pdfborder{0 0 1}% Overrides border definition set with colorlinks=true
  \def\@pdfborderstyle{/S/U/W 1}% Overrides border style set with colorlinks=true
                                % Hyperlink border style will be underline of width 1pt
}
\makeatother

\hypersetup{%
  colorlinks=true,% hyperlinks will be coloured
%  linkcolor=blue,% hyperlink text will be blue
  urlcolor=blue,% hyperlink text will be blue
%  linkbordercolor=red,% hyperlink border will be red
  urlbordercolor=red,% hyperlink border will be red
}
\usepackage{nameref}
\usepackage{thmtools}
\newtheorem{thm}{Theorem}
\begin{document}
\begin{frame}
  \frametitle{Equations are here}
  this is important
  \begin{equation}
    \label{eq:beamer-auto-nameref:1}
    \int f dx =0
  \end{equation}
\end{frame}
\begin{frame}
  \frametitle{Reference with autoref}
this is   \autoref{eq:beamer-auto-nameref:1}

But using eqref \eqref{eq:beamer-auto-nameref:1}
\end{frame}
\begin{frame}
  \frametitle{Now a theorem}
  \begin{thm}[Riemann's Hypothesis]
\label{thr:beamer-auto-nameref:1}
    Let 
  \end{thm}
\end{frame}

\begin{frame}
  \frametitle{Reference to the theorem}
\ref{thr:beamer-auto-nameref:1}

  Consider \autoref{thr:beamer-auto-nameref:1}

And \nameref{thr:beamer-auto-nameref:1}
\end{frame}
\end{document}

and the pdf file

beamer-auto-nameref.pdf

ouboub commented 7 months ago

Hi

I found a solution for the required functionality but it relies on cleveref, any comments are welcome.

regards

Uwe Brauer

 \documentclass{beamer}
 \hypersetup{colorlinks=true}
 \usepackage{nameref}
 \newtheorem{thm}{Theorem}
 \usepackage{cleveref}
 \Crefname{thm}{Theorem}{Theorems}
 % fix for cleverref
 \let\chyperref\cref % Save the orginal command under a new name
 \renewcommand{\cref}[1]{\hyperlink{#1}{\chyperref{#1}}} % Redefine the \cref command and explictely add the hyperlink. 
 %
 \newcommand*{\fullcleveref}[1]{%
   \hyperref[{#1}]{\Cref{#1} (\nameref*{#1})}%
 }
 \newcommand*{\hypercleveref}[1]{%
   \hyperref[{#1}]{\Cref{#1}}%
 }

 \begin{document}
 \begin{frame}
   \frametitle{Equations are here}
   this is important
   \begin{equation}
     \label{eq:beamer-auto-nameref:1}
     \int f dx =0
   \end{equation}
 \end{frame}

 \begin{frame}
   \frametitle{Now a theorem}
   \begin{thm}[Riemann's Hypothesis]
 \label{thr:beamer-auto-nameref:1}
     Let 
   \end{thm}
 \end{frame}

 \begin{frame}
   \frametitle{Reference to the theorem and the equation}

 \hypercleveref{eq:beamer-auto-nameref:1}
 \fullcleveref{thr:beamer-auto-nameref:1}
 \end{frame}
 \end{document}