TeX - LaTeX Asked by Spenhouet on January 24, 2021
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.
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}
aaabegin{figure}
caption{AAA} end{figure}
bbb
begin{table} caption{BBB}
end{table}ccc
begin{lstlisting}
CCC
end{lstlisting}
uuubegin{figure} % empty "figure" environment
end{figure}vvv
end{document}
Correct answer by Mico on January 24, 2021
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}
newififplotfig % 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.65textwidth]{./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.Answered by daniel.heydebreck on January 24, 2021
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. renewcommandincludegraphics[2][]{}
.
Answered by Ulrike Fischer on January 24, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP