Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've been writing a mathematical text for some time, and seeing as it is the 21st century, I would like this text to be interactive and dynamic, probably in PDF format. The main function that I am looking to implement is a sort of "spoiler text" environment where the user can click a button to reveal content that is otherwise collapsed and unseen. This could be used to hide answers to exercises or proofs for theorems, etc.

I am led to believe that this is possible by using some form of Javascript embedded in LaTeX. Can somebody point me to a reference that would allow me to implement this, or better yet, explain to me how I should design this "spoiler text" environment?

share|improve this question
    
You can use links to go to another pages and then go back. I use this sometimes in beamer. –  Sigur Nov 22 '13 at 0:25
    
Someting that works quite well in Adobe Products (Reader, Acrobat) and partially in Foxit-Reader, and which allows for LaTeX formatted pop-ups is given here: tex.stackexchange.com/a/120005/1053 –  AlexG Nov 22 '13 at 7:36
add comment

1 Answer 1

Ok, this is an ugly hack, but if nothing else works, well, this will work. This is from The PracTEX Journal, 2006, No. 4, Article revision 2006/11/03, Hypertext capabilities with pdfTEX by Federico Garcia.

\pdfannot width w height h depth d { /Subtype /Text
/Contents (htexti)}

This is via pdfTEX primitives, so I have no idea what is going on with it. It makes a postit note in the document that you click on to see the text.

Instructions:

The three dimensions w, h, and d are all LATEX dimensions. But the one that is important is h (the height), because it determines where the note appears in relation to the text baseline. It is also a good idea use a \qquad after it.

Also note: This works fine in Adobe. It doesn't work at all in Sumatra PDF. Well, the note shows up, but you can't click it. So this is a bit risky (So is javascript for that matter, as a lot of PDF readers avoid it for security reasons).

A bit more from the article:

One thing to have in mind with post-it notes is that their exact behavior (color, size, when it opens, how it closes, etc.) is not very much standardized, and tends to change from version to version of Acrobat Reader. That said, the note can be of a different color if, between the brackets of \pdfannot, /C [r g b] is appended; a title for the note is determined with /T (title), and the note can show up open by default with /Open true.

Well, that is one way. A terrible, terrible way, but it would technically work.

share|improve this answer
    
Thanks, it is nice to know that the capability exists. Your comment about compatibility with PDF readers is also a good point. At least for my own purposes, I use Adobe Acrobat Professional so there shouldn't be any features that I cannot test myself, hopefully. However, I agree with your opinion that this method seems rather adhoc. –  Christopher A. Wong Nov 22 '13 at 1:07
    
For formatted text, see tex.stackexchange.com/a/120005 –  AlexG Nov 22 '13 at 7:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.