[Tex/LaTex] Force all floats to the end of the document without using endfloat

floatshookspositioning

What is the easiest way to have all floats forcibly appear at the end of the document, one per page? The endfloat package is not an option, see below.
The following questions are related but not helpful:

How to place all floats (tables in particular) at a certain point in the document

Place all floats last without changing numbering

Details

In our environment we have wrappers for creating figures, tables etc.. The wrappers are implemented as environments to allow "everything" inside and furthermore accept, among others, the long and short caption name, the label and the contens of the figure. The implementation of the wrappers can be altered for different document layouts (caption above/below, figure separated by rule yes/no, …).

One particular layout requires each figure to be placed on a separate page after the main document.

Own attempts

The endfloat package comes to mind. However, I was unable to get it to work, as the figures are created by a wrapper.

I have tried implementing this using \gappto: The figure-creating command would be just appended to a global hook which is executed just before \end{document}. This worked when the figure-creating wrapper was just a command, but now it's an environment to allow "everything" inside. I have added my attempt to the MnWE below, but this results in the following error message:

! Extra }, or forgotten \endgroup.
\environment_richfigure_end_aux:w ...gure}\egroup 

l.39       \end{richfigure}

How would you implement this?

MnWE

\documentclass{scrartcl}
\pagestyle{empty}
\usepackage{caption}
\usepackage{xparse}
\usepackage{etoolbox}

\newcommand{\delayedfigures}{}

% Comment the following line to get working code
\newcommand{\dofigure}[1]{\gappto{\delayedfigures}{\clearpage#1}}

% The example works with the default implementation of \dofigure
\providecommand{\dofigure}[1]{#1}

%%   \begin{richfigure}
%%     [<placement>, e.g. htp (h=here, t=top, p=page)]
%%     {<short caption>}
%%     {<long caption>}
%%     {<\label{label}>}
%%       <\includegraphics[...]{figure}>
%%   \end{richfigure}
\NewDocumentEnvironment{richfigure}{O{tbp} m m m}{%
  \dofigure\bgroup%{%
    \begin{figure}[#1]%
      \caption[#2]{#3}#4%
        }{% Here, the contents of the environment are placed
    \end{figure}%
  \egroup%{
}

\gpreto{\enddocument}{\delayedfigures}

% Usage example
\begin{document}
  Main document contents.

  \begin{richfigure}{Short caption}{Long caption}{\label{fig:1}}
    Figure contents.
  \end{richfigure}

  All figures are to appear on separate pages, one per page.
\end{document}

Best Answer

here is an example which modies the floatcheck and uses [p] as placement. The floats appear at the end of the sections, one per page.

\documentclass{scrartcl}
\pagestyle{empty}
\usepackage{caption}
\usepackage{lipsum}
\makeatletter
\def \@largefloatcheck{\ht\@currbox 0.5\textheight}
\makeatother

\begin{document}
\section{baz}
  Main document contents.
\lipsum
\begin{figure}[p]
 \centerline{ Figure contents. }
\caption[Short caption]{Long caption of fig 1}\label{fig:1}
\end{figure}

\lipsum

All figures are to appear on separate pages, one per page.
\lipsum

\section{foo}
\lipsum
\begin{figure}[p]
 \centerline{ Figure contents. }
\caption[Short caption]{Long caption  of fig 2}\label{fig:2}
\end{figure}

\lipsum

\end{document}
Related Question