# How to hide a part of a latex file?

I would like to have a generic command that basically reserves space for a set of commands, without actually rendering them in the PDF.

For example, \hide{this is some hidden text} will allocate space in the pdf for that string, but will never actually print it -- it will be just white.

Or alternatively, it should also work with \hide{\includegraphics[width=3in]{image.png}}. If there is no way to do it generically, I would at the very least want to know whether I can do it with the includegraphics command.

• This may be a duplicate of How do I create an invisible character?, as the answers actually apply to more than a single character. If not, please clarify. – Chris H Sep 25 '15 at 11:52
• Does my answer of your question is what you want or you want to create invisible character as suggest Chris? – Romain Picot Sep 25 '15 at 11:54

there are

\phantom{whatever}%  an empty box with width and height of the argument
\vphantom{whatever}%  an empty box with a zero width and height of the argument
\hphantom{whatever}%  an empty box with a width and zero height of the argument

• Per comments under other response, tested with floats and does not compile. Works well for simple text though. – Aubrey Blumsohn Sep 25 '15 at 16:45
• Use \phantom inside the float! – user2478 Sep 25 '15 at 17:27
• Yes indeed -that does work – Aubrey Blumsohn Sep 25 '15 at 18:08

You can use comment package:

\documentclass{article}

\usepackage{comment}

\begin{document}
\begin{comment}
not shown
\end{comment}
show on the pdf
\end{document}


output:

• The OP's question doesn't read like that to me -- it sounds like they want empty space to be shown in place of the text. – Chris H Sep 25 '15 at 11:50
• @ChrisH perhaps. In this case The answer should be \phantom{text} but not sure that is work with graphics. – Romain Picot Sep 25 '15 at 11:52
• @RomainPicot for floating content, I'm pretty sure it just wouldn't work. Only way it could would be to patch many different commands to respect some piece of state that's passed down implicitly. – Sean Allred Sep 25 '15 at 12:35

There are several different questions here so I am going to address only the main one which appears to be the hiding of specified graphics. It is presumed that the image file exists (and has a particular dimension) and the aim is to produce either a space or a placeholder that would be the same size as would be produced, while at the same time not making the image available to the reader. This could serve the purpose of reducing file size in a draft, or acting as a placeholder for an incorrect image. You could do something like the below, measuring the image and then inserting a tikz node in its place. By altering the code you could remove or alter the text inside, and remove the border at various times.

I did this by defining a variant of \includegraphics (\includegraphicsd)

\documentclass{article}
\usepackage{tikz}
\usepackage{xparse}
\usepackage{graphicx}

\newsavebox\abimagebox
\DeclareDocumentCommand \includegraphicsd { o m }{%
\sbox\abimagebox{\includegraphics[#1]{#2}}%
\begin{tikzpicture}
\node[draw, dashed, text width=\the\wd\abimagebox,minimum height=\the\ht\abimagebox, align=center, inner sep=0]{This is white};%
\end{tikzpicture}%
}%

\begin{document}

%This image is shown
\begin{figure}[htbp]
\centering
\includegraphics[width=0.345\textwidth]{example-image-a}
\caption{Close up of an opossum, part of the genus of piglet.}
\end{figure}

%This one is not shown
\begin{figure}[htbp]
\centering
\includegraphicsd[width=0.345\textwidth]{example-image-a}
\caption{Close up of an opossum, part of the genus of piglet.}
\end{figure}

\end{document}


If you want hide pictures to speed up compilations in a PDF preview or save ink cartridges in printer test, but a completely empty space is not essential, then the most simple method is use the draft option in the graphicx package to obtain only a frame with the name of the image.

And may be too obvious, but for most common texts without colors and without brackgrounds, is worth to note that an easy method could be use a white color. As simple \def\hide#1{\textcolor{white}{#1}} to hide and \def\hide#1{#1} to unhide. Obviously, the advantage/disadvantage of a white text with respect a true \phantom text is that you can still select and copy the hidden text in the PDF viewer.

\documentclass{article}
\usepackage[draft]{graphicx}
\usepackage{xcolor}
\def\hide#1{{\color{white}#1}}
\begin{document}
\begin{figure}[htbp]
\centering\includegraphics[width=0.345\textwidth]{example-image-a}
\caption{Close up of \hide{an opossum}, part of the \hide{genus} of piglet.}
\end{figure}
\end{document}


I know I'm late to this, but I think I found a good solution when trying to figure out the header for my resume.

The following command works to create a blank \raisebox with the dimensions of the input. It works for single-line text and \includegraphic commands, including wrap-text instances like the wrapfig package offers.

Note that you'll need the xspace package in order for the command to act like the given image or text with respect to surrounding spaces.

\documentclass{article}

\usepackage{xspace}
\usepackage{graphicx}

\newlength{\svarW}
\newlength{\svarH}
\newcommand{\makethismuchbox}[1]
{
\settowidth{\svarW}{#1}
\settoheight{\svarH}{#1}
\raisebox{0ex}[\the\svarH]{\hspace{\the\svarW}}\xspace
}

\begin{document}

% HEADER with two logos showing
{
\centering
\sffamily
\includegraphics[scale=.1]{my_logo}
\hfill
\Huge{My Name}
\hfill
\includegraphics[scale=.1]{my_logo}
}

\vspace{4ex}

% HEADER with one logo showing
{
\centering
\sffamily
\makethismuchbox{\includegraphics[scale=.1]{my_logo}}
\hfill
\Huge{My Name}
\hfill
\includegraphics[scale=.1]{my_logo}
}

\end{document}


Which outputs: