# Is there a \renewtheorem equivalent of \renewcommand, using amsthm and not ntheorem?

Suppose I have a theorem that is defined a certain way, as follows.

\newtheorem*{mytheorem}{Foo}


And I want to redefine it another way further down in my document, as below.

\newtheorem*{mytheorem}{Bar}


I would like something like this, but I get undefined control sequence on \renewtheorem.

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

\begin{document}
\theoremstyle{definition}
\newtheorem*{thmTemp}{Foo}
\begin{thmTemp} First one.  \end{thmTemp}

\renewtheorem*{thmTemp}{Bar}
\begin{thmTemp} Second one.  \end{thmTemp}
\end{document}


When I run pdflatex on this, I get the following:

! Undefined control sequence.
l.10     \renewtheorem
*{thmTemp}{Bar}


I am avoiding ntheorem because it does not preserve the theorem styles defined by amstheorem, even when the amsthm option is passed to it, and I would prefer not to redefine those styles.

• Have you tried \renewtheorem? It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. That way we would know which packages you are using as some solutions may be package specific. – Peter Grill Mar 18 '13 at 6:13
• Try replacing amsthm with ntheorem. – Peter Grill Mar 18 '13 at 6:22
• @PeterGrill, There's actually a specific reason I want to use amsthm and not ntheorem. I prefer not to redefine \theoremstyle{definition} among others. – merlin2011 Mar 18 '13 at 6:23
• And yes, I have tried the [amsthm] option to ntheorem, but it does not achieve the desired effect. – merlin2011 Mar 18 '13 at 6:23
• Perhaps it would help if you specified more closely what you mean by 'redefine it another way'... How do you expect the redefined theorem environment to behave? Do you simply want to change the heading and continue numbering with the previous counter? Or do you also want to change the style of the theorem? – bencarabelli Mar 18 '13 at 8:12

Rather than redefining the environment each time, I would define a wrapper:

\documentclass{article}
\usepackage{amsthm}
\theoremstyle{definition}
\newenvironment{defi}[1]
{\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}

• Please, do not tell me you submit papers using some sort of mymacros.tex. If you do, I truly hope I won't meet the papers. – yo' Feb 26 '16 at 22:30
• @yo': Hmm... sorry to disappoint you, but LaTeX most relevant feature is macros, which avoid repetitive typing. Putting all of them in the preamble, or even worse in the body of text, creates clutter and defeats the whole purpose of LaTeX being focused on content, rather than presentation. Anyway, unless you are involved publishing a journal, you are not supposed to read the sources producing the papers. P.S. in case you might be interested, I fixed a bug in the code. – antonio Feb 27 '16 at 20:10
• @yo' from your perspective, you are right. From the author perspective, you are absolutely wrong. But I understand that journal typesetting is the key part of Science. – Spherical Triangle Mar 1 '16 at 17:18
• @antonio Can your trick be made to work with \newtheorem*{thm*} ? – Paulo Ney Apr 26 '16 at 6:31
• Also, I know from experience that researchers who maintain a personal style file ends up with better (La)TeX code (easier to read, more accurate and elegant typesetting), which should in the end ease the work of publishers. The latter should actually take this into account before imposing class files loading packages known for conflicting with many others. – Hugo Raguet Feb 20 '18 at 3:02