I have a document for a student research project and want to know how many pages of content without figures, listings and tables I have. My university does differentiate between content and figures etc. and we are supposed to write a specific number of content pages.

Therefore I would like to deactivate/disable/do not show/... any figure, listing and table.

Is this somehow possible?

I have a finished document. If I have to apply something to every figure, table and listing than this would be more work than just making a copy and deleting everything. But if you have a solution that works without compromise but with consideration from the start, then please still feel free to share, even it does not help with my problem.

  • I dont know if this answers your question, but i found this: tex.stackexchange.com/a/164141/64781
    – Buschmann
    Jun 3, 2016 at 7:57
  • It could help for figures but wouldn't for tables and listings. What i'm looking for is more something like a disable or don't show option for any tex element.
    – Spenhouet
    Jun 3, 2016 at 8:09
  • are you saying that tables and figures themselves in the document are not considered part of the content? Or you mean listoftables? and listoffigures? for me, a picture is worth 1,000 words. So I do not see how a figure is not part of document content. Your school have some really strange policy ;)
    – Nasser
    Jun 3, 2016 at 8:14
  • Yes, while the figures and tables get included in the assessment they are not considered content. There are strict rules on how much "content" pages you have to deliver, and that doesn't coun't figures, tables and listing. That the other pages like cover, list of content,..., glossarie, acronyms, appendix... also doesn't count, is normal i think. But for me it's hard to get how much "content" pages i have with a big document and ~40 figures, tables and listings.
    – Spenhouet
    Jun 3, 2016 at 8:25
  • 1
    please add a minimale example of your code with a figure, table and a listing. Yes this is possible, that's why LaTeX was invented.
    – touhami
    Jun 3, 2016 at 12:07

3 Answers 3


Here's a LuaLaTeX-based solution. It defines a Lua function called hide_stuff which "gobbles" the contents of all figure, table, and lstlisting environments. The only input-related requirements are: (a) the environments' \begin and \end statements must not occur on one and the same input line, and (b) there's only one \begin{...} or \end{...} statement per input line.

Note that it's not necessary to modify or "prime" any of the existing figure, table, and lstlisting environments. All you need to do (besides using LuaLaTeX to compile the document) is to copy the code block from \usepackage{luacode} to \AtBeginDocument{...} into the preamble of your LaTeX document.

enter image description here

% !TEX TS-program = lualatex
\usepackage{listings} % for 'lstlistings' environment    
\usepackage{luacode} % for 'luacode' environment
in_group = false  -- initialize a Boolean variable
function hide_stuff ( buff )
  if string.find ( buff, "\\begin{figure}" ) or 
     string.find ( buff, "\\begin{table}" ) or
     string.find ( buff, "\\begin{lstlisting}" ) then 
            -- start gobbling
            buff = buff:gsub ( "\\begin%b{}.-$" , "" )
            in_group = true
  elseif string.find ( buff, "\\end{figure}" ) or 
         string.find ( buff, "\\end{table}" ) or
         string.find ( buff, "\\end{lstlisting}" ) then
            buff = buff:gsub ( "^.-\\end%b{}" , "" )
            in_group = false -- end gobbling
  elseif in_group == true then  
            buff = "" -- keep gobbling
  return buff
%% Assign the fuction to LuaTeX's "process_input_buffer" callback
\AtBeginDocument{\directlua{luatexbase.add_to_callback (
   "process_input_buffer", hide_stuff, "hide_stuff" )}}


\caption{AAA} \end{figure}


\begin{table} \caption{BBB}


uuu\begin{figure} % empty "figure" environment


You can use e.g. environ to collect the body and throw them away:







If you don't want to throw away the whole content, you can redefine the commands you want to ignore, e.g. \renewcommand\includegraphics[2][]{}.

  • 1
    I think one can get quite similar functionality with the comment package, excluding some environments. If you exclude tabular but not table you keep the captions. For figures, redefining \includegraphics as suggested does the same. I don't know about listings. Jun 3, 2016 at 15:46

This can be solved by using booleans.

You define a boolean variable which states whether you want to include figures and tables or not. Each figure and table statement has to be surrounded by an if statement testing for the boolean variable.

The simplest way to do this is:


\newif\ifplotfig  % you can also call it ifplottab or ifplotfigtab
\plotfigtrue      % uncomment for 'setting' it to false

  Some text with reference to Fig.~\ref{fig:myLabel} 

    \caption{Test Caption}\label{fig:myLabel}

  Some more text with reference to Table~\ref{tab:myLabel}...

    \caption{Tables Caption}\label{tab:myLabel}
      \begin{tabular}{c|c c}
        Grid & Some Value & Another Value  \\ \hline
        CD24 & -1398 & -1191 \\
        CD72 & -1926 & -2655

This solution comes from this and this answers. Here you will find an alternative solution.

In order to reduce the time spend on adding the if clauses you search & replace

  • \begin{tabular} by \ifplotfig \begin{tabular},
  • \end{tabular} by \end{tabular} \fi and
  • \includegraphics{...} by \ifplotfig \includegraphics{...} \fi.

For the latter replacement you need regular expressions or a search & replace functions that uses non-regex wildcards. If you have no experience with these, you replace

  • \includegraphics with \ifplotfig \includegraphics and
  • .pdf} with .pdf} \fi. The pdf needs to be replaced by the appropriate file ending of your figure files.
  • 1
    Thank's for the edit note. I just was about to mark your answer as solution and note that i should have done the \if mark while writing as this solution does have the same amount of work as deleting every figure, table and listing in a copy of the document. But with the information of your note, it's not a solution. lables and references are a must have.
    – Spenhouet
    Jun 3, 2016 at 8:31
  • @Spen The answer was updated. Now, the answer answers the question as requested. Jun 3, 2016 at 14:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .