| 1 |
================================== |
| 2 |
The `ocgx2' LaTeX Package |
| 3 |
|
| 4 |
https://gitlab.com/agrahn/ocgx2 |
| 5 |
|
| 6 |
(C) 2015--\today Alexander Grahn |
| 7 |
================================== |
| 8 |
|
| 9 |
|
| 10 |
1. Introduction |
| 11 |
=============== |
| 12 |
|
| 13 |
This package serves as a drop-in replacement for the already existing |
| 14 |
packages `ocgx' by Paul Gaborit and `ocg-p' by Werner Moshammer for the |
| 15 |
creation of PDF Layers. |
| 16 |
|
| 17 |
It re-implements the functionality of the `ocg', `ocgx' and `ocg-p' |
| 18 |
packages and adds support for all known engines and back-ends including |
| 19 |
|
| 20 |
* LaTeX --> dvips --> ps2pdf/Distiller |
| 21 |
* (Xe)LaTeX --> (x)dvipdfmx |
| 22 |
* pdfLaTeX, luaLaTeX |
| 23 |
|
| 24 |
To enable dvipdfmx support, pass `dvipdfmx' globally as a class option. |
| 25 |
|
| 26 |
Also, it adds some minor improvements and bug fixes, such as package |
| 27 |
options, remembering option settings of re-opened OCGs, correct behaviour |
| 28 |
of layer switching links that were themselves placed on layers, correct |
| 29 |
listing of (nested) OCGs in the layers tab of PDF viewers, compatibility |
| 30 |
with the `animate' and `media9' packages. |
| 31 |
|
| 32 |
* New features: |
| 33 |
|
| 34 |
+ PDF layers extending over page breaks |
| 35 |
+ OCMDs (Optional Content Membership Dictionaries) for creating layers |
| 36 |
with complex visibility dependency |
| 37 |
+ grouping OCGs into Radio Button Groups |
| 38 |
+ additional keys for the TikZ interface of package `ocgx' |
| 39 |
+ re-implementing `hyperref's `ocgcolorlinks' option for creating |
| 40 |
OCG coloured links, which are printed on paper in the default |
| 41 |
text colour and which can, unlike the original `hyperref' |
| 42 |
implementation, extend over line and page breaks. |
| 43 |
|
| 44 |
|
| 45 |
2. Usage |
| 46 |
======== |
| 47 |
|
| 48 |
\usepackage[<options>]{ocgx2} |
| 49 |
|
| 50 |
\begin{ocg}[<options>]{<layer name>}{<OCG id>}{<initial visibility>} |
| 51 |
... material to be put on a PDF layer ... |
| 52 |
\end{ocg} |
| 53 |
|
| 54 |
<layer name> is the name shown in the PDF viewer's "Layers" panel, |
| 55 |
<OCG id> is an identifier used for referencing the layer elsewhere in the |
| 56 |
document (e. g. layer switching buttons, visibility configuration of an `ocmd' |
| 57 |
environment, re-opening the OCG at another place using the `ocg' environment). |
| 58 |
|
| 59 |
<initial visibility> is `on', `true', `1' or `off', `false', `0'. |
| 60 |
|
| 61 |
\begin{ocmd}[<OCMD id>]{[<visibility policy>][,<visibility expression>]} |
| 62 |
... material to be put on a PDF layer ... |
| 63 |
visibility calculated by <visibility expression> (Boolean expression) from |
| 64 |
other OCGs visibility, or according to <visibility policy> |
| 65 |
\end{ocmd} |
| 66 |
|
| 67 |
|
| 68 |
Package and `ocg' environment options: |
| 69 |
|
| 70 |
viewocg = always | never | ifvisible |
| 71 |
printocg = always | never | ifvisible |
| 72 |
exportocg = always | never | ifvisible |
| 73 |
|
| 74 |
not in ocgx, ocg-p: |
| 75 |
|
| 76 |
showingui (to be preferred over `listintoolbar' of ocgx/ocg-p) |
| 77 |
radiobtngrps = {<group name 1>[,<group name 2>[, ...]]} |
| 78 |
|
| 79 |
tikz (package-only option) |
| 80 |
ocgcolorlinks (package-only option) |
| 81 |
|
| 82 |
Package options have global scope. Environment options override package |
| 83 |
options locally. |
| 84 |
|
| 85 |
OCGs can be added to one or multiple Radio Button Groups using the new |
| 86 |
option `radiobtngrps'. From all OCGs within a Radio Button Group only _one_ |
| 87 |
can be enabled at a time. Enabling an OCG, e. g. in the Layers tab of the PDF |
| 88 |
viewer, automatically hides the previously visible OCG in the group. An OCG |
| 89 |
can be added to multiple Radio Button Groups, passing a comma-separated list of |
| 90 |
group names. Such a list must be enclosed in braces, `{...}'. |
| 91 |
|
| 92 |
`ocg' as well as `ocmd' environments can be nested and span multiple pages. |
| 93 |
|
| 94 |
See the `ocg-p' manual about the environment usage and the meaning of |
| 95 |
the remaining options: |
| 96 |
|
| 97 |
texdoc ocg-p |
| 98 |
|
| 99 |
|
| 100 |
3. The `ocmd' environment (Optional Content Membership Dictionary) |
| 101 |
================================================================== |
| 102 |
|
| 103 |
\begin{ocmd}[<OCMD id>]{[<visibility policy>][,<visibility expression>]} |
| 104 |
... material to be put on a PDF layer ... |
| 105 |
\end{ocmd} |
| 106 |
|
| 107 |
This environment creates a PDF layer whose visibility is determined by the |
| 108 |
current visibilities of other OCGs in the document according to at most one |
| 109 |
visibility policy plus at most one visibility expression. If both are given |
| 110 |
(with a comma in between) `<visibility expression>' takes precedence over |
| 111 |
`<visibility policy>', but the latter may serve as a fallback in older PDF |
| 112 |
viewers. |
| 113 |
|
| 114 |
`<OCMD id>' is an optional identifier which can be used to re-open the same |
| 115 |
layer with the same visibility setting at another place further down in the |
| 116 |
document. |
| 117 |
|
| 118 |
A `<visibility policy>' can be _one_ of |
| 119 |
|
| 120 |
\AllOn{<OCG id 1>, <OCG id 2>, ...} |
| 121 |
\AnyOn{<OCG id 1>, <OCG id 2>, ...} |
| 122 |
\AnyOff{<OCG id 1>, <OCG id 2>, ...} |
| 123 |
\AllOff{<OCG id 1>, <OCG id 2>, ...} |
| 124 |
|
| 125 |
All four directives take a list of OCG ids from wich the OCMD visibility is |
| 126 |
calculated. If the condition represented by the policy is met, the content |
| 127 |
associated with the OCMD is shown. The listed OCGs can be defined anywhere in |
| 128 |
the document. These directives can neither be combined nor nested in order to |
| 129 |
define the policy. Thus, a visibility policy has limited capabilities. |
| 130 |
|
| 131 |
A `<visibility expression>' is much more flexible than a policy. Arbitrarily |
| 132 |
complex visibility relationships can be formulated, based on the Boolean |
| 133 |
functions |
| 134 |
|
| 135 |
\And{<item a>, <item b>, ...} |
| 136 |
\Or{<item i>, <item j>, ...} |
| 137 |
\Not{<item n>} |
| 138 |
|
| 139 |
In the argument list, items represent OCG/OCMD ids as well as nested Boolean |
| 140 |
functions. As nesting of the three functions is possible, any thinkable |
| 141 |
visibility relationship can be defined. |
| 142 |
|
| 143 |
Note that `\Not{...}' accepts only one item, either an OCG/OCMD id or a nested |
| 144 |
function. Besides that, a single, isolated OCG/OCMD item is not allowed as an |
| 145 |
expression, it must always be embedded in one of the Boolean functions listed |
| 146 |
above. In the simple case of an OCMD depending on a single OCG in a positive |
| 147 |
way, it is better to use a policy, such as `\AllOn{<OCG id>}', or to put it as |
| 148 |
`\And{<OCG id>}'. |
| 149 |
|
| 150 |
Thus, simple OCMD visibilities can be expressed in an equivalent way by a |
| 151 |
policy or an expression. For example, the visibility expression equivalent of |
| 152 |
the policy directive `\AllOff{...}' is written by means of Boolean functions as |
| 153 |
`\Not{ \Or{ ... } }'. |
| 154 |
|
| 155 |
Note that Boolean functions and policy directives cannot be intermixed. |
| 156 |
|
| 157 |
|
| 158 |
4. Clickable links for switching PDF layer visibility |
| 159 |
===================================================== |
| 160 |
|
| 161 |
The available commands are |
| 162 |
|
| 163 |
\switchocg[<trigger>]{<OCG ids to toggle, comma-separated>}{<link text>} |
| 164 |
\showocg[<trigger>]{<OCG ids to switch ON, comma-separated>}{<link text>} |
| 165 |
\hideocg[<trigger>]{<OCG ids to switch OFF, comma-separated>}{<link text>} |
| 166 |
\actionsocg[<trigger>]{<ids to toggle>}{<ids to switch ON>}{<ids to switch OFF>}{<link text>} |
| 167 |
|
| 168 |
For details about their usage, read the `ocgx' package manual: |
| 169 |
|
| 170 |
texdoc ocgx |
| 171 |
|
| 172 |
By default, links are triggered on mouse-click. Other triggers are possible |
| 173 |
with `ocgx2'. For this, `ocgx2' provides the optional argument [<trigger>] to |
| 174 |
the commands listed above. Choose one of |
| 175 |
|
| 176 |
onmousenter, onmouseexit, onmousedown, onmouseup, onmouseall |
| 177 |
|
| 178 |
for <trigger>. In order to listen to more than one mouse event, use |
| 179 |
`onmouseall'. Layer ids in the mandatory argument(s) must then be grouped with |
| 180 |
braces and commas as follows: |
| 181 |
|
| 182 |
{<mouse-enter group>}, {<mouse-exit group>}, {<mouse-down group>}, {<mouse-up group>} |
| 183 |
|
| 184 |
Any of these groups may be left empty in order to configure only some |
| 185 |
mouse triggers. Inside the groups, OCG ids are also separated by commas. |
| 186 |
Therefore, braces must be put around the groups. For example: |
| 187 |
|
| 188 |
\switchocg[onmouseall]{ |
| 189 |
, , {ocg1, ocg2, ocg3, ocg4}, {ocg1, ocg2, ocg3, ocg4} |
| 190 |
}{Toggle layers on mouse-down and -up} |
| 191 |
|
| 192 |
|
| 193 |
5. Package option `ocgcolorlinks' |
| 194 |
================================= |
| 195 |
|
| 196 |
Is a re-implementation of the same `hyperref' option for creating OCG- |
| 197 |
coloured links, which are printed on paper in the default text colour. |
| 198 |
|
| 199 |
\usepackage{hyperref} % do NOT set [ocgcolorlinks] here! |
| 200 |
\usepackage[ocgcolorlinks]{ocgx2} |
| 201 |
|
| 202 |
Unlike the original `hyperref' implementation, OCG-coloured links are now |
| 203 |
allowed to extend over line and page breaks. Moreover, with pdfLaTeX/LuaLaTeX, |
| 204 |
OCG coloured links can be nested. |
| 205 |
|
| 206 |
Breakable OCG coloured links work best with normal text as link text. If |
| 207 |
the link text is mixed with graphical content, such as from external files or |
| 208 |
inline graphics (e. g. TikZ) and even \fbox-ed text, these graphical parts must |
| 209 |
be enclosed in |
| 210 |
|
| 211 |
\ocglinkprotect{...} |
| 212 |
|
| 213 |
For example: |
| 214 |
|
| 215 |
\href{http://ctan.org}{Visit me on |
| 216 |
\ocglinkprotect{\includegraphics{ctan-lion}}!} |
| 217 |
|
| 218 |
|
| 219 |
5. Usage with TikZ |
| 220 |
================== |
| 221 |
|
| 222 |
`ocgx2' uses code from file `tikzlibraryocgx.code.tex' by P. Gaborit to |
| 223 |
enable TikZ styles for creating PDF Layers and clickable layer switching |
| 224 |
links in the `tikzpicture' context. |
| 225 |
|
| 226 |
Just say: |
| 227 |
|
| 228 |
\usepackage[tikz]{ocgx2} |
| 229 |
|
| 230 |
instead of |
| 231 |
|
| 232 |
\usepackage{tikz} |
| 233 |
\usetikzlibrary{ocgx} |
| 234 |
|
| 235 |
to enable these TikZ styles and read the `ocgx' documentation about |
| 236 |
their usage: |
| 237 |
|
| 238 |
texdoc ocgx |
| 239 |
|
| 240 |
Package `ocgx2' adds the key `/tikz/ocg/opts' to the list in section ``How to |
| 241 |
add TikZ scopes into OCGs'" in the `ocgx' manual: |
| 242 |
|
| 243 |
/tikz/ocg/opts={<OCG options>} |
| 244 |
|
| 245 |
It can be used inside the `ocg' style |
| 246 |
|
| 247 |
\begin{scope}[ |
| 248 |
ocg={ref=..., name=..., opts={..., ...}}, |
| 249 |
... |
| 250 |
] |
| 251 |
... |
| 252 |
\end{scope} |
| 253 |
|
| 254 |
and allows passing `ocg'-environment options (`viewocg', `printocg', `exportocg', |
| 255 |
`showingui', `radiobtngrps') to the TikZ scope. |
| 256 |
|
| 257 |
The style `ocmd={...}' is another way for turning a TikZ scope into a PDF |
| 258 |
layer (in addition to `ocg={...}'). It has two sub-keys, `ref={...}' and |
| 259 |
`visibility={...}', which have the same meaning as the optional and the |
| 260 |
mandatory arguments of the `ocmd' environment: |
| 261 |
|
| 262 |
\begin{scope}[ |
| 263 |
ocmd={ref=..., visibility=...}, |
| 264 |
... |
| 265 |
] |
| 266 |
... |
| 267 |
\end{scope} |
| 268 |
|
| 269 |
|
| 270 |
Moreover, TikZ objects to be turned into OCG switching hyperlinks (section "How |
| 271 |
to transform nodes or paths into clickable links" in the `ocgx' manual) accept |
| 272 |
the additional key |
| 273 |
|
| 274 |
/tikz/trigger ocg = onmousenter | onmouseexit | onmousedown | onmouseup |
| 275 |
| onmouseall |
| 276 |
|
| 277 |
which makes them listen to various mouse events, as explained above. |
| 278 |
|
| 279 |
|
| 280 |
* * * |
| 281 |
|
| 282 |
|
| 283 |
This material is subject to the LaTeX Project Public License. See |
| 284 |
|
| 285 |
http://mirrors.ctan.org/macros/latex/base/lppl.txt |
| 286 |
|
| 287 |
for the details of that license. |