The following code will extract all graphics and floats. To prove it, I load the extracted objects again with \includepdf
(see the animation).
% this file name is extractor.tex
% compile it with pdflatex -shell-escape extractor
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{template.tex}
\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{mwe}
\usepackage[active,tightpage,\placeholder]{preview}
%\PreviewEnvironment{\placeholder}
\PreviewBorder=12pt\relax
\begin{document}
\lipsum[1]
\begin{table}[htb]
\centering
\begin{tabular}{|lll|}
\hline
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
41 & 42 & 43\\
51 & 52 & 53\\
\hline
\end{tabular}
\caption{A table}
\end{table}
\begin{figure}[htp]
\includegraphics{example-image-a}
\caption{A}\label{a}
\end{figure}
\lipsum[6-10]
\begin{figure}[htp]
\includegraphics{example-image-b}
\caption{A}\label{a}
\end{figure}
\begin{figure}[htp]
\includegraphics{example-image-c}
\caption{A}\label{a}
\end{figure}
\lipsum[16-20]
\end{document}
\end{filecontents*}
\usepackage{pgffor,pdfpages}
\begin{document}
\foreach \x in{graphics,floats}{%
\immediate\write18{pdflatex -jobname=template-\x\space "\def\noexpand\placeholder{\x} \noexpand\input{template}"}%
\includepdf[pages=-]{template-\x}%
}
\end{document}
The code above just simulates your scenario. To apply it in your real scenario, do the following.
Step 1
Assume that your input file is as follows.
\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{mwe}
\begin{document}
\lipsum[1]
\begin{table}[htb]
\centering
\begin{tabular}{|lll|}
\hline
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
41 & 42 & 43\\
51 & 52 & 53\\
\hline
\end{tabular}
\caption{A table}
\end{table}
\begin{figure}[htp]
\includegraphics{example-image-a}
\caption{A}\label{a}
\end{figure}
\lipsum[6-10]
\begin{figure}[htp]
\includegraphics{example-image-b}
\caption{A}\label{a}
\end{figure}
\begin{figure}[htp]
\includegraphics{example-image-c}
\caption{A}\label{a}
\end{figure}
\lipsum[16-20]
\end{document}
Step 2
Insert
\usepackage[active,tightpage,graphics]{preview}
\PreviewBorder=12pt\relax
in your input file. So your input file becomes as follows.
\documentclass{article}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{mwe}
\usepackage[active,tightpage,graphics]{preview}
\PreviewBorder=12pt\relax
\begin{document}
\lipsum[1]
\begin{table}[htb]
\centering
\begin{tabular}{|lll|}
\hline
11 & 12 & 13\\
21 & 22 & 23\\
31 & 32 & 33\\
41 & 42 & 43\\
51 & 52 & 53\\
\hline
\end{tabular}
\caption{A table}
\end{table}
\begin{figure}[htp]
\includegraphics{example-image-a}
\caption{A}\label{a}
\end{figure}
\lipsum[6-10]
\begin{figure}[htp]
\includegraphics{example-image-b}
\caption{A}\label{a}
\end{figure}
\begin{figure}[htp]
\includegraphics{example-image-c}
\caption{A}\label{a}
\end{figure}
\lipsum[16-20]
\end{document}
Save this input file as anyfilename-graphics.tex
Step 3
Invoke pdflatex anyfilename-graphics
to obtain a PDF file containing all extracted graphics.
Step 4
Repeat Step 2 but replace graphics
with floats
, save the file as anyfilename-floats.tex
. Now compile with pdflatex anyfilename-floats
to get a PDF file containing all extracted floats (figure or table).
Step 5
Done!
fig
and use the terminal to runpdftk fig*.pdf cat output all-figs.pdf
for example. Thus you will have all pdf glued together..tex
files and include with\input{table1}
between the main text and in a empty document. Is this way the main text is more readable for humans and the document only with tables is very easy to do. Of course, thi is also valid for for the figures.\begin{table}
, add\input{tableXXX}
just before, select until\end{table}
, cut the whole float and paste in the new documenttableXXX.tex
. With a good editor may be you can automatize most of this procedure with a macro.