5

I've tried a few items I've found on the forum here, by using \phantom or the following code:

\newcommand\invisiblesection[1]{%
  \refstepcounter{section}%
  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
  \sectionmark{#1}}
...
\invisiblesection{Blah}

Neither compile without errors when I try to print the following invisiably - meaning leaving blank space where the solution is typed.

\phantom{
For this experiment the sample space is simple to think about and write down. We can use canonical ordering to find the sample space as seen in Table \ref{tab:samplespaceexample} which yields a sample space of 

\begin{displaymath}
\Omega = \{\textrm{HHH, HHT, HTH, HTT, THH, THT, TTH, TTT}\}.
\end{displaymath}

  \begin{center}
  \begin{tabular} {ccc}
    First Toss & Second Toss & Third Toss \\\hline
    H & H & H\\
    H & H & T\\
    H & T & H\\ 
    H & T & T\\
    T & H & H\\
    T & H & T\\
    T & T & H\\
    T & T & T\\
  \end{tabular}
  \caption{Canonical ordering used to specify a sample space.}
  \label{tab:samplespaceexample}
  \end{center}
It should be noted that the sample space can be represented differently for the same random experiment if the point of interest changes. If we were interested in the number of heads instead of the specific outcomes the sample space would be

\begin{displaymath}
\Omega = \{0, 1, 2, 3\}.
\end{displaymath}
}
\end{exmp}

I should note that if I only use phantom on the text at the top before the \begin{displaymath} function it does seem to work but as soon as I go into another environment it doesn't work.

3 Answers3

2

I would like to suggest a different approach. You should create an if/else case to print or not print the text you want. Here is a simple example. I created a function called \showSolution. With this function you can show the solution or hide, just comment the line \showSolution and the solution will be hidden

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[top=2cm,bottom=2cm,left=1cm,right=1cm]{geometry}
\usepackage[table]{xcolor}



% ---------- commands  -- -----------------------------

\newif\ifPrintSolution

\newcommand{\showSolution}{
\PrintSolutiontrue
}

\newcommand{\solution}[1]{
  \ifPrintSolution {\color{black!65}\it Solution:\\[1ex] #1} \fi
}

% ------------------------------------------------------------



\begin{document}


\showSolution

Question: This is a question...

\solution{
    This is the solution
}


\end{document}
1

Have you tried simply making the text white? Use the xcolor package, with \textcolor{color}{text}

Stefan Pinnow
  • 29,535
1

It isn't clear to me if you want to hide certain text when the pdf is printed on paper or if you want to create two versions of the pdf (for example one for internal and one for public distribution). I'm guessing the latter and for that Charles Henrique Porto Ferreir's answer is great.

If you instead want to make text appear in the pdf but not on paper when printed, you can use the ocgx2-package.

Here's a small example:

\documentclass{article}
\usepackage{ocgx2}

\begin{document}
\Huge Hello world!

\begin{ocg}[printocg=ifvisible]{myworldlayer}{id1}{1} 
% possible options are printocg=ifvisible or always or never
\Huge The world is a book and if you do not travel you read only one page
\end{ocg}
\end{document}

You can choose to show or hide the text in acrobat reader and it will only appear on paper if it appears in the pdf. To toggle the text, use the tickbox in this screenshot:

ocgx2_example

Preview of print:

enter image description here

  • This is great! I'd like to have pdf copies of the blanks and the filled in ones though. – user1329307 Aug 24 '16 at 12:55
  • @user1329307 I changed my example to show the possibilities! Is this closer to what you want to have? –  Aug 25 '16 at 05:49