1

In the example below you can see that both environments get the same caption.

How to prevent this? You will get the same result if you use an other package like amsthm, theorem or thmtools.

\setcounter{errorcontextlines}{999}
\documentclass{scrartcl}
\usepackage{ntheorem,xcolor}
\def\tempA{Game}
\newtheorem{game}{\color{red}\bfseries\tempA}
\def\tempA{Example}
\newtheorem{example}{\color{blue}\bfseries\tempA}
\begin{document}

\begin{example}
Test
\end{example}

\vspace*{2em}

\begin{game}
Test
\end{game}
\end{document}

enter image description here

2

Of course: the second \def overrides the meaning of the first one: \tempA is expanded only when \begin{game} and \begin{example} are used, not when defined. At that time, \tempA expands to Example.

\def\tempA{Game}
\begingroup
\edef\x{\endgroup
  \noexpand\newtheorem{game}{\noexpand\color{red}\noexpand\bfseries\tempA}}
\x
\def\tempA{Example}
\begingroup
\edef\x{\endgroup
  \noexpand\newtheorem{example}{\noexpand\color{red}\noexpand\bfseries\tempA}}
\x

will do, but it's rather cumbersome

| improve this answer | |
  • +1 -- Works well. Maybe somebody knows a solution which isn't cumbersome ;-) – Marco Daniel Sep 6 '11 at 13:31
  • 2
    Please, be more specific about your problem; in the shown form it's quite easy: write Game and Example instead of \tempA in the definitions. – egreg Sep 6 '11 at 13:43
  • Yes that is true ;-) -- The problem base on this question: Own command to create new environment. I used this answer for my package but this simple question demonstrate my bug. – Marco Daniel Sep 6 '11 at 13:47
  • I've added another answer to that question – egreg Sep 6 '11 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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