What is the easiest way to have all floats forcibly appear at the end of the document? The solution should work with htlatex, the floats should appear at the end of the HTML document in this case. (The original question, Force all floats to the end of the document without using endfloat, didn't have the htlatex requirement, and the solution doesn't work for htlatex. Other than that it's a copy, sorry for that. I didn't want to edit the original question, but I could.)
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 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}
htlatex" mean? You want them by the end in the HTML document, or they can appear at their place in the HTML document, just in must be compilable? – yo' Aug 30 '12 at 12:59\bgroupwill work as a substitute for{in the beginning of the environment (and\egroupin the end): that will not work and you will need to use a body-collection approach. Could you give an example showing whyendfloatis not an option? – Joseph Wright Aug 30 '12 at 13:23texdoc endfloatexplains this: The package explicitly looks for the\end{float}string, and this is embedded in the wrapper code. Also, I'd like to keep the environment-type interface -- my approach works with a macro-type interface, i.e. if the figure contents is just another argument to a macro. (The contents of therichfigureenvironment might be autogenerated and contain verbatim code.) – krlmlr Aug 30 '12 at 13:43\dofigure? + place a\AtEndDocument{\clearpage}after\begin{document}? + wrap each\begin{richfigure}...\end{richfigure}with a\AtEndDocument{ ... }? If no: sorry, if yes: does that solve your problem? – Stephen Aug 30 '12 at 15:10environpackage? – krlmlr Aug 31 '12 at 07:09answerspackage provides 'FileSave'-type commands – cmhughes Aug 31 '12 at 15:48