While exploring the depths of the microtype package with regard to LuaTeX I came across this innocent looking page 18 from the microtype.pdf 2.5 beta-08.
As the blue note in the margins hints a mouse click reveals the kerns and spacings
The final surprise comes be clicking on the words in the text.
Which is really neat! Of course, I want to know how it is done. As it is the official package documentation I immediately went for the dtx. However it does not give away its magic so easily. The relevant part in the dtx is:
\begin{verbatim}
\SetTracking
[ no ligatures = {"\anchorarrow{nolig}"f},
spacing = {60"\anchorarrow{ispace}"0*,-1"\anchorarrow{istretch}"00*,"\anchorarrow{ishrink}"},
outer spacing = {4"\anchorarrow{ospace}"50,2"\anchorarrow{ostretch}"50,1"anchorarrow{oshrink}"50},
outer kerning = {"\anchorarrow{okernbegin}"*,"\anchorarrow{okernend}"*} ]
{ encoding = * }
{ 1"\anchorarrow{lsamount}"60 }
\end{verbatim}
and then write:
\begin{verbatim}
Stop \textls{stealing sheep}!
\end{verbatim}
this is the (typographically dubious) outcome:
\lssample
\noindent
While the word `Stop' is not letterspaced, the space between the letters in
the other two words is expanded by the \showarrow[tracking]{tracking~amount}{red}
of 160/1000\,em\,=\allowbreak\,0.16\,em.
The definitions of the macros are of course not to be found. Instead a “bonus material” section in the preamble shows that
\InputIfFileExists{microtype-lssample.dtx}
it is in another file, unfortunately not included in the .zip. So the questions is still open. How is this achieved. The macros in the dtx hint that a general solution is at work here. I would suspected some Tikz overlay magic at work here. But as the positions are not determined until after the page is typeset the arrows must somehow come afterwards. And then how is the information passed on to the pdf viewer that they can be toggled by clicking on the words?
EDIT: Following Martin Schröder’s pointer I have learned, that the PDF Format since version 1.5 supports “layers” here called Optional Content Groups (OCG). In an older thread (2007) on comp.text.tex Michael Ritzert offered his ocg.sty
for creating them in LaTeX directly. There is even a nice demonstration on TeXample that shows that the toggling is achieved by bits of JavaScript executed by Acrobat Reader. There is also a fairly recent package ocgtools
. The question that remains is how to get the anchors in the page and let the arrows cris-cross over the typesetted material?