Assume we have some text with exercises accompanied by solutions. I would like solutions to be hidden by default, with only clickable references present. When clicked, the solutions must show up, formatted just like any other piece of the document. I don't want solutions to be located at, say, other page, but right after the corresponding exercises.

Is there any way to implement this?

p.s. not sure about the tags, please correct me and delete this p.s.

  • 3
    Welcome to TeX.SX! I've ocg - features in my mind. For example, the ocgx package. I've never used it, however
    – user31729
    Oct 2, 2015 at 19:36
  • Thank you for greetings and recommendation! The ocgx package is nice, settles my search at the moment. The documentation is also quite friendly so I don't think it is worth explaining in an answer. Oct 2, 2015 at 20:13
  • 2
    @WeatherReport: If you found a solution it would be nice to post it as a self-answer for future reference and other readers :-)
    – Tobi
    Oct 2, 2015 at 20:25
  • When this is done with slides, one actually creates a new page each time. Oct 2, 2015 at 22:16
  • @ChristianHupfer, amazing package.
    – CroCo
    Oct 2, 2015 at 22:43

1 Answer 1


Following recommendations I will post a brief answer.

Christian Hupfer suggested to use ocgx package, to be found here https://www.ctan.org/pkg/ocgx .

As a minimal working example consider

This text is either hidden or revealed

Here \begin{ocg} starts the ocg (optional content group) enviroment which is supplemented by three arguments: 1) name_ext -- name of the ocg to be displayed in a pdf viewer; 2) name_int -- name of the ocg for internal references within the tex document; 3) 1 or 0 for the default state of the ocg -- visible (1) or invisible (0).

\switchocg command takes two arguments: 1) internal name of the ocg that it controls and 2) the text to be displayed over the interactive button which hides/reveals text

A problem: A serious issue is that whether this feature will work depends on the pdf viewer used. Some popular readers are supported, but some other are not.

A question related to the problem: As explained in the op question, I would like solutions to the problems to be hidden by default. Then, if the feature works on a particular viewer everything is fine. However, if it does not, then an unfortunate reader can not see a hidden text at all. It would be appropriate to change the default state of the secret text from hidden to visible for the readers which do not support the feature. I wonder whether this might be achievable.

I can imagine something like creating a document where all such fields are visible by default. Then, include some command that automatically (say, at the beginning of the document view) executes the "button" hiding text. Then, if a reader do not support the hiding/revealing feature all the text stay visible. In contrast, for the reader capable of hiding the text it will be hidden. However, I have no idea if one can "execute" a command in the described way. Advices are quite appreciated.

  • ocgx is just one of those packages. There are others, but as I wrote in my comment to the question (above): (Unfortunately) I've not used them so far
    – user31729
    Oct 3, 2015 at 7:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .