1

I'd like to have answers to my worksheet in LaTex that is visible when highlighted. Simply changing the text color to white means that when it is highlighted, you can tell there is text there, but it isn't legible, as it would be in Microsoft Word. Is there a way to do this, or another way to have not-easily accessible solutions somewhere on the page?

Thanks!

  • Welcome to TeX.sx! Of course, you can use the xcolor package and then use \textcolor{white}{invisible}. Please add a minimal working example (MWE) starting with \documentclass{...} and ending with \end{document} if you found some problem with this. – Fran Mar 10 '17 at 18:39
  • I think Ricky already tried that and found that the white text does not show up when highlighted in the PDF viewer. – Michael Palmer Mar 10 '17 at 19:29
  • This is exactly what I tried, and Michael correctly described the outcome. The text is highlighted but still cannot be read. It did just occur to me to maybe try a black \hl and see if that works, but I won't be able to try it for some time. Thanks anyway! – Ricky Barz Mar 10 '17 at 21:51
  • Look like a desktop or viewer configuration problem. When I select some word in my system, appear a green olive background and the text turn white regardless of the the original color in the PDF viewer as happen in most programs (browsers, text editors, etc.). – Fran Mar 11 '17 at 04:17

1 Answers1

2

Here is a suggestion based on the ocgx package. The answer is shown by clicking a switch.

\documentclass{article}
\usepackage{ocgx,lipsum,boxedminipage}

\newcounter{question}

\newenvironment{question}%
{\medskip\par\stepcounter{question}%
 \begin{boxedminipage}{\textwidth}%
 \textbf{Question \arabic{question}}}
%
{\end{boxedminipage}}

\newenvironment{answer}%
{\medskip\par\begin{ocg}{Answer \arabic{question}}{answer\arabic{question}}{0}}
%
{\end{ocg}\medskip\par\switchocg{answer\arabic{question}}{\fbox{Show Answer}}\medskip\par}

\begin{document}

\begin{question}
The ultimate question. 
\begin{answer}
42
\end{answer}
\end{question}

\begin{question}
The penultimate question. 
\begin{answer}
21
\end{answer}
\end{question}

\begin{question}
Write some pseudo-Latin. 
\begin{answer}
\lipsum[1-4]
\end{answer}
\end{question}

\end{document}

The visibility switch only works if the whole answer is on the same page. To ensure this, I have wrapped the answer inside a minipage. I also stuffed the question inside the same minipage, although that is not required; whether or not it is practical for you will depend on your content. Obviously, there is some room for improvement with respect to the layout ;)

The ocgx documentation warns that the package is not fully tested in all PDF viewers. On my Linux box, it works in Acrobat Reader but not Okular.