Is there a \renewtheorem equivalent of \renewcommand, using amsthm and not ntheorem?
Rather than redefining the environment each time, I would define a wrapper:
\documentclass{article}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem*{inner}{\innerheader}
\newcommand{\innerheader}{}
\newenvironment{defi}[1]
{\renewcommand\innerheader{#1}\begin{inner}}
{\end{inner}}
\begin{document}
\begin{defi}{Foo}
First one.
\end{defi}
\begin{defi}{Bar}
Second one.
\end{defi}
\end{document}
If one systematically needs different theorems definitions in the same documents, egreg approach is convenient. But many of us might have a mymath.tex
with common shortcuts and settings, which is a very likely place for the \newtheorem
definitions, and occasionally one might want to override these definitions, e.g. to change the theorems' locale.
In these cases, editing mymath.tex
or mantaining a second one is inconvenient and prone to errors, much better to plug a new altthm.tex
in the main document overriding theorem definitions.
To this end, we need a \renewtheorem
command:
\makeatletter
\def\renewtheorem#1{%
\expandafter\let\csname#1\endcsname\relax
\expandafter\let\csname c@#1\endcsname\relax
\gdef\renewtheorem@envname{#1}
\renewtheorem@secpar
}
\def\renewtheorem@secpar{\@ifnextchar[{\renewtheorem@numberedlike}{\renewtheorem@nonumberedlike}}
\def\renewtheorem@numberedlike[#1]#2{\newtheorem{\renewtheorem@envname}[#1]{#2}}
\def\renewtheorem@nonumberedlike#1{
\def\renewtheorem@caption{#1}
\edef\renewtheorem@nowithin{\noexpand\newtheorem{\renewtheorem@envname}{\renewtheorem@caption}}
\renewtheorem@thirdpar
}
\def\renewtheorem@thirdpar{\@ifnextchar[{\renewtheorem@within}{\renewtheorem@nowithin}}
\def\renewtheorem@within[#1]{\renewtheorem@nowithin[#1]}
\makeatother
Use as the \renewtheorem
as the standard \newtheorem
:
\renewtheorem{env_name}{caption}[within]
\renewtheorem{env_name}[numbered_like]{caption}
It works with amsthm
.
The MWE, excluding the \renewtheorem
definition, is:
\documentclass{article}
\begin{document}
\newtheorem{thm}{Theorem}[section]
\begin{thm}
My theorem ...
\end{thm}
\renewtheorem{thm}{Proposition}[section]
\begin{thm}
My theorem ...
\end{thm}
\end{document}
Reducing @antonio's answer: you can get a more robust result with only the first block of code; instead of a \renewtheorem
, one can just as easily use a \cleartheorem
as below:
\makeatletter
\def\cleartheorem#1{%
\expandafter\let\csname#1\endcsname\relax
\expandafter\let\csname c@#1\endcsname\relax
}
\makeatother
In my view, the extra complexity and dependency on \newtheorem
(which precludes the use of re-defining a theorem with \declaretheorem
from thmtools
, and assumes additional things about the inner workings of the theorem package & its interface) is not justified over the extra line of code to get the desired effect:
% suppose you're using \declaretheorem
\usepackage{amsthm, thmtools}
% this could be included from a separate file
\declaretheorem[name=Definition,numberwithin=section]{defn}
\cleartheorem{defn}
\declaretheorem[name=RevisedDefinition]{defn} % no error here
Edit: for further convenience, one can clear all theorems with one command, so that there is no more than one line of redundant code:
% define this in the preamble in between \makeatletter and \makeatother
\def\clearthms#1{ \@for\tname:=#1\do{\cleartheorem\tname} }
Then in the document:
% clear the previous definitions
\clearthms{defn,example,theorem,coro,prop}
% now execute all of the commands exactly as if the preamble didn't have them...
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{coro}{Corollary}[theorem]
\newtheorem{prop}[theorem]{Proposition}
\theoremstyle{definition}
\newtheorem{defn}{Definition}{section}
\declaretheorem[qed=$\square$]{example}