1

I'm trying to number equations following theorem-like environments. So I write

\declaretheorem[name=Theorem,sibling=equation]{thm}

But then there are errors:

Command \@thm already defined.

No counter 'thm' defined.

\thm undefined.

However, even if I change my code to

\declaretheorem[name=Theorem,sibling=equation]{theorem}

or something other than "thm", the problem disappears.

I wonder why this happens?

Here is my sample:

\documentclass{article}
\usepackage{amsmath}
\usepackage{thmtools}

\numberwithin{equation}{section}

\declaretheorem[name=Theorem,sibling=equation]{thm}

\begin{document}
\section{MWS}
\begin{thm}
content
\end{thm}
\end{document}
Gau-Syu
  • 473
  • 1
    Congratulations! You found a bug in thmtools. I sent mail to the package author. – egreg Apr 15 '18 at 21:01
  • presumably you're using thmtools for a particular reason, so this may be irrelevant, but it's an alternate methos. using amsthm just specify your theorem objects this way: \newtheorem{thm}[equation]{Theorem}. – barbara beeton Apr 16 '18 at 01:17

1 Answers1

2

This exposes a nasty bug of thmtools. At line 59 of the auxiliary package aliasctr.sty we find

\@ifdefinable{c@#1}{%

as part of the definition of \@counteralias. It is a bad error, because \@ifdefinable expects a single token as its argument and havoc ensues if this part of the code is executed.

Solution:

\documentclass{article}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{etoolbox}

% fix the bug in aliasctr.sty
\makeatletter
\patchcmd{\@counteralias}
 {\@ifdefinable{c@#1}}
 {\expandafter\@ifdefinable\csname c@#1\endcsname}
 {}{}
\makeatother

\numberwithin{equation}{section}
\declaretheorem[
  name=Theorem,
  sibling=equation,
]{thm}


\begin{document}
\section{MWS}
\begin{thm}
content
\end{thm}
\begin{equation}
1=1
\end{equation}
\end{document}

enter image description here

egreg
  • 1,121,712