# How to retain figures only with captions in their original positions

The publisher of our book has requested us to modify the source of the book so that only figures with their captions remain retaining their original positions in the document as if the rest of the document (i.e. paragraphs, chapter and section headers, tables etc) was still there. So, it's like everything should be made white except figures and their captions.

Is this possible? If so, how could this be achieved?

-
Would it be OK if the normal text would still be in the document but be turned all white? –  Martin Scharrer Apr 13 '11 at 11:05
@Martin Scharrer -- yes, it would be OK. I have tried using \color{white}, but table borders, their captions and counters for formulas remain black. –  01es Apr 13 '11 at 11:18

The notext option of the crop package removes all text for a similar purpose, e.g. that color graphics only can be printed with a color printer. (It has also a nographics option.)

It turns the color to white and disables all color macros to avoid the switching to different colors afterwards. You have to save and later restore these commands inside the figure like shown below to get normal colors inside the figures. This works fine in my test.

\documentclass{article}

\usepackage{tikz}

% Save away the color command incl. their internal macros:
\let\origcolor\color
\expandafter\let\csname origcolor \expandafter\endcsname\csname color \endcsname
\let\origtextcolor\textcolor
\expandafter\let\csname origtextcolor \expandafter\endcsname\csname textcolor \endcsname
% there is also \pagecolor but it isn't of relevance here

\newcommand{\restorecolorcmds}{%
\let\color\origcolor
\expandafter\let\csname color \expandafter\endcsname\csname origcolor \endcsname
\let\textcolor\origtextcolor
\expandafter\let\csname textcolor \expandafter\endcsname\csname origtextcolor \endcsname
\color{black}%
}

\usepackage[notext]{crop}% must be after tikz

\usepackage{lipsum}% dummy text
\begin{document}

\lipsum

\begin{figure}
\restorecolorcmds
\centering
\begin{tikzpicture}
\draw        (0,0) -- (1,1);
\draw [blue] (1,0) -- (0,1);
\end{tikzpicture}
\caption{caption text}
\end{figure}

\lipsum

\begin{figure}
\restorecolorcmds
\centering
\includegraphics[width=.8\textwidth]{image}
\caption{caption text}
\end{figure}

\lipsum

\end{document}

### Update:

The solution can be easier and nicer coded using the etoolbox package, which also allows to automatically add the required macro to all figures and tables.

\documentclass{article}

\usepackage{tikz}
\usepackage{etoolbox}

% Save away the color command incl. their internal macros:
\let\origcolor\color
\csletcs{origcolor }{color }
\let\origtextcolor\textcolor
\csletcs{origtextcolor }{textcolor }
\csletcs{origdefault@color}{default@color}
% there is also \pagecolor but it isn't of relevance here

\newcommand{\restorecolorcmds}{%
\let\color\origcolor
\csletcs{color }{origcolor }%
\let\textcolor\origtextcolor
\csletcs{textcolor }{origtextcolor }%
\def\normalcolor{\origcolor{black}}%
\normalcolor
}
\AtBeginEnvironment{figure}{\restorecolorcmds}
\AtBeginEnvironment{table}{\restorecolorcmds}

\usepackage[notext]{crop}% must be after tikz

\usepackage{lipsum}% dummy text
\begin{document}

\lipsum

\begin{figure}
\centering
\begin{tikzpicture}
\draw        (0,0) -- (1,1);
\draw [blue] (1,0) -- (0,1);
\end{tikzpicture}
\caption{caption text}
\end{figure}

\lipsum

\begin{figure}
\centering
\includegraphics[width=.8\textwidth]{image}
\caption{caption text}
\end{figure}

\lipsum

\end{document}
-
Thanx for the solution -- it worked for both ordinary figures as well as tikz graphics! –  01es Apr 13 '11 at 11:41