TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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}

What is the easiest way to go about this?

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.

share|improve this question
    
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
1  
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? – benwilfut Mar 18 '13 at 8:12
up vote 7 down vote accepted

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}

enter image description here

share|improve this answer

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}
share|improve this answer
    
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 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 at 20:10
    
Well, if people define 100 macros in their "preamble file" and then use 5 of them in the article, it's anything but convenient. (btw, I am involved in journal typesetting...) – yo' Feb 27 at 20:16
1  
@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 at 17:18
    
@antonio Can your trick be made to work with \newtheorem*{thm*} ? – Paulo Ney Apr 26 at 6:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.