Title: How make a part of page invisible?
Tags: macros;xetex
Question: Excuse me for my bad English.
I want to make answer part of page unvisible but occupy space. I use xetex. 

```\documentclass{book}
\usepackage{lipsum}
\newcommand{\question}[1]{#1}
\newcommand{\answer}[1]{#1}
\begin{document}
    \question{What is your idea?}
    \answer{\lipsum[1]}
    \lipsum[2]
\end{document}
```

Output:

In above code I want to lipsum1 be unvisible. like this

Unfortunately transparent package not work in xetex and since answer part might be everything like tikz or colorbox or other things so change color of answer part to white not solve the problem in some situations.
Thanks in advance

Comment: There is a difference between invisible but present (transparent, white, copy & paste is possible) and invisible occupying space, but not being there (phantom, no copy & paste).

Comment: @cfr thanks but phantom dont solve problem

Comment: @Daniel thanks. content of answer must be invisible

Comment: „Invisible” in the printout / PDF display only or should the content itself not be part of the PDF file?


Here is another answer: You could use boxes to make sure the height is appropriate. That is, the actual height of the content. Almost.

By defining the ```\ProcessCutFile``` to be empty then the ```comment``` package won't do anything (it's all in the docs). Further more, we can use the ```\CommentCutFile``` to put the content of the environment into a ```\box```, which we can get the height of. Then we just apply ```\vskip``` to push this height.

This does not make space across multiple pages (although, I made a similar answer here that does). Also it works with verbatim commands like ```listings```

```\documentclass{article}
\usepackage{comment}
\usepackage{lipsum}
\usepackage{tikz}
% Make ourselves a new conditional
% Use \HideSolutionstrue to "activate" it
\newif\ifHideSolutions
% Make a solution environment
\generalcomment{solution}{%
  \begingroup
  \ifHideSolutions%
  % if \HideSolutionstrue is not called, then we remove the contents
  \def\ProcessCutFile{}\fi%
}{%
  \ifHideSolutions%
    % aand,now (also when it's not called), we make a box
    % and then we \input the \CommentCutFile.
    \setbox1=\vbox{\input{\CommentCutFile}}%
    % Get the height from \ht1 and use \vskip to make appropriate space
    \vskip\ht1
  \fi
\endgroup%
}

%Uncomment below to show solutions
\HideSolutionstrue

\begin{document}
  Some problem text goes here

  \begin{solution}
    \textbf{SOLUTION 1}
    \[ \forall\varepsilon&gt;0\exists\delta&gt;0:\dots \]
    \tikz{\draw(0,0)--(3,2);}
\end{solution}
%^ \end{solution} has to be ALONE on line without any prior spaces

  BETWEEN

\begin{solution}
    \textbf{SOLUTION 2}
    \begin{verbatim}
        This
        is
        also
        hidden
    \end{verbatim}
    \[ \forall\varepsilon&gt;0\exists\delta&gt;0:\dots \]
\end{solution}
%^ has to be ALONE on line without any prior spaces
  Some text after solution.

\end{document}
```


Here is another answer: Option 1: Nullify Everything and Measure Using Boxes

If you want to make anything (any box) invisible, you could 


wrap things with an environment
capture the content in a box that you never typeset (just measure)
measure the box's height, 
add a  vertical skip of that amount


The output might not be exactly the same as the visible version due to line skipping issues, but it should be within a reasonable margin of error.

Code

```\documentclass{book}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{environ,varwidth}
\newcommand{\question}[1]{#1}

\newcounter{showsolutions}
\setcounter{showsolutions}{0}% 0=False 1=True

\newsavebox{\hidebox}
\NewEnviron{answer}{\savebox{\hidebox}{\begin{varwidth}{\linewidth}\BODY\end{varwidth}}\ifnum\value{showsolutions}=0\relax\par\vspace{\the\dimexpr\ht\hidebox+\dp\hidebox}\else\BODY\fi}%

\begin{document}
  \question{What is your idea?}
  \begin{answer}
  \lipsum[1]
  \end{answer}
  \lipsum[2]
\end{document}
```



Option 2: Whitify Text

For a text-only solution

If


it is just text you‘re looking to hide, 
you want the text to take up the same amount of space as it normally would
should work with xelatex


swapping out black for white should do what you want. 

```\documentclass{book}
\usepackage{lipsum}
\usepackage{xcolor}
\newcommand{\question}[1]{#1}
\newcommand{\answer}[1]{\begingroup\color{white}#1\endgroup}
\begin{document}
  \question{What is your idea?}
  \answer{\lipsum[1]}
  \lipsum[2]
\end{document}
```

 

Another way might be to have a look at the xetex documentation, particularly under the font options. You could define.



Comment for this answer: @mojtababaghban Without example code, it is hard to help. Maybe you could, at least, list the conditions in the question
Comment for this answer: @mojtababaghban See update.
Comment for this answer: @mojtababaghban You never said anything about visibility logic (conditions) in the question, nor mentioned that some answers should not vertically skip the same amount of space as their contents. Again, you should clarify your requirements in your question. Anyway, adding a condition around \BODY would allow you to control the visibility of the contents.
Comment for this answer: @mojtababaghban Just use the command using the white-out technique for inline text, and the environment for everything else.
Comment for this answer: Thanks for your attention. but it is not just text I'm looking to hide. answer argument might be tikz or picture or math or text or everything else. so just change color to white not solve all of situation. make transparent to 0 solve all situation but transparent package is not compatible with xetex.
Comment for this answer: Thanks alot. I want when answer is invisibe page be like when it is visible. I want answer have an argument and depend on that argument answer be visible or invisible and occupid space when answer is invisible be exactly like when answer is visible.
Comment for this answer: Consider a situation that answer finish at the same line question exist so in this situation vspace not need just not typeset answer solve problem. some situation answer start at middle of a line and other situations.

Here is another answer: A most straightforward solution would be to use the ```adjustbox``` package and define answer command as :

``` \newcommand{\answer}[1]{\adjustbox{minipage=linewidth,phantom,frame}{#1}}
```

and removing the ```phantom``` option when the answer should be displayed. Of course, the ```frame``` is for demonstration purpose and must likely be removed.

Edit: I just read in the comments that the switch must be given as argument, so ```\answer``` can be defined as:

```\newcommand\answer[2][phantom]{\adjustbox{minipage=\textwidth,frame,#1}{#2}}
```

with an optional argument, set by default to ```phantom``` to hide the content,
and simply omitted to show it.

Nevertheless, as a teacher, I would find much more convenient to make a global change, for example with  a simple ```\newif``` that could be used as follows.

```\documentclass{book}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{adjustbox}
\newcommand{\question}[1]{#1\par}

\newif\ifhideanswer

\newcommand\answer[1]{%
\ifhideanswer
\adjustbox{minipage=\textwidth,phantom}{#1}
\else
\adjustbox{minipage=\linewidth}{#1}
\fi
}

\begin{document}
\hideanswerfalse
\question{What is your idea?}
\answer{%
\tikz{\draw[fill=red,line width=1pt]  circle(1ex);} 
\lipsum[1]
}
\lipsum[2]

\rule{\textwidth}{1pt}  \bigskip

\hideanswertrue
\question{What is your idea?}
\answer{
\tikz{\draw[fill=red,line width=1pt]  circle(1ex);} 
\lipsum[1]
}
\lipsum[2]

\end{document}
```

producing the attached image.


Comment for this answer: @Jhor With `\ifvmode` you can check wether you are on a new paragraph or still in the same paragraph.
Comment for this answer: @Jhor In case you were going to implement the inline answer solution.
Comment for this answer: consider situation that answer and question are in same line
Comment for this answer: If you really need this, I  will have a try to provide it as an additional argument to ``answer``, containing the question...
Comment for this answer: @Manuel, thanks for the hint, but I don't understand what would be the use here. My ``adjustbox`` solution likely wont use it as the box is not breakable and the 'phantom' option affect it as a whole.
Comment for this answer: For "situation that answer and question are in same line" you will need the empty box to be broken across lines (and possibly pages). Hence the ``adjustbox`` approach can not be used, or would require a significant hacking of the package
On the other side, as it seems that whitify the text could be enough for you, I suggest to use the ``tcolorbox`` solution suggested in the accepted answer to https://tex.stackexchange.com/questions/434055

{'source': 'StackExchangeDataset', 'subset': 'tex.stackexchange.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:06/23/18', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<macros><xetex>', 'Title': 'How make a part of page invisible?', 'ViewCount': 438, 'id': 437614, 'user_AboutMe': None, 'user_AccountId': 10380484.0, 'user_DisplayName': 'mojtaba baghban', 'user_Reputation': 327.0, 'user_Views': 35.0, 'user_id': 161275.0}}