# pdflatex to create hidden text that is revealed on click

At present when I create worksheets my code as a very MWE looks something like the following:

\documentclass{article}

\begin{document}

\newcommand{\solution}[1]{} % actually some clever code and stuff that many users here have helped create for me but for the moment is not needed.

\begin{enumerate}
\item Question text 1 \solution{the first answer}
\item Question text 2 \solution{the second answer}
\item Question text 3 \solution{the third answer}
\item Question text 4 \solution{the fouth answer}
\end{enumerate}

\end{document}


In the future, at my institution, all future pupils will have a tablet to work from, instead of paper and so it now appears that all my worksheets will need to be reformatted to be more useful.

Being more useful is in my mind as follows:

1. On every page at the top is the question and the rest of the page is empty (space to solve the problem).
2. Having a clickable button that reveals the solution.

So my questions are:

1. How can enumerate by redefined so that there is only one question or even part of question per page?
2. How can \solution be redefined so that it shows in the pdf the test solution which when clicked reveals the hidden text that is the argument of the solution macro?
• Related regarding the second subquestion: tex.stackexchange.com/q/270780/134144 – leandriis Apr 16 '18 at 18:36
• @leandriis I am afraid OCGs won't work in mobile PDF readers (see question). At least not in AR for android (just tested this). – AlexG Apr 17 '18 at 9:26

I managed to find a working solution for both parts of my request.

The enumeration can be made pagewise by globally setting itemsep to \textheight. This seems to look good even with multiple lines of text. I tried to use \newpage or \pagebreak but neither of these seemed to work.

The hidden text, which I now know is called OCG, I worked from the comment of leandriis and uses the package ocgx2. It works when I open the document in Adobe Acrobat Reader DC and as of yet I have not had a chance to test it on a tablet.

A working example of code is given below.

\documentclass{article}

\usepackage{enumitem}
\setlist{itemsep={\textheight}}

\usepackage{ocgx2}

\newcounter{ocgSolution}
\setcounter{ocgSolution}{1}

\newcommand{\solution}[1]{%
\newline
\switchocg{\theocgSolution}{Solution:}
\begin{ocg}{OCG\theocgSolution}{\theocgSolution}{0}
#1
\end{ocg}
}

\begin{document}

\begin{enumerate}
\item Question text 1 \solution{the first answer}
\item Question text 2 \solution{the second answer}
\item Question text 3 \solution{the third answer}
\item Question text 4 \solution{the fourth answer}

\end{enumerate}

\end{document}