Debian Codegraph @

texmf-dist/doc/optex/pdfextra/examples/pdfextra-example-latex.tex

raw
1 % Compiled with:
2 % env TEXMFDOTDIR='..//:~/src/texlive/texmf-dist/source/latex/media9/files/' lualatex pdfextra-example-latex.tex
3 \documentclass{article}
4
5 \usepackage{hyperref}
6 \usepackage{xcolor}
7 \usepackage{graphicx}
8 \usepackage{pdfextra}
9 \sdef{_linkcolor}{\color{blue}}
10
11 \begin{document}
12
13 % Using document level JavaScript we can run initialization code right at the
14 % start (this is more flexible than \openaction).
15 \dljavascript[random]{
16 function getRandomNumber() {
17 return 4; % chosen by fair dice roll, ![https://xkcd.com/221/]
18 }
19 console.println("initialized with seed " + getRandomNumber());
20 }
21
22
23
24 % For external references we need to `\filedef` "external" and "url" files
25 % beforehand:
26 \filedef/u[doc-internet]{http://petr.olsak.net/ftp/olsak/optex/optex-doc.pdf}
27 \filedef/x[doc-local]{optex-doc.pdf}
28
29 % We then try to reference them using external references:
30 \hlink[extref:doc-internet:ref:langphrases]{OpTeX documentation, section ``Multilingual phrases and quotation marks''.}
31 \hlink[extpgref:doc-internet:12]{OpTeX documentation, page 12.}
32
33
34
35 % Insert a video twice with different settings:
36 \filedef/e[video]{example-movie.mp4}
37 % Insert video into page using Renditions mechanism with controls and autoplay.
38 \render[video][
39 controls=true,
40 aactions=\renditionautoplay,
41 ]{\includegraphics[width=\textwidth]{example-image.pdf}}
42
43 % We set red text color, blue border (RGB triplet) for "rendition" links.
44 \sdef{_renditionlinkcolor}{\color{red}}
45 \sdef{_renditionborder}{0 1 0}
46 % Then we add some buttons.
47 \hlink[rendition::play]{play} \hlink[rendition::pause]{pause}
48 \hlink[rendition::stop]{stop} \hlink[rendition::resume]{resume}
49
50 % Render the same file again, but with different dimensions, no controls
51 % and explicit activation.
52 \render[video]{\includegraphics{example-image.pdf}}
53 % This one can't have buttons, because it doesn't have its own name -- "video"
54 % is used by the previous one.
55
56
57
58 % Add already embedded video to the list of attachments shown in user
59 % interface.
60 \attach[video]
61
62
63 % We are done for this page, who not go to the next one?
64 %
65 % \hlink typesets in group, so we locally disable lining links (our button is
66 % bigger than normal line)
67 \hlink[named:NextPage]{\nolininglinks\scalebox{2}[2]{NEXT PAGE}}
68
69
70
71 \clearpage
72
73
74
75 % Deliver fresh random number to everyone who sees this page using "page open"
76 % ("O") trigger event of page's actions.
77 \pageactions[
78 {O} {js:{app.alert("Random number for you is " + getRandomNumber());}}
79 ]
80
81
82 % Link to previous page (predefined PDF action) with "Split" transition:
83 \hlink[named:PrevPage, transition:Split]{Go to previous page (with transition).}
84
85
86
87 \clearpage
88
89 % A 3D Rich Media annotation with a custom view and script follows:
90
91 % First we define the 3D file, so we can use same name for the view and have it
92 % auto included.
93 \filedef/e[example]{pdfextra-example-part.prc}
94
95 % Then a simplistic "front" view.
96 \DDDview[example][
97 projection=ortho,
98 roo=400,
99 ]
100
101 % A 3D JavaScript script that will define function to use with action button.
102 % (we write the script only now, so we don't have to carry around an extra file
103 % in the package, you would normally have the contents in the file -- "turn.js"
104 % in this case).
105 \newwrite\js
106 \immediate\openout\js=turn.js
107 % rotate every node by angle degrees along $x$ axis
108 \immediate\write\js{\detokenize{
109 function turn(angle) {
110 angle = angle * Math.PI / 180;
111 for (var i = 0; i < scene.nodes.count; i++) {
112 var node = scene.nodes.getByIndex(i);
113 node.transform.rotateAboutXInPlace(angle);
114 }
115 }
116 }}
117 \closeout\js
118
119 % The annotation itself, with our script above.
120 \RM[example][
121 activation=auto,
122 scripts=turn.js,
123 ]{\textcolor{white}{\vrule width\textwidth height\textwidth}}
124
125 \hlink[js:\DDDcontext{example}.turn(10);]{Turn by 10 degrees along $x$ axis.}\par
126 \hlink[js:\DDDcontext{example}.turn(30);]{Turn by 30 degrees along $x$ axis.}\par
127 \hlink[js:\DDDcontext{example}.turn(90);]{Turn by 90 degrees along $x$ axis.}
128
129
130
131 \clearpage
132
133
134 % Here is the "epix" 3D model example from media9 documentation ported to
135 % pdfextra.
136 %
137 % First we define a view with the same name as the future Rich Media
138 % annotation. This view will then automatically be used if no `views` key is
139 % specified. No need to be excessive with decimal numbers.
140 \DDDview[epix][
141 FOV=30,
142 c2c=4 2 3,
143 coo=4.41 2.19 0,
144 roo=430,
145 ]
146
147 % 3Dmenu is used often, lets use shortcut instead.
148 \filedef/e[3dmenu]{3Dmenu.js}
149 % We want to use the nice "epix" name for the view and annotation.
150 \filedef/e[epix]{epix.prc}
151
152 % Just to spice things up, we diverge a bit from media9 and define custom
153 % background color. We can't use LaTeX's colors, so we use RGB triplet.
154 \newcommand{\GreyBG}{0.9 0.9 0.9}
155
156 % Define the 3D Rich Media annotation. One view is automatically detected from
157 % name ("epix"). Scripts will run in specified order at initialization time
158 % (when the annotation is activated).
159 \RM[epix][
160 scripts={
161 asylabels.js,
162 3Dspintool.js,
163 3dmenu,
164 },
165 background=\GreyBG,
166 ]{\includegraphics[width=0.8\textwidth, height=0.8\textwidth]{epixposter.pdf}}
167
168
169
170 \clearpage
171
172
173
174 % Second media9 example is "dice" it has a lot of views, but they are simple.
175 % This time we can't use the view name deduction from `\RM` name -- there is
176 % more than one view.
177 \DDDview[Front][roo=27]
178 \DDDview[Back][roo=27, c2c=0 1 0]
179 \DDDview[Left][roo=27, c2c=-1 0 0]
180 \DDDview[Right][roo=27, c2c=1 0 0]
181 \DDDview[Top][roo=27, c2c=0 0 1]
182 \DDDview[Bottom][roo=27, c2c=0 0 -1]
183 \DDDview[Fish Eye at Centre][fov=120]
184
185 % We want to use all the defined views, as well as autoactivate the annotation.
186 % This means that the preview mostly sets dimensions, because it will not be
187 % shown much. (Only in viewers that don't support 3D Rich Media -- that is, all
188 % except Acrobat).
189 \RM[dice.u3d][
190 views={Front, Back, Left, Right, Top, Bottom, Fish Eye at Centre},
191 activation=auto,
192 scripts=3dmenu,
193 ]{\textcolor{red}{\vrule height.5\textwidth width.5\textwidth}}
194
195 % A few buttons for switching views.
196 \hlink[goto3dview::/N]{\frame{Next view}}
197 \hlink[goto3dview::(Back)]{\frame{View ``Back''}}
198 \hlink[goto3dview::5]{\frame{6th view in the list}}
199
200 \clearpage
201
202
203 % Last media9 example ported. It has its own JavaScript file for animation,
204 % which can be customized at runtime using JavaScript actions that access 3D
205 % context of the annotation.
206 \filedef/e[malte]{malte.u3d}
207 \DDDview[malte][c2c=1 1 1, roo=0.25]
208 \RM[malte][
209 activation=auto,
210 scripts={3dmenu, malte.js},
211 ]{\textcolor{blue}{\vrule height 0.5\textwidth width 0.5\textwidth}}
212
213 % Normal JavaScript actions, but we access functions defined globaly in the 3D
214 % JavaScript context of "malte" Rich Media annotation.
215 \hlink[js:\DDDcontext{malte}.cntrClockWise();] {\includegraphics[height=1.44em]{boutona.pdf}}
216 \hlink[js:\DDDcontext{malte}.pause();] {\includegraphics[height=1.44em]{boutonb.pdf}}
217 \hlink[js:\DDDcontext{malte}.clockWise();] {\includegraphics[height=1.44em]{boutonc.pdf}}
218 \hlink[js:\DDDcontext{malte}.scaleSpeed(1/1.1);]{\includegraphics[height=1.44em]{boutond.pdf}}
219 \hlink[js:\DDDcontext{malte}.origSpeed();] {\includegraphics[height=1.44em]{boutone.pdf}}
220 \hlink[js:\DDDcontext{malte}.scaleSpeed(1.1);] {\includegraphics[height=1.44em]{boutonf.pdf}}
221
222
223 \end{document}