0

In the code below, I would like to store the number of theorems as there are formatted by amsmath. How can I do that ?

My code stores 1, 2, 3, 1 instead of 1.1, 1.1, 1.1, 2.1. In other cases the numbering could be different so I need to have access to the macro displaying the counter in the final PDF output.

\documentclass[12pt]{article}

\usepackage{amsthm}


\newwrite\tempscoresfile

\immediate\openout\tempscoresfile=\jobname.test
\AtEndDocument{\immediate\closeout\tempscoresfile}


\newtheorem{@theorem@}{Théorème}[section]

\newenvironment{theorem}[1][]{
    \begin{@theorem@}[#1]
    \immediate\write\tempscoresfile{\arabic{@theorem@}}
}{
    \end{@theorem@}
}


\begin{document}

\section{Section 1}

\begin{theorem} 
    Bla, blo, bli...
\end{theorem}

\begin{theorem} 
    Bla, blo, bli...
\end{theorem}

\begin{theorem} 
    Bla, blo, bli...
\end{theorem}


\section{Section 2}

\begin{theorem} 
    Bla, blo, bli...
\end{theorem}

\end{document}
projetmbc
  • 13,315

1 Answers1

1

Solution that uses the comment above of Werner.

\documentclass[12pt]{article}

\usepackage{amsthm}


\newwrite\tempscoresfile

\immediate\openout\tempscoresfile=\jobname.test
\AtEndDocument{\immediate\closeout\tempscoresfile}

\newcommand\storerefs{
    \immediate\write\tempscoresfile{\arabic{@theorem@}::\csname the@theorem@\endcsname}
}  

\newtheorem{@theorem@}{Théorème}[section]

\newenvironment{theorem}[1][]{
    \begin{@theorem@}[#1]
    \storerefs{}
}{
    \end{@theorem@}
}


\begin{document}

\section{Section 1}

\begin{theorem} 
    Bla, blo, bli...
\end{theorem}

\begin{theorem} 
    Bla, blo, bli...
\end{theorem}

\begin{theorem} 
    Bla, blo, bli...
\end{theorem}


\section{Section 2}

\setcounter{@theorem@}{0}
\begin{theorem} 
    Bla, blo, bli...
\end{theorem}

\end{document}
projetmbc
  • 13,315