While working on curating my lecture notes with LaTeX, I've come across a dilemma:
readability and aesthetics VS. rigor and comprehensiveness
I find myself e.g. working on a proof, and boiling it down to a few, slick arguments, but then recognize that I might have trouble following it later on. Not willing to sacrifice elegance or overwhelm my future self with huge chunks of explanatory texts, I thought, let's comment the proof. The idea would be to show comments if they were needed, but, by default, have them be hidden.
Some options include fancytooltips and pdfcomment, but their intended purposes differ from what I'm aiming to do.
What I'm aiming to do
Something like this:
The idea is simply that, while pressing a key (e.g. S, but might as well be a custom command, just preferably not a button in the PDF itself) on the keyboard, some additional elements (pre-rendered in LaTeX) show in the PDF, and, once the S key is no longer pressed, they hide (a toggling option might also be interesting). The difficulty is that this interaction would have to be able to:
- Show/hide TikZ pictures (esp. overlays),
- Change the color / highlighting / etc. of regular text shown in the document,
- Be reasonably efficient (when viewing the PDF in e.g. Acrobat) and not make the LaTeX source code completely unreadable.
Possible approaches
Now, I know that there are animation packages with similar functionalities (e.g. animate, see this question I've asked for an MWE on switching between TikZ pictures by clicking on a button).
Another possibility might be directly embedding JavaScript code into the PDF file via LaTeX code (see AlexG's wonderful answer to this question). This should be possible (hopefully? See p. 651 table 8.46 of the PDF-1.7 reference, and p. 709), and might even be the best way of doing so in terms of efficiency and compact code, but I must say I'd be very grateful for a couple tips on how to do it, since I can already see myself spending hours on end troubleshooting).
Working with booleans in LaTeX probably doesn't serve this purpose too well, as I suspect that one can't just toggle them in the rendered output (or then expect anything to change). But I'd be very happy if I'm mistaken.
I hope this question is not too broad; if I could narrow it down any further, I would, but which direction I should go in is, of course, actually part of the question. In any case, thank you so much for reading this or taking time to comment or answer, and all the best!
Below is a minimal non-working example:
\documentclass[12pt]{report}
\usepackage{tikz}
\usepackage{xcolor}
\newif\ifshowcomments
\begin{document}
\showcommentsfalse
\ifshowcomments
\tikz[overlay]{\draw[green!50!black](0,-.1) -- (1,-.1); \draw[green!50!black,->](.7,-.6) node[xshift=5, yshift=5]{\tiny interesting} -- (.1,-.6) -- (0.1,-.1)}%
\textcolor{green!50!black}{lorem}
\tikz[overlay]{\draw[blue!75!black](0,.4) -- (1,.4); \draw[blue!75!black,->] (0.1,1) node[xshift=12, yshift=-3]{\tiny $math$} -- (0.1,.4)}%
\textcolor{blue!75!black}{ipsum}
\else lorem ipsum \fi
%
\showcommentstrue\hspace{1cm}
%
\ifshowcomments
\tikz[overlay]{\draw[green!50!black](0,-.1) -- (1,-.1); \draw[green!50!black,->](.7,-.6) node[xshift=5, yshift=5]{\tiny interesting} -- (.1,-.6) -- (0.1,-.1)}%
\textcolor{green!50!black}{lorem}
\tikz[overlay]{\draw[blue!75!black](0,.4) -- (1,.4); \draw[blue!75!black,->] (0.1,1) node[xshift=12, yshift=-3]{\tiny $math$} -- (0.1,.4)}%
\textcolor{blue!75!black}{ipsum}
\else lorem ipsum \fi
\end{document}
Output (cropped):




ocgx2documentation doesn't list key listeners as an option to toggle the layer visibilities (it asks to choose one ofonmousenter, onmouseexit, onmousedown, onmouseup, onmouseall). Maybe I could make a small change in the package's source code? Or are key listeners just not a good idea for this (even after defining its scope of action and other details)? (Or, if the change is easily implemented, maybe it could even become part of the official package?) – steve Mar 19 '20 at 20:47\switchocg...with\actionsocg[onmouseall]{}{,,ocg1,}{,,,ocg1}{illuminate}– AlexG Mar 19 '20 at 21:11