Debian Codegraph @

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

raw
1 % PDFextra example file.
2 % This file, apart from other topics, shows how to port 3D examples from media9
3 % (https://ctan.org/pkg/media9) documentation. You probably have to adjust path
4 % searching to succesfully compile this example, e.g.:
5 %
6 % \begtt
7 % env TEXMFDOTDIR=.:~/src/texlive/texmf-dist/source/latex/media9/files/ optex pdfextra-example.tex
8 % \endtt
9
10 % Basic \OpTeX/ settings:
11 \enlang\enquotes
12 \fontfam[lm]
13
14 % Load the package from standard search path:
15 \load[pdfextra]
16
17 % Before using \hlink we must activate hyperlinks:
18 \hyperlinks\Blue\Green
19
20 % Maybe we want to greet the user and jump to page 2 right at the start?
21 \openaction[
22 js:{%
23 app.alert("Javascript alert, open action");
24 console.println("printing to console from openaction");},
25 pg:2,
26 ]
27
28
29
30 % Using document level JavaScript we can run initialization code right at the
31 % start (this is more flexible than \openaction).
32 \dljavascript[random]{
33 function getRandomNumber() {
34 return 4; % chosen by fair dice roll, ![https://xkcd.com/221/]
35 }
36 console.println("initialized with seed " + getRandomNumber());
37 }
38
39
40
41 % For external references we need to `\filedef` "external" and "url" files
42 % beforehand:
43 \filedef/u[doc-internet]{http://petr.olsak.net/ftp/olsak/optex/optex-doc.pdf}
44 \filedef/x[doc-local]{optex-doc.pdf}
45
46 % We then try to reference them using external references:
47 \hlink[extref:doc-internet:ref:langphrases]{OpTeX documentation, section \"Multilingual phrases and quotation marks".}
48 \hlink[extpgref:doc-internet:12]{OpTeX documentation, page 12.}
49
50
51
52 % Insert a video twice with different settings:
53 \filedef/e[video]{example-movie.mp4}
54 % Insert video into page using Renditions mechanism with controls and autoplay.
55 \render[video][
56 controls=true,
57 aactions=\renditionautoplay,
58 ]{\picwidth=\hsize \inspic{example-image.pdf}}
59
60 % We set red text color, blue border (RGB triplet) for "rendition" links.
61 \let\_renditionlinkcolor\Red
62 \def\_renditionborder{0 1 0}
63 % Then we add some buttons.
64 \hlink[rendition::play]{play} \hlink[rendition::pause]{pause}
65 \hlink[rendition::stop]{stop} \hlink[rendition::resume]{resume}
66
67 % Render the same file again, but with different dimensions, no controls
68 % and explicit activation.
69 \render[video]{\inspic{example-image.pdf}}
70 % This one can't have buttons, because it doesn't have its own name -- "video"
71 % is used by the previous one.
72
73
74
75 % Add already embedded video to the list of attachments shown in user
76 % interface.
77 \attach[video]
78
79
80 % We are done for this page, who not go to the next one?
81 %
82 % \hlink typesets in group, so we locally disable lining links (our button is
83 % bigger than normal line)
84 \hlink[named:NextPage]{\nolininglinks\typoscale[2000/2000]\inoval{NEXT PAGE}}
85
86
87
88 \vfil\break
89
90
91
92 % Deliver fresh random number to everyone who sees this page using "page open"
93 % ("O") trigger event of page's actions.
94 \pageactions[
95 {O} {js:{app.alert("Random number for you is " + getRandomNumber());}}
96 ]
97
98 % Link to OpTeX's page reference ("pg:1") with "Split" transition:
99 \hlink[pg:1, transition:Split]{Go to previous page (with transition).}
100
101
102
103 \vfil\break
104
105 % A 3D Rich Media annotation with a custom view and script follows:
106
107 % First we define the 3D file, so we can use same name for the view and have it
108 % auto included.
109 \filedef/e[example]{pdfextra-example-part.prc}
110
111 % Then a simplistic "front" view.
112 \DDDview[example][
113 projection=ortho,
114 roo=400,
115 ]
116
117 % A 3D JavaScript script that will define function to use with action button.
118 % (we write the script only now, so we don't have to carry around an extra file
119 % in the package, you would normally have the contents in the file -- "turn.js"
120 % in this case).
121 \newwrite\js
122 \immediate\openout\js=turn.js
123 % rotate every node by angle degrees along $x$ axis
124 \immediate\write\js{\detokenize{
125 function turn(angle) {
126 angle = angle * Math.PI / 180;
127 for (var i = 0; i < scene.nodes.count; i++) {
128 var node = scene.nodes.getByIndex(i);
129 node.transform.rotateAboutXInPlace(angle);
130 }
131 }
132 }}
133 \closeout\js
134
135 % The annotation itself, with our script above.
136 \RM[example][
137 activation=auto,
138 scripts=turn.js,
139 ]{\White\vrule width\hsize height\hsize}
140
141 \hlink[js:\DDDcontext{example}.turn(10);]{Turn by 10 degrees along $x$ axis.}\par
142 \hlink[js:\DDDcontext{example}.turn(30);]{Turn by 30 degrees along $x$ axis.}\par
143 \hlink[js:\DDDcontext{example}.turn(90);]{Turn by 90 degrees along $x$ axis.}
144
145
146
147 \vfil\break
148
149
150 % Here is the "epix" 3D model example from media9 documentation ported to
151 % pdfextra.
152 %
153 % First we define a view with the same name as the future Rich Media
154 % annotation. This view will then automatically be used if no `views` key is
155 % specified. No need to be excessive with decimal numbers.
156 \DDDview[epix][
157 FOV=30,
158 c2c=4 2 3,
159 coo=4.41 2.19 0,
160 roo=430,
161 ]
162
163 % 3Dmenu is used often, lets use shortcut instead.
164 \filedef/e[3dmenu]{3Dmenu.js}
165 % We want to use the nice "epix" name for the view and annotation.
166 \filedef/e[epix]{epix.prc}
167
168 % Just to spice things up, we diverge a bit from media9 and define custom
169 % background color.
170 \colordef\GreyBG{0.1\Black}
171
172 % Define the 3D Rich Media annotation. One view is automatically detected from
173 % name ("epix"). Scripts will run in specified order at initialization time
174 % (when the annotation is activated).
175 \RM[epix][
176 scripts={
177 asylabels.js,
178 3Dspintool.js,
179 3dmenu,
180 },
181 background=\GreyBG,
182 ]{\picwidth=0.8\hsize \picheight=0.8\hsize \inspic{epixposter.pdf}}
183
184
185
186 \vfil\break
187
188
189
190 % Second media9 example is "dice" it has a lot of views, but they are simple.
191 % This time we can't use the view name deduction from `\RM` name -- there is
192 % more than one view.
193 \DDDview[Front][roo=27]
194 \DDDview[Back][roo=27, c2c=0 1 0]
195 \DDDview[Left][roo=27, c2c=-1 0 0]
196 \DDDview[Right][roo=27, c2c=1 0 0]
197 \DDDview[Top][roo=27, c2c=0 0 1]
198 \DDDview[Bottom][roo=27, c2c=0 0 -1]
199 \DDDview[Fish Eye at Centre][fov=120]
200
201 % We want to use all the defined views, as well as autoactivate the annotation.
202 % This means that the preview mostly sets dimensions, because it will not be
203 % shown much. (Only in viewers that don't support 3D Rich Media -- that is, all
204 % except Acrobat).
205 \RM[dice.u3d][
206 views={Front, Back, Left, Right, Top, Bottom, Fish Eye at Centre},
207 activation=auto,
208 scripts=3dmenu,
209 ]{\Red \vrule height.5\hsize width.5\hsize}
210
211 % A few buttons for switching views.
212 \hlink[goto3dview::/N]{\frame{Next view}}
213 \hlink[goto3dview::(Back)]{\frame{View \"Back"}}
214 \hlink[goto3dview::5]{\frame{6th view in the list}}
215
216 \vfil\break
217
218
219 % Last media9 example ported. It has its own JavaScript file for animation,
220 % which can be customized at runtime using JavaScript actions that access 3D
221 % context of the annotation.
222 \filedef/e[malte]{malte.u3d}
223 \DDDview[malte][c2c=1 1 1, roo=0.25]
224 \RM[malte][
225 activation=auto,
226 scripts={3dmenu, malte.js},
227 ]{\Blue \vrule height.5\hsize width0.5\hsize}
228
229 {\picheight=1.44em
230 % Normal JavaScript actions, but we access functions defined globaly in the 3D
231 % JavaScript context of "malte" Rich Media annotation.
232 \hlink[js:\DDDcontext{malte}.cntrClockWise();]{\inspic{boutona.pdf}}
233 \hlink[js:\DDDcontext{malte}.pause();]{\inspic{boutonb.pdf}}
234 \hlink[js:\DDDcontext{malte}.clockWise();]{\inspic{boutonc.pdf}}
235 \hlink[js:\DDDcontext{malte}.scaleSpeed(1/1.1);]{\inspic{boutond.pdf}}
236 \hlink[js:\DDDcontext{malte}.origSpeed();]{\inspic{boutone.pdf}}
237 \hlink[js:\DDDcontext{malte}.scaleSpeed(1.1);]{\inspic{boutonf.pdf}}
238 }
239
240
241 \vfil\break
242
243
244 % Lastly a showcase of transitions / page durations in \OpTeX/ slideshow.
245 % Because transitions are displayed only in fullscreen mode, we could request
246 % it by using `\fullscreen`. But we have more pages before this, so we didn't.
247
248 % We just turn the rest of the document into slideshow.
249 \slides
250 \slideshow
251 % To see the transitions better, we color each page with a background color.
252 \global\pgbackground={\bgcolor \hrule height\pdfpageheight width\pdfpagewidth}
253 \glet\bgcolor=\Yellow
254
255 % Transitions on all pages where it is not said otherwise will be of type
256 % "Wipe" and be 1 second long.
257 \transitions[Wipe:1]
258
259 % The slides will by default be shown for 3 seconds before advancing to the
260 % next one.
261 \defaultpageduration[3]
262 % But the first slide has override to only be shown for 1 second.
263 \pageduration[1]
264
265 \tit Presentation
266
267 \subtit Transistions and durations
268
269 \pg;
270 \glet\bgcolor=\Red
271 % All transitions are defined on the page object and they are shown when we go
272 % to that page. That means that we probably didn't see the "Wipe:1" animation
273 % of the first slide, because we already were there. However, this second slide
274 % with "Fade" is now shown correctly. (The first one also will, when we go
275 % back to it.)
276 \transition[Fade]
277
278 \sec First slide
279
280 Some\pg+
281 % In a slideshow, by using \pg+ we are on a new PDF page with independently set
282 % transition/duration. We can use this to disable page durations -- we have
283 % seen the "single page override" in action on previous page, and the default
284 % duration on this "page".
285 \defaultpageduration[]
286
287 % Also apply a long transition on this "page"/"slide"/"subslide".
288 \transition[Dissolve:4]
289
290 % More uses of currently set default values follow.
291 text\pg+
292
293 to\pg+
294
295 test\pg+
296
297 slideshow
298
299 \pg;
300 % Now show different transitions on differently colored pages:
301 \glet\bgcolor=\Green
302 \transition[Split:3:/Dm /V /M /I]
303
304 \sec Second slide
305
306 \transitions[Blinds:2]
307
308 more\pg+
309
310 text
311
312 \transitions[Wipe]
313
314 \pg;
315 \glet\bgcolor=\Brown
316 \transition[Dissolve]
317
318 \sec Third slide
319
320 \pg;
321 \glet\bgcolor=\Red
322 \transition[Box]
323
324 \sec More
325
326 \pg;
327 \glet\bgcolor=\Yellow
328
329 \sec slides
330
331 \pg;
332 \glet\bgcolor=\Red
333
334 \sec using
335
336 \pg;
337 \glet\bgcolor=\Yellow
338
339 \sec default transition
340
341 bye\pg+
342
343 bye
344
345 \bye