5
\documentclass[french]{book}
\usepackage[french]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}

\begin{document}
{

\newtheorem{theorem}{Théorème}
\newtheorem*{theorem*}{Théorème}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{corollary}[theorem]{Corollaire}
\newtheorem{lemma}[theorem]{Lemme}

\chapter{Pomme}
Bonjour
\begin{theorem}
Si alors
\end{theorem}

Bonjour
\begin{theorem*}
Ssi
\end{theorem*}

\begin{theorem}
$\Rightarrow$
\end{theorem}



\chapter{Banane}
\begin{corollary}
Donc
\end{corollary}

\begin{lemma}
Ainsi
\end{lemma}

\chapter*{Théorèmes}
%Reprint all the theorems here

\end{document}

How can I print all the theorems a second time?

Sophie
  • 51
  • 3
  • 1
    You have to use \newtheoremx, not \newtheorem. However, the code doesn't cope with unnumbered theorems. A new version for this will appear shortly. – egreg Mar 23 '19 at 21:14
  • 1
    The new version is online – egreg Mar 23 '19 at 21:26
  • 1
    You need to use the first solution. – egreg Mar 23 '19 at 23:30
  • This is a duplicate of https://tex.stackexchange.com/questions/474089/ I can't close it any longer, it was wrong to reopen it in the first place, because porting the code is straightforward. – egreg Mar 24 '19 at 15:34

1 Answers1

3

Using the code in https://tex.stackexchange.com/a/474095/4427 (amended)

\documentclass[a4paper]{book}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}

\usepackage{amsmath} \usepackage{amsthm} \usepackage{exercise}

\ExplSyntaxOn

\NewDocumentCommand{\newtheoremx}{smomo} { \IfBooleanTF{#1} { \printthm_nonumber:nn { #2 } { #4 } } { \printthm_number:nnnn { #2 } { #3 } { #4 } { #5 } } }

\cs_new_protected:Nn \printthm_nonumber:nn { \newtheorem{#1@inner}{#2} \NewDocumentEnvironment{#1}{o+b} { % start the inner environment (without or with optional argument) \tl_if_novalue:nTF { ##1 } { \begin{#1@inner} } { \begin{#1@inner}[##1] } % typeset the statement ##2 % end the inner environment \end{#1@inner} % store the statement in a sequence variable, actually as % four arguments as shown \seq_gput_right:Nx \g_riccardo_theorems_seq { { #1 } % name { } % number \tl_if_novalue:nF { ##1 } { [\exp_not:n {##1}] } % attribution { \exp_not:n { ##2 } } % body } }{} }

\cs_new_protected:Nn \printthm_number:nnnn { % * Let's duplicate the working of \newtheorem; \newtheoremx should % be used for theorems that need to be listed % * \newtheoremx{theorem}{Theorem} will actually do % \newtheorem{theorem@inner}{Theorem} (honoring the usual optional arguments) % * We also need a property list to store along with the theorem % the one which it is subordinate to \tl_if_novalue:nTF { #2 } { \tl_if_novalue:nTF { #4 } { \newtheorem{#1@inner}{#3} } { \newtheorem{#1@inner}{#3}[#4] } % #1 is not subordinate, store the name itself \prop_gput:Nnn \g_riccardo_theorems_prop { #1 } { #1 } \seq_gput_right:Nn \g_riccardo_theorems_counters_seq { #1 } } { \newtheorem{#1@inner}[#2@inner]{#3} % #1 is subordinate to #2 \prop_gput:Nnn \g_riccardo_theorems_prop { #1 } { #2 } } % define a "grabbing" environment #1 with the usual features \NewDocumentEnvironment{#1}{o+b} { % start the inner environment (without or with optional argument) \tl_if_novalue:nTF { ##1 } { \begin{#1@inner} } { \begin{#1@inner}[##1] } % save the statement number \tl_gset:Nx \g__riccardo_theorems_number_tl { \use:c {@currentlabel} } % typeset the statement ##2 % end the inner environment \end{#1@inner} % store the statement in a sequence variable, actually as % four arguments as shown \seq_gput_right:Nx \g_riccardo_theorems_seq { { #1 } % name { \g__riccardo_theorems_number_tl } % number \IfValueT{##1}{ [\exp_not:n { ##1 }] } % attribution { \exp_not:n { ##2 } } % body } }{} }

% allocate the needed variables \prop_new:N \g_riccardo_theorems_prop \seq_new:N \g_riccardo_theorems_seq \tl_new:N \g__riccardo_theorems_number_tl \iow_new:N \g_riccardo_theorems_stream \seq_new:N \g_riccardo_theorems_counters_seq

% print the stored theorems \NewDocumentCommand{\printtheorems}{} { % we need a group where nullifying the action of \label \group_begin: \cs_set_eq:NN \label \use_none:n % map the sequence, passing each item to the function that prints a theorem \file_if_exist_input:n { \c_sys_jobname_str.thl } % end the group \group_end: \seq_map_inline:Nn \g_riccardo_theorems_counters_seq { \setcounter{##1@inner}{0} } }

\cs_new_protected:Nn \riccardo_theorems_save: { \seq_map_function:NN \g_riccardo_theorems_seq __riccardo_theorems_save:n } \cs_new_protected:Nn __riccardo_theorems_save:n { \iow_now:Nn \g_riccardo_theorems_stream { \savedtheorem #1 } } \AtEndDocument { \iow_open:Nn \g_riccardo_theorems_stream { \c_sys_jobname_str.thl } \riccardo_theorems_save: \iow_close:N \g_riccardo_theorems_stream }

\NewDocumentCommand{\savedtheorem}{smmom} { % redefine \the<statement>@inner to yield the stored number % we use the property list to use the correct counter % (for instance, in case of "lemma", <statement> will be "theorem" \IfBooleanTF{#1} { \IfNoValueTF{#4} {\begin{#2@inner}#5\end{#2@inner}} {\begin{#2@inner}[#4]#5\end{#2@inner}} } { \cs_set:cpn { the \prop_item:Nn \g_riccardo_theorems_prop {#2} @inner } { #3 } \IfNoValueTF{#4} { % no attribution \begin{#2@inner} #5 \end{#2@inner} } { % attribution \begin{#2@inner}[#4] #5 \end{#2@inner} } } }

\ExplSyntaxOff

\newtheoremx{theorem}{Théorème}[chapter] \newtheoremx{theorem}{Théorème} \newtheoremx{proposition}[theorem]{Proposition} \newtheoremx{corollary}[theorem]{Corollaire} \newtheoremx{lemma}[theorem]{Lemme}

\begin{document}

\chapter{Pomme} Bonjour \begin{theorem} Si alors \end{theorem}

Bonjour \begin{theorem} Ssi \end{theorem}

\begin{theorem}[Attribution] $\Rightarrow$ \end{theorem}

\chapter{Banane} \begin{corollary} Donc \end{corollary}

\begin{lemma} Ainsi \end{lemma}

\begin{Exercise}[difficulty=2] \begin{theorem}[Théorème de Steiner]Whatever.\end{theorem} \end{Exercise}

\chapter*{Théorèmes}

\printtheorems

\end{document}

The last page:

enter image description here

egreg
  • 1,121,712