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

1

1 Answer 1

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

4
  • +1 -- Works well. Maybe somebody knows a solution which isn't cumbersome ;-) Commented Sep 6, 2011 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
    Commented Sep 6, 2011 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. Commented Sep 6, 2011 at 13:47
  • I've added another answer to that question
    – egreg
    Commented Sep 6, 2011 at 14:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .