Take the 2-minute tour ×
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.

I am attempting to make an environment out of the command given in one of the answers to this question: Customizing theorem name.

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

\newenvironment{namedtheorem}[1]{
\theoremstyle{definition}
   \newtheorem*{thmTemp}{#1}
\begin{thmTemp}}{\end{thmTemp}}

\begin{document}

\begin{namedtheorem}{foo}
    This is a named theorem bar.
\end{namedtheorem}

\begin{namedtheorem}{bar}
    This is a named theorem bar.
\end{namedtheorem}

\end{document}

Unfortunately, my invocation of \newtheorem*{thmTemp}{#1} seems to be scoping beyond the current environment, causing an error when the environment is used a second time.

How can I fix my environment to avoid this problem?

share|improve this question
    
You could use \renewtheorem from the ntheorem package. –  Peter Grill Mar 18 '13 at 6:19
add comment

1 Answer

As far as I can see, Andrew Stacey's answer to your other question is providing you with an environment for these named theorems. The only difference from your request, is that the name is an optional argument. Using his code, we can define a new environment, where the name is required, by using the result of his definition and providing the argument:

\newenvironment{namedtheorem}[1]{\begin{internalnamedtheorem}[#1]}{\end{internalnamedtheorem}}

This way, we move the \newtheorem command out of the environment definition. This is close to a common (La)TeX coding idiom, when main commands are defined in terms of other secondary commands.

Sample output

\documentclass{article}

\usepackage{amsthm}

\newtheorem*{theorem}{Theorem}

\newtheoremstyle{named}{}{}{\itshape}{}{\bfseries}{.}{.5em}{\thmnote{#3's }#1}
\theoremstyle{named}
\newtheorem*{internalnamedtheorem}{Theorem}

\newenvironment{namedtheorem}[1]{\begin{internalnamedtheorem}[#1]}{\end{internalnamedtheorem}}

\begin{document}

\noindent
Standard naming.

\begin{theorem}[Euclid]
  There are infinitely many primes.
\end{theorem}

\noindent
New naming.

\begin{namedtheorem}{Euclid}
  There are infinitely many primes.
\end{namedtheorem}

\end{document}
share|improve this answer
add comment

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.