2

I am writing my master thesis in Latex and was wondering whether it would be possible to render the document without any figures or tables. The goal is to get a feel for how many text pages I have as figures and tables don't count towards reaching the minimum page count requirement.

I could obviously just comment out all figures and tables, but my goal would be to get this version rendered with no or only minor modifications to the document.

4

If you have no concern over undefined \references, 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 \referencing capabilities, you could capture the figures and tables 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.

  • Thanks for the answer. As I only want to get the page count, I don't care about broken references. – vatbub Jan 14 at 23:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.