# How to gather tcolorboxes at the end of a document

I want to add remarks at different places in a document, using tcolorbox (which I found a very nice package) and at the end of the document to get a compilation of all the remarks added along the document. Here is my MWE :

\documentclass[french]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,amsbsy,thmtools} % thmtools pour list of theorem
\usepackage[a4paper,
vmargin=2cm,
hmargin=2.5cm]{geometry}
\usepackage{xcolor}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\usepackage{babel}

\renewcommand\familydefault{\sfdefault}

\newtcbtheorem[]{rema}{Remarque}%
{colback=white,colframe=gray!50,fonttitle=\bfseries,
enhanced,
coltitle=gray!75!black,
attach boxed title to top left={xshift=2ex,yshift=-2mm,yshifttext=-1mm},
boxed title style={colframe=red!50,colback=gray!25},
code=\bfseries
}{th}

\title{Comment faire une liste de remarques}
\author{}
\date{}
\begin{document}
\maketitle

\vspace{-1cm}

\noindent
\section*{Bla}
\lipsum[1]
\begin{rema}{}{foo}
\lipsum[2]
\end{rema}

\section*{Bli}
\lipsum[3]
\begin{rema}{}{bar}
\lipsum[4]
\end{rema}

\section*{Liste des remarques}
%\listofremarks% to be defined
%\setcounter{\therema}{0} % not working
\begin{rema}{}{foo}
\lipsum[2]
\end{rema}

\begin{rema}{}{bar}
\lipsum[4]
\end{rema}

\end{document}


What I would like to get is :

1) preferably some kind of command like \listofremarks' which could list at the very end of the document all the remarks introduced previously, if this is possible.

2) if not possible, I could eventually add the remarks manually at the end of the document, but I would need to reset the remark counter to 0 and I did not found how to do this (I did not found the name of the counter involved).

I browsed through section 15.Theorem of the tcolorbox manual but did not found a satisfying solution.

EDIT: What I want is not exactly a list, it is a rather an extensive compilation of all the remarks of the document

EDIT2: Title changed (boxes, not list of boxes) and also the question slightly edited for a better explanation of the goal

• Restate theorem in separate file might be a good starting point. If I'm understanding correctly that you want to restate all the theorems at the end? – Troy Aug 23 '18 at 16:30
• If we closed this too quickly and @Troy 's suggestion is a better solution, please leave a comment and we can add that question to the duplicate list or reopen the question. – Alan Munn Aug 23 '18 at 16:52
• @Troy, thanks for your suggestion. Indeed using some kind of savebox is probably a good starting point, I will try to use it. However, since I got more than one box to restate, I still need to know the name of the counter involved. I'll have to dig into tcolorbox code unless somebody already had to use this name. – DRi Aug 24 '18 at 6:38
• @Alan Munn, Could you please re-open this question since what I want is not covered by How to create a list of tcbtheorems, it is in fact not a list , but rather a compilation of the theorem, box, etc... Moreover, using @Troy suggestion, I came up to an answer which I would like to share. Thanks – DRi Aug 24 '18 at 10:21

Following @Troy's comment, I started from this question Restate theorem in separate file and adapted it to my need.

The trick lies in the use of the xr package (which I discovered) and of an external document where the contents of the boxes is stored. The only difference being that the "saving" and the "compilation" of the boxes is done in the same file in the present case.

Here is my working MWE:

\documentclass[french]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,amsbsy}
\usepackage[a4paper,
vmargin=2cm,
hmargin=2.5cm]{geometry}
\usepackage{xcolor}
\usepackage[many]{tcolorbox}
\usepackage{lipsum}
\usepackage{xr}
\externaldocument{test-list-remark}% external file where the boxes are stored
\usepackage{babel}

\renewcommand\familydefault{\sfdefault}

\newtcbtheorem[list inside=rema]{rema}% name      Formatting each individual box
{Remarque}% display name
{colback=white,colframe=gray!50,fonttitle=\bfseries,
enhanced,
title={Remark~\thetcbcounter:},
label={rema@\thetcbcounter},
coltitle=gray!75!black,
attach boxed title to top left={xshift=2ex,yshift=-2mm,yshifttext=-1mm},
boxed title style={colframe=red!50,colback=gray!25},
code=\bfseries,
saveto=remas/rema-\thetcbcounter.tex,
record={\string\compilelement{\thetcbcounter}{remas/rema-\thetcbcounter.tex}},
#1}% options
{th}% prefix

\NewTotalTColorBox{\compilelement}{mm}{% The TotalBox where all the boxes are put
colback=white,colframe=gray!50,fonttitle=\bfseries,
enhanced,
coltitle=gray!75!black,
attach boxed title to top left={xshift=2ex,yshift=-2mm,yshifttext=-1mm},
boxed title style={colframe=red!50,colback=gray!25},
code=\bfseries,
title={Remarque~\ref{rema@#1}},
}{\input{#2}}

\title{Comment faire une liste de remarques}
\author{}
\date{}
\begin{document}
\maketitle

\vspace{-1cm}

\noindent
\tcbstartrecording % pretty obvious
\section*{Bla}
\lipsum[1]
\begin{rema}{}{foo} %
\lipsum[2]
\end{rema}

\section*{Bli}
\lipsum[3]
\begin{rema}{}{bar} %
\lipsum[4]
\end{rema}
\tcbstoprecording % idem

% this line is not necessary, since it is not what I wanted
\tcblistof[\section*]{rema}{Liste des remarques}
% I leave it however, someone may find it useful

\section*{Compilation des remarques}
\tcbinputrecords[test-list-remark.records]% to display the compilation of boxes

\end{document}
`

I hope this answer may be useful to someone.