2

Is there a way to obtain a pdf file without figures and tables, while maintaining the figure numbers in the body text.

Thank you very much

  • 2
    For the graphicx-package the option draft exists, which replaces all images included with it with placeholders. – Skillmon Mar 25 '17 at 12:12
  • 1
    See http://tex.stackexchange.com/questions/21234/doing-something-only-when-the-draft-option-is-on . – JPi Mar 25 '17 at 12:14
  • Thank you for your response. But I would like to obtain only the text, without placeholder – Seif Fetni Mar 25 '17 at 12:16
  • The answer in my link tells you how to achieve that. – JPi Mar 25 '17 at 13:19
  • 1
    Did you look at endfloat? You could just remove the final pages from the resulting PDF... – Thruston Mar 25 '17 at 13:22
  • Excuse me, I don't find a response fot that in this link, whan you use the draft option the figures are replaced by white box – Seif Fetni Mar 25 '17 at 14:46
  • You could use the \ifdraft from that link and wrap it around all your tables and figures. This way you accomplish the stuff you want. – Skillmon Mar 25 '17 at 15:15
  • Thank you very much, I will try that. But I hope that there is an easy manner. I have just a article to check. But imagine the case of a thesis or a book ; you would like to obtain a free version, what will be the solution !! – Seif Fetni Mar 25 '17 at 15:34

2 Answers2

2

You might use the following utilizing the ifdraft package:

\documentclass[draft]{scrartcl}

\usepackage{ifdraft}
\usepackage{graphicx}

\newcommand{\tabledraft}[2]{%
    \ifdraft{\refstepcounter{table}\label{#1}}{#2}%
}
\newcommand{\figuredraft}[2]{%
    \ifdraft{\refstepcounter{figure}\label{#1}}{#2}%
}

\begin{document}
\figuredraft{fig:ex-a}{
    \begin{figure}
        \centering
        \includegraphics[width=5cm]{example-image-a}
        \caption{Example image a}\label{fig:ex-a}
    \end{figure}
}
\tabledraft{tab:ex}{
    \begin{table}
        \centering
        \caption{A neat table}\label{tab:ex}
        \begin{tabular}{ll}
            \hline
            neat&table\\
            being&neat\\
            \hline
        \end{tabular}
    \end{table}
}

Some random text.


Figure \ref{fig:ex-a} is nice but table \ref{tab:ex} is even nicer.

\end{document}

With draft-option resulting in:

results with draft

And without it resulting in:

results without draft

Skillmon
  • 60,462
2

This solution (using Skillmon's MWE) makes the figure or table invisible, although it actually goes through all the steps of drawing it.

\documentclass[draft]{scrartcl}

\usepackage{ifdraft}
\usepackage{graphicx}
\usepackage{environ}

\makeatletter
\ifdraft{\RenewEnviron{figure}[1][tbp]%
 {\hrule height0pt \rlap{\hspace{\paperwidth}\smash{\begin{minipage}{\textwidth}%
  \def\@captype{figure}\BODY\end{minipage}}}\ignorespaces}}

\ifdraft{\RenewEnviron{table}[1][tbp]%
 {\hrule height0pt \rlap{\hspace{\paperwidth}\smash{\begin{minipage}{\textwidth}%
  \def\@captype{table}\BODY\end{minipage}}}\ignorespaces}}
\makeatother

\begin{document}
Before text

    \begin{figure}
        \centering
        \includegraphics[width=5cm]{example-image-a}
        \caption{Example image a}\label{fig:ex-a}
    \end{figure}

    \begin{table}
        \centering
        \caption{A neat table}\label{tab:ex}
        \begin{tabular}{ll}
            \hline
            neat&table\\
            being&neat\\
            \hline
        \end{tabular}
    \end{table}

After text.

Figure \ref{fig:ex-a} is nice but table \ref{tab:ex} is even nicer.

\end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
  • I'm not sure whether I like your solution or not. While it is great, because it doesn't need any restructuring of the code, it is bad because it might add extra vspace because the not shown figures still result in new paragraphs. (is it possible to give half of an upvote?) – Skillmon Mar 26 '17 at 18:21
  • i make a few tweaks, I had noticed previously the \hrule\null takes up less room the \null by itself. – John Kormylo Mar 27 '17 at 03:21
  • Well done. Now the only thing that might be bothering (but being a case which shouldn't ever happen anyway), is that it starts a new paragraph even if there is now space between the environments and the text. Really a nice solution. – Skillmon Mar 27 '17 at 07:02