7

In my ocgx package, I would use the new ocg-p package instead of the ocg package. With pdflatex or lualatex, all is good. But with xelatex, I obviously can't use \pdfstartlink and \pdfendlink (these primitives are provided by pdftex or luatex).

How to emulate these two primitives with xetex?

Here is an example of current code in my ocgx package:

\long\def\switchocg#1#2{%
  \def\ocgx@list{}%
  \ocgx@listOCG#1 ENDOFOCGS %
  \leavevmode%
  \pdfstartlink user {%
    /Subtype /Link
    /A << /S/SetOCGState /State [/Toggle \ocgx@list] >>
    /Border [0 0 0]
  }%
  #2\pdfendlink%
}
Paul Gaborit
  • 70,770
  • 10
  • 176
  • 283

1 Answers1

6

According to texdoc dvipdfmx the pair of specials

\special{pdf:bann <<dict>>}
\special{pdf:eann}

allow for producing breakable annotations with dvipdfmx/XeTeX in analogy to the pdfTeX commands \pdfstartlink/pdfendlink.

Thus,

\long\def\switchocg#1#2{%
  \def\ocgx@list{}%
  \ocgx@listOCG#1 ENDOFOCGS %
  \leavevmode%
  \special{pdf:bann <<
    /Subtype /Link
    /A << /S/SetOCGState /State [/Toggle \ocgx@list] >>
    /Border [0 0 0]
  >>}%
  #2%
  \special{pdf:eann}%
}
AlexG
  • 54,894
  • Unlike pdfTeX/LuateX, XeTeX/(x)dvipdfm(x) does not support nested annotations. – Heiko Oberdiek Dec 10 '12 at 11:32
  • @Heiko: Do you think of something like \pdfstartlink user {...} ... \pdfstartlink user {...} ... \pdfendlink ... \pdfendlink? Doesn't seem to be relevant for @Paul's problem. What might this be good for? Do mouse events bubble through superimposed PDF annotations? – AlexG Dec 10 '12 at 12:07
  • The question was about emulating \pdfstartlink and \pdfendlink with XeTeX. \pdfstartlink can be nested, \special{pdf:bann} cannot. – Heiko Oberdiek Dec 10 '12 at 12:45
  • @Heiko: I am pretty sure that nesting links, that is, the possibility for \switchocg{foo}{footext\switchocg{bar}{bartext}footext cont'd}, isn't really wanted by the OP. Maybe @Paul could comment on this. – AlexG Dec 11 '12 at 10:19
  • @AlexG Thanks for your excellent answer (I looked at the xetex documentation and not at the dvipdfmx documentation). – Paul Gaborit Dec 13 '12 at 10:46
  • @HeikoOberdiek Thanks for your comment about nested annotations. – Paul Gaborit Dec 13 '12 at 10:47