How to only show text?
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][]{}
.
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.
% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{listings} % for 'lstlistings' environment
\usepackage{luacode} % for 'luacode' environment
\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 = 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
end
return buff
end
\end{luacode}
%% Assign the fuction to LuaTeX's "process_input_buffer" callback
\AtBeginDocument{\directlua{luatexbase.add_to_callback (
"process_input_buffer", hide_stuff, "hide_stuff" )}}
\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}
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
. Thepdf
needs to be replaced by the appropriate file ending of your figure files.