I am currently trying to create subtheorems that are linkable. I referenced the code put forth by another post, here: How do I get sub-numbering for theorems (Theorem 1.A., Theorem 1.B., Theorem 2.)?
I have tried to adapt it to numbering using the following code but it seemst o link to a theorem before the one inside the subtheorem environment. I am wondering if there is perhaps a fix to this. For example, running the code below and linking to Theorem 2A leads to Theorem 1 instead. Any help would be greatly appreciated. Thank you.
\documentclass{article}
\usepackage[linktoc=page,colorlinks,linkcolor=blue,citecolor=blue,urlcolor=blue]{hyperref}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}
\makeatletter
\newenvironment{subtheorem}[1]{%
\def\subtheoremcounter{#1}%
\refstepcounter{#1}%
\protected@edef\theparentnumber{\csname the#1\endcsname}%
\setcounter{parentnumber}{\value{#1}}%
\setcounter{#1}{0}%
\expandafter\def\csname the#1\endcsname{\theparentnumber.\Alph{#1}}%
\ignorespaces
}{%
\setcounter{\subtheoremcounter}{\value{parentnumber}}%
\ignorespacesafterend
}
\makeatother
\newcounter{parentnumber}
% - - environments
\newtheorem{thm}{Theorem}
\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}
\begin{document}
\begin{thm}\label{thm:one}
One
\end{thm}
\begin{subtheorem}{thm}\label{thm:two}
\begin{thm}\label{thm:twoA}
Two, first part
\end{thm}
\begin{thm}\label{thm:twoB}
Two, second part
\end{thm}
\end{subtheorem}
\begin{thm}\label{thm:three}
Three
\end{thm}
\ref{thm:one}, \ref{thm:two}, \ref{thm:twoA}, \ref{thm:twoB}, \ref{thm:three}.
\end{document}
