[Tex/LaTex] \autoref from hyperref not showing correct theorem label

autorefhyperreflabels

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

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

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

Best Answer

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.

Related Question