I really like this question/answer ("patched theorem defintion" in the minimal example) and I wanted to adapt it to my custom dissertation class file. However, I ran into some problems with the package IEEEtrantools, which I "need" to typeset some math.
Originally, the definition of my theorems was placed inside the \AtEndPreamble hook, although I don't remember why, it worked together with IEEEtrantools. But if the above Q/A is applied inside the hook, the patch has no effect. If I put it outside the hook, IEEEtrantools causes errors.
I could try to avoid IEEEtrantools, but I prefer not to. So can you identify what is causing the problem and may offer a solution?
Thank you in advance!
MWE
\documentclass{scrbook}
\usepackage{etoolbox}
\usepackage{xpatch}
%\RequirePackage{IEEEtrantools} % <==== breaks patched theorem defintion
%% patched theorem defintion ==============
\usepackage{thmtools}
\usepackage{thm-restate}
\makeatletter
\xpatchcmd{\thmt@restatable}% Edit \thmt@restatable
{\csname #2@xa\endcsname\ifx@nx#1@nx\else[{#1}]\fi}% Replace this code
{\ifthmt@thisistheone\csname #2@xa\endcsname\ifx@nx#1@nx\else[{#1}]\fi\else\csname #2@xa\endcsname\fi}% with this code
{}{} % execute code for success/failure instances
\makeatother
%% ========================================
\AtEndPreamble{
\usepackage{hyperref}
\usepackage[sort&compress]{cleveref}
% <=== theorem definition could be moved here and originally was here, but then the patch does not work.
}
\newtheorem{thm}{Theorem}
\begin{document}
\section{Introduction}
\begin{restatable}[\S\ref{SectionNumber}]{thm}{TheoremName}
theorem contents
\end{restatable}
\section{Some Section}
\label{SectionNumber}
\TheoremName*
\end{document}