Debian Codegraph @

texmf-dist/doc/latex/ocg-p/ocg-p.tex

raw
1 % Copyright (C) 2012 by Werner Moshammer
2 % This file may be distributed and/or modified under the LaTeX Project Public License
3
4 %\documentclass[11pt]{article}
5 \documentclass[a4paper]{ltxdoc}
6
7 \usepackage{tikz}
8 \usetikzlibrary{arrows,automata}
9
10 \usepackage{hyperref}
11 \hypersetup
12 {
13 pdfauthor={Di Werner Moshammer},
14 pdfsubject={The ocg-p package},
15 pdftitle={The ocg-p package},
16 pdfkeywords={LaTeX,OCG, Layers}
17 }
18
19
20 \usepackage{fancyvrb}
21 %\usepackage{ocg-p}
22 \usepackage{framed}
23
24 \usepackage{datatool}
25 \usepackage{booktabs}
26
27
28
29
30 \usepackage{listings}
31 %\usepackage{xcolor}
32
33 \lstset{
34 language=[LaTeX]TeX,
35 basicstyle=\footnotesize\ttfamily,
36 upquote=true,
37 frame=single,
38 keywordstyle=\color{blue}\bfseries,
39 emphstyle=\color{blue}\bfseries,
40 backgroundcolor=\color{black!05},
41 fontadjust=true,
42 flexiblecolumns=true,
43 breaklines=true,
44 emph={ocg}
45 }
46
47 \newcommand{\TikZ}{Ti\emph{k}Z}
48
49 \newcommand*{\pkg}[1]{\textsf{#1}}
50 \newcommand*{\mail}[1]{\href{mailto:#1}{\texttt{#1}}}
51
52 \ifpdf
53 \pdfinfo{
54 /Author (DI Werner Moshammer)
55 /Title (The ocg-p package)
56 }
57 \fi
58
59 \title{The \pkg{ocg-p} package\thanks{This manual correspondends to \pkg{ocg-p} v0.4, dated 2013/01/10}}
60 \author{DI Werner Moshammer\thanks{Contact me when you find mistakes in the manual: \mail{[email protected]}}}
61 \date{2013/01/10}
62
63 \begin{document}
64
65 \maketitle
66
67 \tableofcontents
68
69
70
71 \begin{abstract}
72 The \pkg{ocg-p} package provides the environment that allows to insert OCG (Optional Content Group) into PDF documents without JavaScript. These OCGs can be simply described as layers from the user's point of view.
73
74 The \pkg{ocg-p} package is intended as a full replacement for the file |ocg.sty| which is part of the \pkg{asymptote} package. While |ocg.sty| is limited to be used with |pdfLaTeX|, the \pkg{ocg-p} package can also be used with |XeLaTeX|. Additionally nested OCGs (layers inside of another layer) are handled as such.
75
76 \end{abstract}
77 \newpage
78
79 \section{Introduction}
80 The \pkg{ocg-p} package provides the environment that allows to insert OCG (Optional Content Group) into PDF documents without JavaScript. These OCGs can be simply described as layers from the user's point of view.
81
82 OCGs are part of the PDF specification since version 1.5 and are described in the \href{http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/pdf_reference_archives/PDFReference15_v5.pdf}{PDF Reference} as:
83
84 \begin{quote}
85 Optional content (PDF 1.5) refers to sections of content in a PDF document that
86 can be selectively viewed or hidden by document authors or consumers. This capability
87 is useful in items such as CAD drawings, layered artwork, maps, and
88 multi-language documents.
89 \end{quote}
90
91 OCGs are not part of the ISO standard 19005 |PDF/A-1|, but part of the newer |PDF/A-2| standard.
92
93 The \pkg{ocg-p} package is intended as a full replacement for the file |ocg.sty| which is part of the \pkg{asymptote} package. While |ocg.sty| is limited to be used with |pdfLaTeX|, the \pkg{ocg-p} package can also be used with |XeLaTeX|. Additionally nested OCGs (layers inside of another layer) are handled as such.
94
95 \section{Usage}
96 Here is a quick summary of the usage of \pkg{ocg-p}. The package consists of one main environment to create layers and a few commands for buttons to change the visibility of the layers in some way.
97 Based on the ocg main environment there is an additionally environment available to create tables, which can be sorted by clicking on the headers.
98
99 \subsection{Download}
100 This package is available on CTAN\footnote{The Comprehensive \TeX{} Archive Network \url{http://www.ctan.org/}}:
101 \begin{description}
102 \item[\href{ftp://ftp.ctan.org/tex-archive/macros/latex/contrib/ocg-p/ocg-p.sty}{\texttt{CTAN: macros/latex/contrib/ocg-p/ocg-p.sty}}] The source file.
103 \item[\href{ftp://ftp.ctan.org/tex-archive/macros/latex/contrib/ocg-p/ocg-p.pdf}{\texttt{CTAN: macros/latex/contrib/ocg-p/ocg-p.pdf}}] Documentation.
104 \end{description}
105
106 \subsection{Package}
107 Just load the package placing
108 \begin{quote}
109 |\usepackage{ocg-p}|
110 \end{quote}
111 in the preamble of your \LaTeX{} source file. %There are no options available at the moment.
112 There is only one option available for the package, which can be used to offer an additional environment to create tables which can be sorted by clicking on the headers. In this case load the package with the following line:
113 \begin{quote}
114 |\usepackage[ocgtabular]{ocg-p}|
115 \end{quote}
116
117 Important: If packages are used, which use the original \pkg{ocg} package then \pkg{ocg-p} should be loaded after these packages. The |ocg| environment from the \pkg{ocg} package is replaced in this case.
118
119 The \pkg{ocg} package is using the auxiliary file, so it is maybe necessary to compile your document 2 - 3 times until all layers are shown properly.
120
121 %\subsection{Commands and Environments}
122 \subsection{The ocg environment}
123 %At the moment the \pkg{ocg-p} package has only one usable environment.
124 This is the main environment of the \pkg{ocg-p} package.
125 To create a OCG layer you have to use the |ocg| environment with three required arguments. Because it is intended as a replacement for the file |ocg.sty| this command can be used in the same way as it is used in |ocg.sty|.
126 \begin{verbatim}
127 \begin{ocg}{layer name}{layer id}{initial visibility}
128 content ...
129 \end{ocg}
130 \end{verbatim}
131 The arguments are:
132 \begin{itemize}
133 \item \textit{layer name}:
134 This name is shown in in the layer toolbar of the (PDF) viewer, where the visiblity of the layers can be changed.
135 \item \textit{layer id}:
136 A unique id which is internally used by the OCG environment to reference the layer. Only letters and numbers are allowed
137 \item \textit{initial visibility}:
138 Sets the initial visibility when the document is opend. Only 0 and 1 are allowed (0 for invisible, 1 for visible)
139 \item \textit{content}:
140 The content of the layer itself.
141 \end{itemize}
142
143 Beginning with \pkg{ocg-p} version 0.4 there are some optional options available to control the behaviour of the specified layer. Using this options the |ocg| environment is used the following way:
144 \begin{verbatim}
145 \begin{ocg}[opt1=val1, opt2=val2, ...]{layer name}{layer id}{initial visibility}
146 content ...
147 \end{ocg}
148 \end{verbatim}
149 The options are given in a comma separated list of optionname value pairs.
150 The usable options are:
151
152 \begin{center}\begin{tabular}{lp{9cm}}\hline
153 |printocg| & This option can be set to the values |always|, |never| and |ifvisible|. The default value is |ifvisible|. It specifies the visibility state of the content in this layer when the document is printed. |ifvisible| means that the layer is printed only if it is visible in the document. |always| means that it is printed always, independent from the current visiblity state in the document, and |never| means that is never printed.\\
154 |exportocg| & This option can be set to the values |always|, |never| and |ifvisible|. The default value is |ifvisible|. It specifies the state for the content in this layer when the document is exported or saved to a format that does not support layers. |ifvisible| means that the layer is exported only if it is visible in the document. |always| means that it is exported always independent from the current visiblity state in the document, and |never| means that is never exported.\\
155 |listintoolbar| & This option can be set to the values |always|, |never| and |iffirstuse|. The default value is |iffirstuse|. |iffirstuse| means that the layer is only displayed in the toolbar when it is first inserted. |always| means that it is displayed every time this layer is inserted again, and |never| means that the layer is never displayed in the toolbar. \\
156 \hline
157 \end{tabular}\end{center}
158
159 These options can be combined. So if you want for example that a layer can never be displayed in the document but is visible on a printing then you choose |listintoolbar=never|, |printocg=always| and a initial visible of |0| (invisible).
160
161 Important: Nested layers do not work with layers which are not visible in the layer toolbar of the browser.
162
163 \subsection{The commands of the package}
164 Beginning with \pkg{ocg-p} version 0.4 there are a few additional commands available. These commands can be used to add link actions (buttons) to the document, so that the visibility of some layers can be changed in some way.
165 In all commands the |ocg|/|layer ids| should be given in a space separated list, and the last argument is for the link object itself.
166 By default the link object is used by clicking with the mouse on it (mouseup event). But this behaviour can be changed by the optional options.
167
168 The command |toggleocg| can be used to toggle the visible of the given layers i the document.
169 \begin{verbatim}
170 \toggleocgs[optional options]{tlayerid1 tlayerid2 ...}{display}
171 \end{verbatim}
172
173 The command |showocgs| can be used to make the given layers visible in the document.
174 \begin{verbatim}
175 \showocgs[optional options]{slayerid1 slayerid2 ...}{display}
176 \end{verbatim}
177
178 The command |hideocgs| can be used to make the given layers invisible in the document.
179 \begin{verbatim}
180 \hideocgs[optional options]{hlayerid1 hlayerid2 ...}{display}
181 \end{verbatim}
182
183 The command |setocgs| is a combination of the former commands. With |setocgs| it is possible to toggle some layers given as first argument list, to make some layers visible which are given in the second argument list and to make some layers invisible given in the third argument list.
184
185 \begin{verbatim}
186 \setocgs[optional options]{tlayerid1 tlayerid2 ...}
187 {slayerid1 slayerid2 ...}{hlayerid1 hlayerid2 ...}{display}
188 \end{verbatim}
189
190 There is one optional option availabe for all these commands, called |triggerocg|. These option can be set to the following values:
191 \begin{center}\begin{tabular}{lp{9cm}}\hline
192 |onareaenter| & Using this value the action is performed by entering the link area with the cursor (a mousover effect).\\
193 |onareaexit| & Using this value the action is performed when the cursor exits the link area (a mouseout effect).\\
194 |onmousedown| & Using this value the action is performed when the mouse button is pressed inside the link area (a mousedown effect).\\
195 |onmouseup| & Using this value the action is performed when the mouse button isreleased inside the link area (a mouseup effect). |onmouseup| is the default value.\\
196 |allactions| & When this option is used all four trigger events can be used with different ocgs at the same time. To do this four lists of layer ids have to be given in the arguments of the commands. While one ocg layer id list is given as a space separated list, these lists should be comma separated.\\
197 & For example:\\
198 & \verb+\toggleocgs[triggerocg=allactions]+\\ & \verb+ {aenid1 aenid2,aexid1,mdid1,muid1}[display}+ \\
199 & The first list is for mouseover, the second for mouseout the third for mousedown and the last list for mouseup actions.\\
200 & Another example where only mouseenter and mousedown actions are used:\\
201 & \verb+\toggleocgs[triggerocg=allactions]+\\ & \verb+ {aenid1 aenid2,,mdid1 mdid2}+\\
202 \hline
203 \end{tabular}\end{center}
204
205 Important: It is not possible to make an action area inside of another action layer.
206
207 %The |ocg|/|layer ids| in all commands should be given in a space separated list. With |setocgs| it is possible to toggle some layers given as first argument list, to make some layers visible which are given in the second argument list and to make some layers invisible given in the third argument list. The last argument is for the link object itself. The commands |toggleocgs|, |showocgs| and |hideocgs| can be used in the same way, but they are used only for one of the actions.
208 \newpage
209 \subsection{The ocgtabular environment}
210 The purpose of the |ocgtabular| environment is to create tables which can be sorted by clicking on the headers. This environment should also show how the main |ocg| environment can be used to create another environment which can be useful.
211
212 To use the |ocgtabular| environmet the package option |ocgtabular| has to be used. In this way additional packages are imported which are necessary for this environment. The |ocgtabular| uses the original |tabular| package to create tables, where the data of the tables must be given in a database which is provided by the |datatool| package.
213
214 \begin{verbatim}
215 \begin{ocgtabular}[original tabular options]{original tabular argument}{ocgtabular options}
216 {datatool database name}
217 ... original tabular/datatool code ...
218 \end{ocgtabular}
219 \end{verbatim}
220
221 So the only difference to the |tabular| environment are the last two arguments where in the first the name of the database is given. This database is used to sort the data. The last argument is for additional options, but there are no options available at the moment.
222
223 For the header there is an addtional command available, but only inside of this environment.
224
225 \begin{verbatim}
226 \setocgtabularheader{columnname}{displayed header}
227 \end{verbatim}
228
229 The |columnname| is the name of the column in the datatool database and |displayed header| is the text which is shown.
230
231 An example of this environment and its command is given in the following examples sections.
232
233 \newpage
234 \section{Examples}
235 A few examples follow, showing the usage of this package.
236
237 \subsection{Example 1: Three simple text layers}
238 Here is a simple example with three layers with text content, where the second layer is set invisible when the document is opened. These commands are:
239
240 \begin{lstlisting}
241 \documentclass{article}
242 \usepackage{ocg-p}
243 \begin{document}
244
245 \begin{ocg}{First layer}{oc1}{1}
246 The first Layer is visible at start.
247 \end{ocg}
248
249 \begin{ocg}{Second layer}{oc2}{0}
250 The second layer is not visible at start.
251 \end{ocg}
252
253 \begin{ocg}{Third layer}{oc3}{1}
254 The third layer is visible at start.
255 \end{ocg}
256
257 This text is not inside of a layer and always visible.
258
259 \end{document}
260 \end{lstlisting}
261
262 This will produce the following output, where the text in the second layer is invisible when the document is opend:
263 \begin{framed}
264
265 The first Layer is visible at start.
266
267 \makebox[1pt][l]{ }
268
269 The third layer is visible at start.
270
271 This text is not inside of a layer and always visible.
272
273 \end{framed}
274
275 The visiblity of the three layers can be changed with the layer toolbar of the viewer. If all layers are made invisible it looks like that:
276
277 \begin{framed}
278
279 \makebox[1pt][l]{ }
280
281 \makebox[1pt][l]{ }
282
283 \makebox[1pt][l]{ }
284
285 \makebox[1pt][l]{ }
286
287 This text is not inside of a layer and always visible.
288
289 \end{framed}
290
291 \newpage
292 \subsection{Example 2: OGC and the \TikZ{} package}
293 Using the \pkg{ocg-p} package with the \pkg{Ti\emph{k}Z} package is very valuable, because it is possible to show or hide some parts of the picture with the layer toolbar of the viewer. Here a first code example:
294
295 \begin{lstlisting}
296 \begin{tikzpicture}[node distance=3cm,every state/.style={fill=green!20},auto]
297 \begin{ocg}{grid}{ocgridid}{1}
298 \draw[black!20] (-1,-1) grid (4,2);
299 \end{ocg}
300
301 \begin{ocg}{states}{ocstatesid}{1}
302 \node[state] (q_a) {$q_a$};
303 \node[state] (q_b) [right of=q_a] {$q_b$};
304 \end{ocg}
305
306 \begin{ocg}{edges}{ocedgesid}{1}
307 \path[->]
308 (q_a) edge node {0} (q_b)
309 edge [loop above] node {0} ()
310 (q_b) edge [loop above] node {1} ();
311 \end{ocg}
312 \end{tikzpicture}
313 \end{lstlisting}
314
315 When the document is opend the following is shown:
316
317 \begin{framed}
318 \begin{tikzpicture}[node distance=3cm,every state/.style={fill=green!20},auto]
319 \draw[black!20] (-1,-1) grid (4,2);
320 \node[state] (q_a) {$q_a$};
321 \node[state] (q_b) [right of=q_a] {$q_b$};
322 \path[->]
323 (q_a) edge node {0} (q_b)
324 edge [loop above] node {0} ()
325 (q_b) edge [loop above] node {1} ();
326 \end{tikzpicture}
327 \end{framed}
328
329 But, for example, the edges could be made invisible with the layer toolbar:
330 \begin{framed}
331 \begin{tikzpicture}[node distance=3cm,every state/.style={fill=green!20},auto]
332 \draw[black!20] (-1,-1) grid (4,2);
333 \node[state] (q_a) {$q_a$};
334 \node[state] (q_b) [right of=q_a] {$q_b$};
335 \end{tikzpicture}
336 \end{framed}
337
338 Or the grid could be made invisible:
339 \begin{framed}
340 \begin{tikzpicture}[node distance=3cm,every state/.style={fill=green!20},auto]
341 \draw[white!0] (-1,-1) grid (4,2);
342 \node[state] (q_a) {$q_a$};
343 \node[state] (q_b) [right of=q_a] {$q_b$};
344 \path[->]
345 (q_a) edge node {0} (q_b)
346 edge [loop above] node {0} ()
347 (q_b) edge [loop above] node {1} ();
348 \end{tikzpicture}
349 \end{framed}
350
351
352 \subsection{Example 3: OGC and the \TikZ{} package again}
353 These example should show how the layers can be used within text.
354 \begin{lstlisting}
355 The following text can be toggled:
356 \begin{tikzpicture}[baseline=0]
357 \tikzstyle{nome}=[anchor=base,outer sep=0,inner sep=0,minimum height=.45cm,minimum width=4.4cm]
358 \begin{ocg}{blue text}{ocblueid}{1}
359 \node[nome,blue] (p1) {\parbox[b][][t]{4.4cm}{This text is written in blue.}};
360 \end{ocg}
361 \begin{ocg}{red text}{ocredid}{0}
362 \node[overlay,nome,red] (p2) {\parbox[b][][t]{4.4cm}{This text is written in red.}};
363 \end{ocg}
364 \end{tikzpicture}
365 And now the text is black again.
366 \end{lstlisting}
367
368 With the layer toolbar of the viewer it is possible to activate or deactivate the two layers, so there are three possibilities how it can be seen:
369 \begin{framed}
370 \noindent The following text can be toggled: \parbox[b][][t]{4.4cm}{\textcolor{blue}{This text is written in blue.}} And now the text is black again.
371 \end{framed}
372
373 \begin{framed}
374 \noindent The following text can be toggled: \parbox[b][][t]{4.4cm}{\textcolor{red}{This text is written in red.}} And now the text is black again.
375 \end{framed}
376
377
378
379
380 \begin{framed}
381 \noindent The following text can be toggled:
382 \begin{tikzpicture}[baseline=0]
383 \tikzstyle{nome}=[anchor=base,outer sep=0,inner sep=0,minimum height=.45cm,minimum width=4.4cm]
384 \node[nome,blue] (p1) {\parbox[b][][t]{4.4cm}{This text is written in blue.}};
385 \node[overlay,nome,red] (p2) {\parbox[b][][t]{4.4cm}{This text is written in red.}};
386 \end{tikzpicture}
387 And now the text is black again.
388 \end{framed}
389
390 \newpage
391 \subsection{Example 4: OGC and link actions (buttons)}
392 Combining the \pkg{Ti\emph{k}Z} package with buttons to show, hide, toggle or set the layers adds much possibilities how this package can be used. Here is a way to show, how a table can be made, which can be sorted by clicking on the headers.
393
394 \begin{lstlisting}
395 \usepackage{ocg-p}
396 \usepackage{tikz} % will be needed for this example
397 \usepackage{datatool} % will be needed for this example
398 \usepackage{booktabs} % will be needed for this example
399
400 .
401 .
402 .
403
404 % generate database with data for the table
405 \DTLnewdb{sdata}
406 \DTLnewrow{sdata}
407 \DTLnewdbentry{sdata}{Firstname}{John}
408 \DTLnewdbentry{sdata}{Lastname}{Doe}
409 \DTLnewdbentry{sdata}{Grade}{5}
410 \DTLnewrow{sdata}
411 \DTLnewdbentry{sdata}{Firstname}{Paul}
412 \DTLnewdbentry{sdata}{Lastname}{Bauer}
413 \DTLnewdbentry{sdata}{Grade}{1}
414 \DTLnewrow{sdata}
415 \DTLnewdbentry{sdata}{Firstname}{Peggy}
416 \DTLnewdbentry{sdata}{Lastname}{Sue}
417 \DTLnewdbentry{sdata}{Grade}{3}
418 \DTLnewrow{sdata}
419 \DTLnewdbentry{sdata}{Firstname}{Ever}
420 \DTLnewdbentry{sdata}{Lastname}{Last}
421 \DTLnewdbentry{sdata}{Grade}{4}
422 \DTLnewrow{sdata}
423 \DTLnewdbentry{sdata}{Firstname}{Werner}
424 \DTLnewdbentry{sdata}{Lastname}{Moshammer}
425 \DTLnewdbentry{sdata}{Grade}{1}
426
427 This table can be sorted by clicking on the headers:
428
429 \begin{tikzpicture}
430 \begin{ocg}{First Name}{ocfirstid}{0}
431 \node[] (p1) {
432 \begin{tabular}{llc}
433 \toprule
434 \bfseries \setocgs{}{ocfirstid}{oclastid ocgradeid}{First name}
435 & \bfseries \setocgs{}{oclastid}{ocfirstid ocgradeid}{Last name}
436 & \bfseries \setocgs{}{ocgradeid}{ocfirstid oclastid}{Grade}
437 \DTLsort*{Firstname}{sdata}% sorted on the first name
438 \DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{%
439 \DTLiffirstrow{\\ \midrule}{\\}
440 \first & \last & \grade
441 }
442 \\ \bottomrule
443 \end{tabular}
444 };
445 \end{ocg}
446
447 \begin{ocg}{First Name}{oclastid}{1}
448 \node[overlay] (p2) {
449 \begin{tabular}{llc}
450 \toprule
451 \bfseries \setocgs{}{ocfirstid}{oclastid ocgradeid}{First name}
452 & \bfseries \setocgs{}{oclastid}{ocfirstid ocgradeid}{Last name}
453 & \bfseries \setocgs{}{ocgradeid}{ocfirstid oclastid}{Grade}
454 \DTLsort*{Lastname}{sdata}% sorted on the last name
455 \DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{%
456 \DTLiffirstrow{\\ \midrule}{\\}
457 \first & \last & \grade
458 }
459 \\ \bottomrule
460 \end{tabular}
461 };
462 \end{ocg}
463
464 \begin{ocg}{First Name}{ocgradeid}{0}
465 \node[overlay] (p3) {
466 \begin{tabular}{llc}
467 \toprule
468 \bfseries \setocgs{}{ocfirstid}{oclastid ocgradeid}{First name}
469 & \bfseries \setocgs{}{oclastid}{ocfirstid ocgradeid}{Last name}
470 & \bfseries \setocgs{}{ocgradeid}{ocfirstid oclastid}{Grade}
471 \DTLsort*{Grade}{sdata}% sorted on the grade
472 \DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{%
473 \DTLiffirstrow{\\ \midrule}{\\}
474 \first & \last & \grade
475 }
476 \\ \bottomrule
477 \end{tabular}
478 };
479 \end{ocg}
480
481 \end{tikzpicture}
482 \end{lstlisting}
483
484 \DTLnewdb{sdata}
485 \DTLnewrow{sdata}
486 \DTLnewdbentry{sdata}{Firstname}{John}
487 \DTLnewdbentry{sdata}{Lastname}{Doe}
488 \DTLnewdbentry{sdata}{Grade}{5}
489 \DTLnewrow{sdata}
490 \DTLnewdbentry{sdata}{Firstname}{Paul}
491 \DTLnewdbentry{sdata}{Lastname}{Bauer}
492 \DTLnewdbentry{sdata}{Grade}{1}
493 \DTLnewrow{sdata}
494 \DTLnewdbentry{sdata}{Firstname}{Peggy}
495 \DTLnewdbentry{sdata}{Lastname}{Sue}
496 \DTLnewdbentry{sdata}{Grade}{3}
497 \DTLnewrow{sdata}
498 \DTLnewdbentry{sdata}{Firstname}{Ever}
499 \DTLnewdbentry{sdata}{Lastname}{Last}
500 \DTLnewdbentry{sdata}{Grade}{4}
501 \DTLnewrow{sdata}
502 \DTLnewdbentry{sdata}{Firstname}{Werner}
503 \DTLnewdbentry{sdata}{Lastname}{Moshammer}
504 \DTLnewdbentry{sdata}{Grade}{1}
505
506 The output is the following table:
507
508 \begin{framed}
509 This table can be sorted by clicking on the headers:
510
511 \begin{tabular}{llc}
512 \toprule
513 \bfseries First name & \bfseries Last name& \bfseries Grade
514 \DTLsort*{Lastname}{sdata}% sorted on the Last name
515 \DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{%
516 \DTLiffirstrow{\\ \midrule}{\\}
517 \first & \last & \grade
518 }
519 \\ \bottomrule
520 \end{tabular}
521 \end{framed}
522
523 By clicking on |Grade| in the header the table changes the sorting and looks then as follows:
524
525 \begin{framed}
526 This table can be sorted by clicking on the headers:
527
528 \begin{tabular}{llc}
529 \toprule
530 \bfseries First name & \bfseries Last name& \bfseries Grade
531 \DTLsort*{Grade}{sdata}% sorted on the grade
532 \DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{%
533 \DTLiffirstrow{\\ \midrule}{\\}
534 \first & \last & \grade
535 }
536 \\ \bottomrule
537 \end{tabular}
538 \end{framed}
539
540 \subsection{Example 5: The ocgtabular environment}
541 This example does the same as the last but now by using the ocgtabular environment.
542
543 \begin{lstlisting}
544 \usepackage[ocgtabular]{ocg-p}
545 \usepackage{datatool} % will be needed for this example
546 \usepackage{booktabs} % will be needed for this example
547
548 .
549 .
550 .
551
552 % generate database with data for the table
553 \DTLnewdb{sdata}
554 \DTLnewrow{sdata}
555 \DTLnewdbentry{sdata}{Firstname}{John}
556 \DTLnewdbentry{sdata}{Lastname}{Doe}
557 \DTLnewdbentry{sdata}{Grade}{5}
558 \DTLnewrow{sdata}
559 \DTLnewdbentry{sdata}{Firstname}{Paul}
560 \DTLnewdbentry{sdata}{Lastname}{Bauer}
561 \DTLnewdbentry{sdata}{Grade}{1}
562 \DTLnewrow{sdata}
563 \DTLnewdbentry{sdata}{Firstname}{Peggy}
564 \DTLnewdbentry{sdata}{Lastname}{Sue}
565 \DTLnewdbentry{sdata}{Grade}{3}
566 \DTLnewrow{sdata}
567 \DTLnewdbentry{sdata}{Firstname}{Ever}
568 \DTLnewdbentry{sdata}{Lastname}{Last}
569 \DTLnewdbentry{sdata}{Grade}{4}
570 \DTLnewrow{sdata}
571 \DTLnewdbentry{sdata}{Firstname}{Werner}
572 \DTLnewdbentry{sdata}{Lastname}{Moshammer}
573 \DTLnewdbentry{sdata}{Grade}{1}
574
575 This table can be sorted by clicking on the headers:
576
577 \begin{ocgtabular}{llc}{sdata}{}
578 \toprule%
579 \bfseries \setocgtabularheader{Firstname}{First name}
580 & \bfseries \setocgtabularheader{Lastname}{Last name}
581 & \bfseries \setocgtabularheader{Grade}{Grade}
582 \DTLforeach{sdata}{\first=Firstname, \last=Lastname,\grade=Grade}{%
583 \DTLiffirstrow{\\ \midrule}{\\}
584 \first & \last & \grade
585 }
586 \\ \bottomrule%
587 \end{ocgtabular}
588
589 \end{lstlisting}
590
591 \section{Possible future developement}
592
593 These ideas may appear in new versions of the \pkg{ocg-p} package:
594
595 \begin{itemize}
596 \item The package should work with dvips. There is still something wrong at the moment.
597 %\item The |ocg| environment should accept options like |notprintable|, |alwaysprinted|, |notinlayertoolbar| (means that the visiblity is not changeable), |%notexportable|, |alwaysexported|.
598 %So it is for example possible that a layer is not visible but is printed.
599 %\item Commands for buttons which make all layers visible or invisible.
600 \item The package should use |.dtx| instead of |.sty|.
601 \item Radio Button Groups (/RBGroups) %/RBGroups [[ 11 0 R 13 0 R]] /ON[ 11 0 R] /OFF [13 0 R]
602 \end{itemize}
603
604
605 \section{Implementation}
606 The implementation is rather standard. At first main switches are defined to distinguish between the possible drivers |pdfLaTeX|, |XeLaTeX| and |dvips| (not fully implemented yet). Then the environment is defined.
607
608
609 \lstinputlisting[firstline=1, lastline=500]{ocg-p.sty}
610
611 %\VerbatimInput[fontsize=\footnotesize,firstline=1,lastline=320]{ocg-p.sty}
612
613
614 \section{Change history}
615
616 \begin{description}
617 \item[0.1] Initial version, only usable with |XeLaTeX|, not based on the \pkg{ocg} package and therefore the arguments were a little bit different.
618
619 \item[0.2] The \pkg{ocg-p} package was made compatible with the \pkg{ocg} package using the same environment name and arguments and using the |aux| file in the same way. Support for |pdfLaTeX| was added. First public version.
620
621 \item[0.3] Fixed bug in |ocg| environment (missing \verb+\fi+). Fixed a bug if |XeLaTeX| is used. Nestes OCGs (layers inside another layer) are now handled as such.
622
623 \item[0.4] Removed unnecessary \verb+\makeatletter+ and \verb+\makeatother+ commands, fixed an issue with the |beamer| class under |XeLaTeX| and other minor bugfixes. New options in the |ocg| environment. New commands for actions. New |ocgtabular| environment.
624
625 \item[0.5] Planned: Not in a |.sty| file anymore, now using |.dtx|.
626
627 \end{description}
628
629
630 \end{document}