4

I am using a new command to give theorems the name that I want in Beamer, but it won't let me use \pause. The following code works without the \pause, but this error with \pause:

! LaTeX Error: Command \NewThm already defined.  
               Or name \end... illegal, see p.192 of the manual.

What can I do to be able to give theorems the name that I want and to be able to use \pause?

\documentclass{beamer}   
\usefonttheme{professionalfonts}   
\usetheme{Warsaw}

\newcommand\thm[2]{%
  \newtheorem*{#1}{#2}%
  \AtBeginEnvironment{#1}{%
     \setbeamercolor{block body}{}%
  }%
}

\begin{document}   
\begin{frame}    
Text \pause  
\thm{NewThm}{Theorem's Name}   
\begin{NewThm}
Statement.
\end{NewThm}    
\end{frame}
\end{document}

enter image description here

1
  • @cfr Thanks, I added the error
    – Twink
    Nov 29, 2023 at 4:30

1 Answer 1

5

You're getting an error because you are declaring a new theorem twice with the same name, which isn't allowed.

! LaTeX Error: Command \NewThm already defined.
               Or name \end... illegal, see p.192 of the manual.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.682 \end{frame}
                 
? 

This is because it is executed on each slide of the frame. Without \pause, it runs once. With, it runs twice.

The best solution in almost all cases is to declare new commands and environments in the preamble. This makes them easier to manage and errors simpler to find. The occasions when you really need to do this kind of thing are the exception rather than the rule.

The are various ways of dealing with the exceptions. They each have advantages and disadvantages. You could test if the environment is already defined or you could use some form of \provide. Or you could make the definition overlay-specific.

Note that I absolutely do not recommend this in this case. There is no reason you cannot declare this theorem in your preamble.

\documentclass{beamer}

\usefonttheme{professionalfonts}

\usetheme{Warsaw}


\newcommand\thm[2]{%
  \newtheorem*{#1}{#2}%
  \AtBeginEnvironment{#1}{%
     \setbeamercolor{block body}{}%
  }%
}

\thm{NewThm}{Theorem's Name}

\begin{document}

\begin{frame}

Text \pause

% \only<1>{% possible, but not recommended
%   \thm{NewThm}{Theorem's Name}%
% }

\begin{NewThm}

Statement.

\end{NewThm}

\end{frame}

\end{document}

You also might want to read up on Beamer's support for defining overlay-aware custom commands and environments, since that gives you greater flexibility. (But not worth it for a single frame in most cases.)

You must log in to answer this question.

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