[Tex/LaTex] How to fix the beamer and amsthm conflict

amsthmbeamer

I want to have a style of Theorem 1, and the next one is Theorem 1' with the help of Amsthm package.

The following code seems alright, but can't be compiled:

\documentclass{beamer}

\newtheorem{mthm}{Theorem}
\newtheorem{thm}{Theorem}
\renewcommand{\themthm}{\ref{thm:1}'}

\begin{document}
\begin{frame}
  \begin{thm}\label{thm:1}
  test
  \end{thm}
  \begin{mthm}
    test
  \end{mthm}
\end{frame}
\end{document} 

The err. log is :

! Missing \endcsname inserted.
<to be read again> 
                   \csname\endcsname
l.16 \end{frame}

? 
! Emergency stop.
<to be read again> 
                   \csname\endcsname
l.16 \end{frame}

I find the err cased by the \renewcommand{\themthm}{\ref{thm:1}'} line but how to fix this?

Best Answer

First possibility: non-shared counters

\documentclass{beamer}

\setbeamertemplate{theorems}[numbered]
\newtheorem{thm}{Theorem}
\newtheorem{mthm}{Theorem}
\renewcommand{\themthm}{\arabic{mthm}'}

\begin{document}
\begin{frame}
  \begin{thm}\label{thm:1}
  test
  \end{thm}
  \begin{thm}\label{thm:2}
  test
  \end{thm}
  \begin{mthm}
    test
  \end{mthm}
  \begin{thm}\label{thm:3}
  test
  \end{thm}
\end{frame}
\end{document} 

Output

enter image description here

Second possibility: shared counters

\documentclass{beamer}

\setbeamertemplate{theorems}[numbered]
\newtheorem{thm}{Theorem}
\newtheorem{mthm}[thm]{Theorem}

\usepackage{etoolbox}
\AtBeginEnvironment{mthm}{\addtocounter{thm}{-1}\renewcommand{\thethm}{\arabic{thm}'}}

\begin{document}
\begin{frame}
  \begin{thm}\label{thm:1}
  test
  \end{thm}
  \begin{thm}\label{thm:2}
  test
  \end{thm}
  \begin{mthm}
    test
  \end{mthm}
  \begin{thm}\label{thm:3}
  test
  \end{thm}
\end{frame}
\end{document} 

enter image description here


amsthm is not needed, but loading it, it doesn't cause any conflict.

Related Question