If you have no concern over undefined \ref
erences, you can just capture the contents of every figure
and table
using environ
:
\documentclass{report}
\usepackage{environ}
\RenewEnviron{figure}{}% Gobble figure environment
\RenewEnviron{table}{}% Gobble table environment
\usepackage{lipsum}
\begin{document}
\chapter{A chapter}
\lipsum
\begin{table}
\caption{This is a table}\label{tab:table}
\end{table}
\begin{figure}
\caption{This is a figure}\label{fig:figure}
\end{figure}
\lipsum
\end{document}
This should work even if you have a custom class as they typically use the same name for floats.
If you wish to retain \ref
erencing capabilities, you could capture the figure
s and table
s in the same way, but process them to see if they have a \label
within them. Processing here means you capture the \label
by storing the entire figure/table inside a box (that is never set).
\documentclass{report}
\usepackage{environ,etoolbox}
\newsavebox{\figtabsavebox}
\newcommand{\savelabel}[1]{\xdef\savedlabel{#1}}
\RenewEnviron{figure}{%
\patchcmd{\BODY}
{\label}
{\savelabel}
{% \label found
\renewcommand{\caption}[2][]{}% Make \caption[.]{..} a no-op (assume it doesn't contain \label)
\refstepcounter{figure}% Step figure counter
\savebox{\figtabsavebox}{\BODY}% "Execute" \BODY; also stores \label
\label{\savedlabel}% \label figure
}
{% No \label found
\stepcounter{figure}% Step figure counter
}%
\ignorespaces
}
\RenewEnviron{table}{%
\patchcmd{\BODY}
{\label}
{\savelabel}
{% \label found
\renewcommand{\caption}[2][]{}% Make \caption[.]{..} a no-op (assume it doesn't contain \label)
\refstepcounter{table}% Step figure counter
\savebox{\figtabsavebox}{\BODY}% "Execute" \BODY; also stores \label
\label{\savedlabel}% \label figure
}
{% No \label found
\stepcounter{table}% Step figure counter
}%
\ignorespaces
}
\usepackage{lipsum}
\begin{document}
\chapter{A chapter}
\lipsum{}
See Figure~\ref{fig:another_figure}.
\begin{figure}
\caption{A figure}
\end{figure}
\begin{figure}
\caption{Another figure}
\label{fig:another_figure}
\end{figure}
\lipsum
\end{document}
The above assumes that you have a single \label
per figure
/table
float (although, in general, one could have multiple) and that the \label
is not contained within the \caption
.
\ref
erences? – Werner Jan 13 at 21:10