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.

enter image description here

As the blue note in the margins hints a mouse click reveals the kerns and spacings

enter image description here

The final surprise comes be clicking on the words in the text.

enter image description here

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:

  [ 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 }
 and then write:
Stop \textls{stealing sheep}!

this is the (typographically dubious) outcome:


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


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?


I suppose you are asking for the implementation of the layers/OCGs in the microtype documentation. AFAIK this is not done via pgf. Check microtype.dtx v1.66 for the code after line 517 with the comment

% the samples in the introduction, utilising nested optional content groups (aka. layers):

There he implements optional content.


Well, as usual it is all there, right before ones eyes... my pgfmanual was old, the current one has section 16.13 Referencing Nodes Outside the Current Pictures starting with 16.13.1 Referencing a Node in a Different Picture and section 75.3.2 explains the behind the scenes details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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