\autoref from hyperref not showing correct theorem label

I am writing some lecture notes for a course on overleaf.

\documentclass[a4paper,11pt,openany]{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,amssymb,amsthm}

\theoremstyle{definition}
\newtheorem{theorem}{Theorem}[chapter]
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{example}[theorem]{Example}
\newtheorem*{notation}{Notation}
\newtheorem*{note}{Note}
\newtheorem*{solution}{Solution}

\def\bse{\begin{equation*}}
\def\ese{\end{equation*}}
\def\bp{\begin{proposition}}
\def\ep{\end{proposition}}
\def\bt{\begin{theorem}}
\def\et{\end{theorem}}

\begin{document}

%some text

\bt
\label{t:theorem_bla}
bla
\et

\bp
\label{p:deg}
Let $K\ss L$ be fields and let $\a \in L$ be algebraic over $K$. Then:
\bse
[K(\a):K]=\deg P_{min}(\a,K) \, .
\ese
\ep

%some more text

Hence, by \autoref{p:deg}, we have:

%even more text

\end{document}


I just recently found out about the \autoref command provided by the hyperref package. Quite pleased with it, it worked fine showing the correct label for my custom theorem environments (lemmas, prepositions, etc.). However, I realised that at some point all the labels appeared as "Theorem" instead. I don't recall making any changes to the preamble in that short amount of time. Also, I have read this question: How to get correct autoref for theorems However, I didn't have \<name>autorefname in the preamble before and it worked... I have tried to compile it on my MiKTeX and I get the same output, so this doesn't seem to be related to Overleaf.

• \autoref detects the entity by the counter name in the anchor name of the reference. If different types of entities share the same counter, then \autoref cannot distinguish them. Packages like aliascnt might help to created different fake counters, which share the same counter, but make \autoref happy because of the different counter names. Of course, the new counter names needs support by \<name>autorefname. May 19 '16 at 17:15
• Please strip down the example on overleaf and post it here. Code on external sites might vanish at some time. May 19 '16 at 17:17

The problem arises because the theorem, corollary, definition, lemma, and proposition environments all share the same counter.

The quickest solution I can think of is to (a) add the instruction

\usepackage[noabbrev,capitalize]{cleveref}


after loading the hyperref package and (b) replace all instances of \autoref with \cref.

Aside: I can't help but remark that your document suffers from a gross overuse of \left and \right to autosize the "fence symbols" (parentheses, brackets, etc.). In many cases I've looked at, omitting the \left and \right instructions would definitely be the (typographically) correct thing to do.

• Thank you for your answer, and thanks for the remark as well. May I just ask for clarification, do you think I should remove (most of) the \left \right instructions? Is there a good reference that you can suggest about mathematical typography? May 19 '16 at 18:01
• @DemK. - I'd say you only time you need the non-default size of the fences in the document you've posted is when you're encasing a \sum... statement in parentheses in a display-math environment. In these cases, I'd use \biggl( and \biggr), as \left( and \right) would give you parentheses that are too large, typographically speaking. For an excellent introduction to mathematical typography using the TeX system, I can heartily recommend chapters 16 to 19 of The TeXbook by Don Knuth.
– Mico
May 19 '16 at 18:13
• Thank you very much for your tips and the recommendation. May 19 '16 at 18:35
• @DemK. - Do also replace all instances of _{min} with _{\min}, don't redefine \det, \diag, \gcd, and under no circumstance redefine \rm. (It's a good thing you don't actually use \rm in your document...)
– Mico
May 19 '16 at 18:37