5

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

Therefor i woud like to deaktivate/disable/don't show/... any figure, listing and table.

Is this somehow possible?

EDIT: (I have a finished document. If i have to apply something to every figure, table and listing than it's 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 pls still feel free to share, even it doesn't help my problem.

  • I dont know if this answers your question, but i found this: tex.stackexchange.com/a/164141/64781 – Buschmann Jun 3 '16 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. – Spen Jun 3 '16 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 '16 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. – Spen Jun 3 '16 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 '16 at 12:07
5

Here's a LuaLaTeX-based solution. It defines a function that "gobbles" the contents of all figure, table, and lstlisting environments. The only input-related requirement is this: the environments' \begin and \end statements must not occur on one and the same line of input.

Note that it's not necessary to modify or "prime" any of the existing figure, table, and lstlisting environments. All you need to do is to copy and paste the code from \begin{luacode} to \end{luacode} into the preamble of your document (as well as, naturally, use LuaLaTeX).

enter image description here

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{listings} % for 'lstlistings' environment

\usepackage{luacode}
\begin{luacode}
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 = string.gsub ( buff, "\\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 = string.gsub ( buff, "^.-\\end%b{}", "" )
            in_group = false
            -- end gobbling
  elseif in_group == true then    
            -- keep gobbling
            buff = string.gsub ( buff, ".*", "" )
  end
  return buff
end
-- assign the fuction to the "process_input_buffer" callback
luatexbase.add_to_callback ("process_input_buffer", 
   hide_stuff, "hide_stuff" )
\end{luacode}  

\begin{document}

aaa\begin{figure}
\caption{AAA} \end{figure}

bbb

\begin{table} \caption{BBB}
\end{table}ccc

\begin{lstlisting}
CCC
\end{lstlisting}

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

\end{document}
7

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

\documentclass[]{article}
\usepackage{environ,listings}

\RenewEnviron{table}{}
\RenewEnviron{lstlisting}{}
\RenewEnviron{figure}{}
\begin{document}
abllbl

\begin{figure}
figure
\end{figure}

\begin{table}
table
\end{table}

\begin{lstlisting}
abc
\end{lstlisting}

\end{document}

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. – Ethan Bolker Jun 3 '16 at 15:46
3

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:

\documentclass{article}
\usepackage{graphicx}

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

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

  \begin{figure}[h]
    \centering
    \ifplotfig
      \includegraphics[width=0.65\textwidth]{./SOMEFIGURE.pdf}
    \fi
    \caption{Test Caption}\label{fig:myLabel}
  \end{figure}

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

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

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. – Spen Jun 3 '16 at 8:31
  • @Spen The answer was updated. Now, the answer answers the question as requested. – daniel.neumann Jun 3 '16 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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