TransWikia.com

How to hide a part of a latex file?

TeX - LaTeX Asked by hideandseek on April 12, 2021

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.

5 Answers

You can use comment package:

documentclass{article}

usepackage{comment}

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

output:

enter image description here

Answered by Romain Picot on April 12, 2021

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

Answered by user2478 on April 12, 2021

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}

newsaveboxabimagebox
DeclareDocumentCommand includegraphicsd { o m }{%
    sboxabimagebox{includegraphics[#1]{#2}}%
    begin{tikzpicture} 
    node[draw, dashed, text width=thewdabimagebox,minimum height=thehtabimagebox, align=center, inner sep=0]{This is white};%
    end{tikzpicture}%
}%

begin{document}

%This image is shown
begin{figure}[htbp]
  centering
  includegraphics[width=0.345textwidth]{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.345textwidth]{example-image-a}
  caption{Close up of an opossum, part of the genus of piglet.}
end{figure}

end{document} 

enter image description here

Answered by Aubrey Blumsohn on April 12, 2021

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 defhide#1{textcolor{white}{#1}} to hide and defhide#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.

mew

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

Answered by Fran on April 12, 2021

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}[thesvarH]{hspace{thesvarW}}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: enter image description here

Answered by KodoCoder on April 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP