Here's a possible way. First of all the main document (changing \iftrue
to \iffalse
will make possible to typeset it normally, with figures and tables.
\documentclass{article}
\iftrue % change to \iffalse for production version
\usepackage{expl3,environ}
\makeatletter
\newsavebox{\@gobblefloatbox}
\newif\ifcrazy@label
\def\crazy@label#1{\gdef\crazy@thislabel{#1}\xdef\crazy@currentlabel{\@currentlabel}\global\crazy@labeltrue}
\let\figure\relax\let\endfigure\relax
\NewEnviron{figure}[1][\fps@figure]{\crazy@float{figure}}
\let\table\relax\let\endtable\relax
\NewEnviron{table}[1][\fps@table]{\crazy@float{table}}
\def\crazy@float#1{%
\csname crazy_save:nn\expandafter\endcsname\expandafter{\BODY}{#1}%
\begin{lrbox}{\@gobblefloatbox}\begin{minipage}{\textwidth}%
\renewcommand{\caption}[2][]{\refstepcounter{#1}##2}%
\let\label\crazy@label
\BODY
\end{minipage}\end{lrbox}%
\ifcrazy@label\edef\@currentlabel{\crazy@currentlabel}\label{\crazy@thislabel}\global\crazy@labelfalse\fi
}
\ExplSyntaxOn
\seq_new:N \g_crazy_floats_seq
\cs_new:Npn \crazy_save:nn #1 #2
{
\seq_gput_right:Nn \g_crazy_floats_seq { \begin{#2} #1 \end{#2} }
}
\iow_new:N \crazy_output_w
\cs_new:Npn \crazy_write:
{
\iow_open:Nn \crazy_output_w { \c_job_name_tl.ftl }
\seq_map_inline:Nn \g_crazy_floats_seq
{ \iow_now:Nn \crazy_output_w { ##1 } }
\iow_close:N \crazy_output_w
}
\AtEndDocument{\crazy_write:}
\ExplSyntaxOff
\fi
\usepackage{kantlipsum}
\begin{document}
\author{A. U. Thor}
\title{A crazy article}
\maketitle
\section{A section}
\kant[1-2]
\begin{figure}[tp]
\centering
A figure
\caption{A caption}\label{fig:a}
\end{figure}
Here we have a reference to figure \ref{fig:a}
\kant[3-4]
\section{B section}
\kant[1-2]
\begin{table}[tp]
\centering
A table
\caption{A caption\label{tab:b}}
\end{table}
\kant[3-4]
\end{document}
If the document is called mydoc.tex
, at the end a file mydoc.ftl
will be created, containing all the floating objects in the order specified in the document. It will be sufficient to create a new document
\documentclass{article}
% the necessary packages
\begin{document}
\input{mydoc.ftl}
\end{document}
The separate files for figures are easy; for tables it's harder: if they are not so many, editing the produced .ftl
file may be the easiest solution. After all the allowed number of pages is rather limited.
What are we doing? The figure
and table
environments are redefined with \NewEnviron
to first save their contents in a LaTeX3 sequence; then the same contents is typeset in a box in order to establish references and read the label; the box will then be discarded. At the end the collected material is written off in the .ftl
file.
Note: I chose the prefix the internal macros on purpose. Maybe the people who ask to comply with such crazy requirements will understand.
\processdelayedfloats
to relax, you'll get the captions without figures and tables. Within the figures/tables document, you could\include
thefff
andttt
files produced by the other document to get the figures and tables (without captions).