20

I wish to create a dynamic PDF file to write an article. This article will contain some theorems. The user will click a theorem and this will drill down to reveal the proof of that theorem. I think its different than hyperref since the proof is not visible initially in the PDF file only clicking the theorem makes the proof visible. If someone can also give a sample script that'll be much appreciated.

Martin Scharrer
  • 262,582
Scientist
  • 201

5 Answers5

13

This would be so much easier as website. PDF isn't very dynamically (in general, not just using pdflatex). The only way I know of to do it would be to use PDF forms and javascript. This means that you have a text area in a form which is initially empty but then filled with a text using javascript code when a button is pressed. However, this wouldn't look very nice and you are limited to normal text. Also I don't think some drop down action is possible.

Martin Scharrer
  • 262,582
  • 9
    I second the website suggestion. This sort of "dynamic" activity is much more suited to websites than documents. Incidentally, the idea of this sort of click-through proof was once championed by none other than Leslie Lamport. It's a small world. – Andrew Stacey Jun 02 '11 at 10:37
  • @Andrew: do you know where Lamport said that? I'd like to read more about it. – Matthew Leingang Jun 03 '11 at 17:08
  • 4
    @Matthew: I searched for "Lamport proof" and turned up this as the first hit: http://research.microsoft.com/en-us/um/people/lamport/pubs/lamport-how-to-write.pdf (since when did it become impossible to use "copy link location" from a Google search? Makes linking to PDFs very difficult.) – Andrew Stacey Jun 03 '11 at 18:07
  • @andrew blush thanks for doing my googling for me. – Matthew Leingang Jun 04 '11 at 13:41
  • @Matthew: No worries! What I actually meant to convey was that I didn't remember exactly where he'd said it but vaguely remembered reading it, Google led me to that one, but it might not be the best one for conveying his ideas. – Andrew Stacey Jun 04 '11 at 19:59
9

The package ocgtools allows you to define some layers and make them active or not by cliking somewhere. Creating PDF layers using ocg.sty is an entry in TeXample.net's webblog explaining how to use it. And Figure 3 of this article is an example of its real use.

Ignasi
  • 136,588
  • I just took a look at that article, and found more evidence for the argument that this isn't the way to do this! My PDF viewer did absolutely nothing when I clicked on those checkboxes. I agree that it would have been nice to have that functionality (particularly with that diagram), but I don't like features that rely too heavily on one particular viewer. – Andrew Stacey Jun 02 '11 at 16:01
  • 2
    @Andrew Stacey It does not rely on a particular viewer but on an open standard. That most of the so called PDF viewers ignore the standard is not the problem of Adobe Reader. It's chic to bash Adobe, but in this case others would deserve it much more. – Josef Jun 02 '11 at 19:29
  • 1
    @Josef: I wasn't intending my comment to be taken as an Adobe-bash. I have no opinion on Adobe's software. I would like to be able to use HTML5 on my website so that I can embed MathML a little more easily, and snazzy CSS3 tricks like rounded corners for boxes. But they aren't supported yet by "most" browsers so I don't. They should be, but they aren't yet. "Best viewed with XX" generally means "Don't bother looking at my website" as far as I'm concerned. – Andrew Stacey Jun 02 '11 at 20:15
  • I have a similar problem to the OP and have just played around with this and found your approach meets my needs. The simple example I constructed worked with Acrobat Reader and with evince (3.10.3). On my system ocg.sty wasn't available. However, texlive-latex-extra had ocg-p and ocgx available; I used the latter (which provides support without using javascript). – TooTone Apr 26 '14 at 22:18
6

It isn't exactly what you wanted, but with some hyperref magic you could include a link that would take you to an appendix at the end of the document that would include the proof and have a link at the end of the proof to take you back to where you started. This is a bit like "anon"'s solution, but within one file...

Seamus
  • 73,242
  • 3
    Something along the lines of these notes? These notes have a 6 page "cheetsheet" followed by the full text, with links back and forth between cheetsheet and full text. I coded that package some months back. But I never finished it. Should I? – Bruno Le Floch Jun 02 '11 at 16:25
  • @Bruno exactly like that. What exactly does the package do? Provide an easy interface to hyperreffing up backlinks like that? – Seamus Jun 02 '11 at 16:32
  • 3
    yes. The syntax is basically repeated blocks \begin{head}...\end{head} \bein{body}...\end{body}. The content of all the head environments is typeset first, then all the bodies. Links are automatically created. My first question on {TeX} has an example with nesting. I also converted the same source with tex4ht (math rendered with jsmath) into something close to what the OP is asking. See this page. – Bruno Le Floch Jun 03 '11 at 06:57
  • @Bruno Any plans to make the package public? – Yuval Filmus Dec 15 '11 at 11:08
  • @YuvalFilmus No precise plan, but I really should. I never finished that package because I started reading the TeXbook, and then got into LaTeX3. Some time ago I tried to understand and update the package, but I broke it, and wasn't using version control, so I essentially need to rewrite it from scratch :-/. Since I'll be rewriting everything, I could change the input syntax (currently it's what I gave in my first question on {TeX}). Any idea? – Bruno Le Floch Dec 15 '11 at 12:01
  • @BrunoLeFloch Semantically, it makes sense. The head points at the body, and when you go back, you go to the top of the head. Denotationally, there might be different "interpretations". For example, in a fantasy world there might be a "+" that you click and the proof opens below. But as long as your syntax accommodates all such reasonable interpretations, it should be fine. – Yuval Filmus Dec 15 '11 at 17:33
  • The quest for a good implementation is still on, though. As the answers here show, there are limits to the "reasonable" output formats, namely DVI, PostScript and PDF. HTML pages look awful. But perhaps the newest version of PDF supports (say) pop-up windows? Maybe there's another format with a TeX output driver that could accommodate more "interactivity"? – Yuval Filmus Dec 15 '11 at 17:34
  • @YuvalFilmus If you're keen on your interactivity, maybe try Flash? – Seamus Dec 15 '11 at 19:46
5

Do you mean tooltips? In context that works like this:

\setupinteraction[state=start] 
\starttext
This is \tooltip{test}{\TeX\ data}.
\stoptext

Hovering over 'test' will then show the (typeset) '\TeX\ data' as a popup. I am almost certain that there is a LaTeX package for that as well, but I do not know its name.

Edit: found two candidates, even: cooltooltips and fancytooltips.

Taco Hoekwater
  • 13,724
  • 43
  • 67
  • In cooltooltips and fancytooltips the tooltips are a bonus to other functionalty. pdfcomment offers with \pdftooltip a possibility to just use a tooltip. – Josef Jun 02 '11 at 13:56
  • @Josef is the content actually typeset? That what not quite clear from the example.pdf – Taco Hoekwater Jun 02 '11 at 14:15
  • Yes, e.g. $\pdftooltip{H_{2}SO_{4}}{Sulfuric acid}$ typesets H_{2}SO_{4} with a Sulfuric acid tooltip. – Josef Jun 02 '11 at 19:40
4

You can mimic this. From a single TeX file, you can produce to two pdf files, one with proofs and one without. Each theorem in each pdf file will have a link: clicking on it in the lean file will take you to the same place in the file with proofs; clicking on it in the verbose file will take you back to the lean file.

There are several packages that allow you to have an environment that prints or not according to some switch. The package xr allows you to reference a second file. You may have to do a search/replace to change \ref{leanfile-abc} to \ref{verbosefile-abc} to get the two sets of references (unless an expert comes up with a better idea).

Paulo Cereda
  • 44,220
anon
  • 41