# \autoref does not seem to be working properly

\autoref does not seem to be working properly. Whenever I use it I only get the number and not the theorem/proposition/lemma e.t.c. I.e.,

It follows from \autoref{aaa}


comes up as

It follows from 1.1

and not

It follows from Theorem 1.1

• Check the log for a hyperref warning: "No autoref name for ...". Please provide a MWE (minimal working example), because there are millions of ways to define and use theorems. – Heiko Oberdiek Jul 23 '15 at 13:43

## 1 Answer

You have to tell \autoref the name to be used, using \<name>autorefname, where <name> is the name you used for your structure. A complete example:

\documentclass{article}
\usepackage{amsthm}
\usepackage{hyperref}

\newtheorem{ttt}{Theorem}
\providecommand*\tttautorefname{Theorem}

\begin{document}

\begin{ttt}
\label{aaa}
test
\end{ttt}
\autoref{aaa}

\end{document}


The result:

If you don't provide the name in the example above, hyperref will give you a warning:

Package hyperref Warning: No autoref name for ttt' on input line 14.


## Update

In case you have structures with shared counters, you need a little more work: the package aliascnt provides a method to generate a simulated second counter that allows the differentiation between those different structures sharing a counter. A little example:

\documentclass{article}
\usepackage{amsthm}
\usepackage{aliascnt}
\usepackage{hyperref}

\newtheorem{theo}{Theorem}
\newaliascnt{lemma}{theo}
\newtheorem{lemma}[lemma]{Lemma}
\aliascntresetthe{lemma}
\providecommand*{\theoautorefname}{Theorem}
\providecommand*{\lemmaautorefname}{Lemma}

\begin{document}

\begin{theo}
\label{aaa}
test
\end{theo}
\begin{lemma}
\label{bbb}
test
\end{lemma}
\autoref{aaa}\autoref{bbb}

\end{document}


Pay special attention to the lines

\newaliascnt{lemma}{theo}
\newtheorem{lemma}[lemma]{Lemma}
\aliascntresetthe{lemma}


notice, in particular, that for the lemma structure, the optional argument has the alias counter defined in the line just above, not the counter for theorems.

Using cleveref might be an easier option:

\documentclass{article}
\usepackage{amsthm}
\usepackage{hyperref}
\usepackage{cleveref}

\newtheorem{theo}{Theorem}
\newtheorem{lemma}[theo]{Lemma}

\begin{document}

\begin{theo}
\label{aaa}
test
\end{theo}
\begin{lemma}
\label{bbb}
test
\end{lemma}
\Cref{aaa}\Cref{bbb}

\cref{aaa}\cref{bbb}

\end{document}


• What happens if I want to work with Theorems/Propositions/Lemmas etc? Right now it changes everything to Theorem a.b. Even when I write \newtheorem{prop}[thm]{Proposition} \providecommand*\propautorefname{Proposition} – user82130 Jul 23 '15 at 15:22
• I suppose it's because I have linked everything with thm. But If I take [thm] out then the numbering is no longer consecutive amongst all theorems/props/lemmas – user82130 Jul 23 '15 at 15:31
• @user82130 In those cases, you have to provide aliases for the counters. See my updated answer for an example. Perhaps you could consider changing to cleveref` (as I also mentioned and exemplified in the update). – Gonzalo Medina Jul 23 '15 at 15:41