Debian Codegraph @

texmf-dist/source/latex/ltx-talk/ltx-talk-overlay.dtx

raw
1 % \iffalse meta-comment
2 %
3 % File: ltx-talk-overlay.dtx Copyright (C) 2024-2026 Joseph Wright
4 %
5 % It may be distributed and/or modified under the conditions of the
6 % LaTeX Project Public License (LPPL), either version 1.3c of this
7 % license or (at your option) any later version. The latest version
8 % of this license is in the file
9 %
10 % https://www.latex-project.org/lppl.txt
11 %
12 % This file is part of the "ltx-talk bundle" (The Work in LPPL)
13 % and all files in that bundle must be distributed together.
14 %
15 % The released version of this bundle is available from CTAN.
16 %
17 % -----------------------------------------------------------------------
18 %
19 % The development version of the bundle can be found at
20 %
21 % https://github.com/josephwright/ltx-talk
22 %
23 % for those people who are interested.
24 %
25 % -----------------------------------------------------------------------
26 %
27 %<*driver>
28 \documentclass{l3doc}
29 % Additional commands needed in this source
30 \NewDocumentCommand\email{m}{\href{mailto:#1}{\nolinkurl{#1}}}
31 \begin{document}
32 \DocInput{\jobname.dtx}
33 \end{document}
34 %</driver>
35 % \fi
36 %
37 % ^^A As we are dealing with a class, this has to be done manually
38 % \def\filedate{2026-04-30}
39 % \def\fileversion{v0.5.0}
40 %
41 % \title{^^A
42 % \pkg{ltx-talk-overlay} -- Overlays^^A
43 % \thanks{This file describes \fileversion,
44 % last revised \filedate.}^^A
45 % }
46 %
47 % \author{^^A
48 % Joseph Wright^^A
49 % \thanks{^^A
50 % E-mail: \email{[email protected]}^^A
51 % }^^A
52 % }
53 %
54 % \date{Released \filedate}
55 %
56 % \maketitle
57 %
58 % \begin{documentation}
59 %
60 % \end{documentation}
61 %
62 % \begin{implementation}
63 %
64 % \section{\pkg{ltx-talk-overlay} implementation}
65 %
66 % Start the \pkg{DocStrip} guards.
67 % \begin{macrocode}
68 %<*class>
69 % \end{macrocode}
70 %
71 % Identify the internal prefix.
72 % \begin{macrocode}
73 %<@@=talk>
74 % \end{macrocode}
75 %
76 % \subsection{Utilities}
77 %
78 % \begin{macro}[TF]{\@@_if_overlay:n, \@@_if_overlay:V}
79 % \begin{macro}{\@@_overlay_arg:n}
80 % \begin{macrocode}
81 \prg_new_protected_conditional:Npnn \@@_if_overlay:n #1 { T , F , TF }
82 {
83 \@@_decode_parse:n {#1}
84 \bool_if:NTF \l_@@_decode_overlays_bool
85 \prg_return_true:
86 \prg_return_false:
87 }
88 \prg_generate_conditional_variant:Nnn \@@_if_overlay:n { V } { T , F , TF }
89 % \end{macrocode}
90 % A macro processor variant of the check that always results in an |N|-type
91 % bool.
92 % \begin{macrocode}
93 \cs_new_protected:Npn \@@_overlay_arg:n #1
94 {
95 \@@_if_overlay:nTF {#1}
96 { \cs_set:Npn \ProcessedArgument { \c_true_bool } }
97 { \cs_set:Npn \ProcessedArgument { \c_false_bool } }
98 }
99 % \end{macrocode}
100 % \end{macro}
101 % \end{macro}
102 %
103 % \begin{variable}{\l_@@_shuffle_skip}
104 % For tracking.
105 % \begin{macrocode}
106 \skip_new:N \l_@@_shuffle_skip
107 % \end{macrocode}
108 % \end{variable}
109 %
110 % \begin{macro}{\@@_shuffle_skip:n}
111 % As opacity uses whatsits at present, we need to make sure that any spaces
112 % come \emph{after} them. This is done by \enquote{shuffling} the last skip
113 % past the opacity.
114 % \begin{macrocode}
115 \cs_new_protected:Npn \@@_shuffle_skip:n #1
116 {
117 \skip_set_eq:NN \l_@@_shuffle_skip \tex_lastskip:D
118 \bool_lazy_and:nnTF
119 { ! \skip_if_eq_p:nn \l_@@_shuffle_skip { 0pt } }
120 {
121 \bool_lazy_or_p:nn
122 { \mode_if_horizontal_p: }
123 { \mode_if_vertical_p: }
124 }
125 {
126 \tex_unskip:D
127 #1
128 \mode_if_horizontal:TF
129 { \skip_horizontal:n }
130 { \skip_vertical:n }
131 \l_@@_shuffle_skip
132 }
133 {#1}
134 }
135 % \end{macrocode}
136 % \end{macro}
137 %
138 % \subsection{Opacity utilities}
139 %
140 % Currently, opacity is applies using whatsits at a low level. That means
141 % that to preserve spacing, we need to insert no-op versions in various
142 % places. To do that and get correct overlays, we need to track the current
143 % opacity. At present, this seems very \cls{ltx-talk}-specific, so
144 % is handled here with a few auxiliaries.
145 %
146 % \begin{macro}{\@@_opacity_begin:n, \@@_opacity_end:}
147 % Simply tracking wrappers.
148 % \begin{macrocode}
149 \cs_new_protected:Npn \@@_opacity_begin:n #1
150 { \@@_shuffle_skip:n { \opacity_begin:n {#1} } }
151 \cs_new_protected:Npn \@@_opacity_end:
152 { \@@_shuffle_skip:n { \opacity_end: } }
153 % \end{macrocode}
154 % \end{macro}
155 %
156 % \subsection{Action commands and environments}
157 %
158 % Commands that can be used as actions all have a common form (with one
159 % exception). The common internal structure is used to enable them to be used
160 % as actions by looking for the name \cs[no-index]{@@_action_\meta{name}:N}.
161 %
162 % \begin{macro}{\@@_action_alert:N}
163 % At present a color selection.
164 % \begin{macrocode}
165 \cs_new_protected:Npn \@@_action_alert:N #1
166 {
167 \bool_if:NTF #1
168 { \color_select:n { alert } }
169 { \color_select:n { . } }
170 }
171 % \end{macrocode}
172 % \end{macro}
173 %
174 % \begin{macro}
175 % {
176 % \@@_action_invisible:N ,
177 % \@@_action_invisible_end:N ,
178 % \@@_action_visible:N ,
179 % \@@_action_visible_end:N
180 % }
181 % Simply (un)hide unconditionally, overwriting any previous opacity.
182 % \begin{macrocode}
183 \cs_new_protected:Npn \@@_action_invisible:N #1
184 {
185 \bool_if:NTF #1
186 { \@@_opacity_begin:n { 0 } }
187 { \@@_opacity_begin:n { 1 } }
188 }
189 \cs_new_protected:Npn \@@_action_invisible_end:N #1
190 { \@@_opacity_end: }
191 \cs_new_protected:Npn \@@_action_visible:N #1
192 {
193 \bool_if:NTF #1
194 { \@@_opacity_begin:n { 1 } }
195 { \@@_opacity_begin:n { 0 } }
196 }
197 \cs_new_protected:Npn \@@_action_visible_end:N #1
198 { \@@_opacity_end: }
199 % \end{macrocode}
200 % \end{macro}
201 %
202 % \begin{macro}{\@@_action_only:N, \@@_action_only_end:N}
203 % Here, we simply throw away the content we do not want: this is done by
204 % typesetting in a disposable box.
205 % \begin{macrocode}
206 \cs_new_protected:Npn \@@_action_only:N #1
207 {
208 \bool_if:NF #1
209 { \vbox_set:Nw \l_@@_tmp_box }
210 }
211 \cs_new_protected:Npn \@@_action_only_end:N #1
212 {
213 \bool_if:NF #1
214 { \vbox_set_end: }
215 }
216 % \end{macrocode}
217 % \end{macro}
218 %
219 % \begin{variable}{\l_@@_uncover_hidden_fp}
220 % Currently just an on-off, but that will change.
221 % \begin{macrocode}
222 \NewTemplateType { hidden } { 0 }
223 \DeclareTemplateInterface { hidden } { talk } { 0 }
224 { opacity : real = 0 }
225 \DeclareTemplateCode { hidden } { talk } { 0 }
226 { opacity = \l_@@_uncover_hidden_fp }
227 { \@@_opacity_begin:n { \l_@@_uncover_hidden_fp } }
228 \DeclareInstance { hidden } { std } { talk } { }
229 % \end{macrocode}
230 % \end{variable}
231 % \begin{macro}{\@@_action_uncover:N, \@@_action_uncover_end:N}
232 % Use the template: we may need to extend that to deal with the
233 % end-of-template case later.
234 % \begin{macrocode}
235 \cs_new_protected:Npn \@@_action_uncover:N #1
236 {
237 \bool_if:NTF #1
238 { \@@_opacity_begin:n { 1 } }
239 { \UseInstance { hidden } { std } }
240 }
241 \cs_new_protected:Npn \@@_action_uncover_end:N #1
242 { \@@_opacity_end: }
243 % \end{macrocode}
244 % \end{macro}
245 %
246 % \begin{macro}{\invisible, \uncover, \visible}
247 % All generated automatically using the above implementations.
248 % \begin{macrocode}
249 \clist_map_inline:nn { invisible , uncover , visible }
250 {
251 \ExpandArgs { cne } \NewDocumentCommand {#1}
252 { > { \@@_overlay_arg:n } D <> { all } +m }
253 {
254 \exp_not:c { @@_action_ #1 :N } ##1
255 ##2
256 \exp_not:c { @@_action_ #1 _end:N } ##1
257 }
258 % \end{macrocode}
259 % \end{macro}
260 % \begin{environment}{invisibleenv, uncoverenv, visibleenv}
261 % And the environment versions.
262 % \begin{macrocode}
263 \ExpandArgs { nnee } \NewDocumentEnvironment { #1 env }
264 { > { \@@_overlay_arg:n } D <> { all } }
265 { \exp_not:c { @@_action_ #1 :N } ##1 }
266 { \exp_not:c { @@_action_ #1 _end:N } ##1 }
267 }
268 % \end{macrocode}
269 % \end{environment}
270 %
271 % \begin{macro}{\alert}
272 % The \cs{alert} command requires a group to contain color, so is done
273 % separately even though it still uses basically the same mechanism.
274 % \begin{macrocode}
275 \NewDocumentCommand \alert { > { \@@_overlay_arg:n } D <> { all } +m }
276 {
277 \group_begin:
278 \@@_action_alert:N #1
279 #2
280 \group_end:
281 }
282 % \end{macrocode}
283 % \end{macro}
284 % \begin{environment}{alertenv}
285 % As does the environment.
286 % \begin{macrocode}
287 \NewDocumentEnvironment { alertenv } { > { \@@_overlay_arg:n } D <> { all } }
288 { \@@_action_alert:N #1 }
289 { }
290 % \end{macrocode}
291 % \end{environment}
292 % \begin{macro}{\only}
293 % This code needs to be done manually as for the command version the content
294 % must be entirely discarded. That can't work for the environment version,
295 % which has to deal with for example single items in a list (and so cannot
296 % be collected up verbatim and must use a box).
297 % \begin{macrocode}
298 \NewDocumentCommand \only { D <> { all } +m }
299 {
300 \@@_if_overlay:nT {#1}
301 {#2}
302 }
303 % \end{macrocode}
304 % \end{macro}
305 % \begin{environment}{onlyenv}
306 % The environment version could be done above, but it is clearer to keep
307 % this code entirely separate from the rest.
308 % \begin{macrocode}
309 \NewDocumentEnvironment { onlyenv } { > { \@@_overlay_arg:n } D <> { all } }
310 { \@@_action_only:N #1 }
311 { \@@_action_only_end:N #1 }
312 % \end{macrocode}
313 % \end{environment}
314 %
315 % \begin{variable}
316 % {
317 % \l_@@_saved_overlays_bool ,
318 % \l_@@_saved_action_str ,
319 % \l_@@_saved_actions_bool
320 % }
321 % \begin{macrocode}
322 \bool_new:N \l_@@_saved_overlays_bool
323 \str_new:N \l_@@_saved_action_str
324 \bool_new:N \l_@@_saved_actions_bool
325 % \end{macrocode}
326 % \end{variable}
327 %
328 % \begin{variable}
329 % {\l_@@_overlay_all_bool}
330 % \begin{macrocode}
331 \bool_new:N \l_@@_overlay_all_bool
332 % \end{macrocode}
333 % \end{variable}
334 % \begin{macro}{\action}
335 % \begin{environment}{actionenv}
336 % \begin{macro}{\@@_action_begin:n}
337 % \begin{macro}{\@@_action_begin:w}
338 % \begin{macro}{\@@_action_begin_auxi:n, \@@_action_begin_auxii:n}
339 % \begin{macro}{\@@_action_end:}
340 % As we need data on not just overlays but also actions at the end of the
341 % environment, this has to be done manually. To allow working with
342 % environments but also items, the code needs to save data for the end
343 % function. The group is needed for cases where we are not in a \LaTeX{}
344 % environment group. When an \cs{onslide}/\cs{pause} is active, it takes
345 % priority: sorted by applying up-front. Actions can be skipped entirely
346 % if the overlay spec is simply \texttt{all}, as there will never be
347 % any spacing issues, \foreign{etc}.
348 % \begin{macrocode}
349 \NewDocumentCommand \action { d <> +m }
350 {
351 \group_begin:
352 \@@_action_begin:n {#1}
353 #2
354 \@@_action_end:
355 \group_end:
356 }
357 \NewDocumentEnvironment { actionenv } { d <> }
358 { \@@_action_begin:n {#1} }
359 { \@@_action_end: }
360 \cs_new_protected:Npn \@@_action_begin:n #1
361 {
362 \group_begin:
363 \tl_if_novalue:nTF {#1}
364 {
365 \exp_after:wN \@@_action_begin:w
366 \l_@@_action_spec_str < all > \q_stop
367 }
368 { \@@_action_begin_auxi:n {#1} }
369 }
370 \cs_new_protected:Npn \@@_action_begin:w #1 < #2 > #3 \q_stop
371 { \@@_action_begin_auxi:n {#2} }
372 \cs_new_protected:Npn \@@_action_begin_auxi:n #1
373 {
374 \str_if_eq:nnTF {#1} { all }
375 { \bool_set_true:N \l_@@_overlay_all_bool }
376 {
377 \bool_set_false:N \l_@@_overlay_all_bool
378 \@@_action_begin_auxii:n {#1}
379 }
380 }
381 \cs_new_protected:Npn \@@_action_begin_auxii:n #1
382 {
383 \@@_decode_parse:n {#1}
384 \bool_set_eq:NN \l_@@_saved_overlays_bool
385 \l_@@_decode_overlays_bool
386 \str_set_eq:NN \l_@@_saved_action_str
387 \l_@@_decode_action_str
388 \bool_set_eq:NN \l_@@_saved_actions_bool
389 \l_@@_decode_actions_bool
390 \tl_if_empty:NTF \g_@@_onslide_tl
391 {
392 \bool_if:NTF \l_@@_decode_overlays_bool
393 {
394 \cs_if_exist_use:cF
395 { @@_action_ \l_@@_decode_action_str :N }
396 { \use_none:n }
397 \l_@@_decode_actions_bool
398 }
399 { \UseInstance { hidden } { std } }
400 }
401 { \@@_action_invisible:N \c_true_bool }
402 }
403 \cs_new_protected:Npn \@@_action_end:
404 {
405 \bool_if:NF \l_@@_overlay_all_bool
406 {
407 \tl_if_empty:NTF \g_@@_onslide_tl
408 {
409 \bool_if:NTF \l_@@_saved_overlays_bool
410 {
411 \cs_if_exist_use:cF
412 { @@_action_ \l_@@_saved_action_str _end:N }
413 { \use_none:n }
414 \l_@@_saved_actions_bool
415 }
416 { \@@_opacity_end: }
417 }
418 { \@@_action_invisible_end:N \c_true_bool }
419 }
420 \group_end:
421 }
422 % \end{macrocode}
423 % \end{macro}
424 % \end{macro}
425 % \end{macro}
426 % \end{macro}
427 % \end{environment}
428 % \end{macro}
429 %
430 % \subsection{Non-action commands and environments}
431 %
432 % This section contains commands and environments that do \emph{not}
433 % need to be made available as actions.
434 %
435 % \begin{macro}{\alt}
436 % Simple wrappers around the internal switch.
437 % \begin{macrocode}
438 \NewDocumentCommand \alt { D <> { all } +m +m }
439 {
440 \@@_if_overlay:nTF {#1}
441 {#2}
442 {#3}
443 }
444 % \end{macrocode}
445 % \end{macro}
446 %
447 % \begin{macro}{\onslide}
448 % \begin{macro}{\@@_onslide:n}
449 % Simply make transparent: this is done without grouping so we can work
450 % for example in tabular cells.
451 % \begin{macrocode}
452 \NewDocumentCommand \onslide { D <> { all } }
453 {
454 \@@_onslide:n {#1}
455 \ignorespaces
456 }
457 \cs_new_protected:Npn \@@_onslide:n #1
458 {
459 \tl_use:N \g_@@_onslide_tl
460 \tl_gclear:N \g_@@_onslide_tl
461 \@@_if_overlay:nF {#1}
462 {
463 \@@_opacity_begin:n { 0 }
464 \tl_gput_right:Nn \g_@@_onslide_tl
465 { \@@_opacity_end: }
466 }
467 }
468 % \end{macrocode}
469 % \end{macro}
470 % \end{macro}
471 % \begin{variable}{\g_@@_onslide_tl}
472 % \begin{macrocode}
473 \tl_new:N \g_@@_onslide_tl
474 % \end{macrocode}
475 % \end{variable}
476 %
477 % \begin{macro}{\temporal}
478 % A tricky one: to separate the not-on-current-slide cases, the flag to
479 % continue is used.
480 % \begin{macrocode}
481 \NewDocumentCommand \temporal { D <> { all } +m +m +m }
482 {
483 \@@_if_overlay:nTF {#1}
484 {#3}
485 {
486 \bool_if:NTF \g_@@_slide_continue_bool
487 {#4}
488 {#2}
489 }
490 }
491 % \end{macrocode}
492 % \end{macro}
493 %
494 % \begin{macro}{\pause}
495 % A thin wrapper.
496 % \begin{macrocode}
497 \NewDocumentCommand \pause { o }
498 {
499 \legacy_if:nF { measuring@ }
500 {
501 \IfNoValueTF {#1}
502 { \int_gincr:N \g_@@_pauses_int }
503 { \int_gset:Nn \g_@@_pauses_int {#1} }
504 \exp_args:Ne \@@_onslide:n
505 { \int_eval:n { \g_@@_pauses_int + 1 } - }
506 }
507 }
508 % \end{macrocode}
509 % \end{macro}
510 %
511 % \subsection{Fixed-size areas}
512 %
513 % \begin{macro}{\@@_overprint_begin:n}
514 % A common auxiliary for overprinting, which starts off much the same for
515 % both \env{overlayarea} and \env{overprint}.
516 % \begin{macrocode}
517 \cs_new_protected:Npn \@@_overprint_begin:n #1
518 {
519 \par
520 \vbox_set_to_wd:Nnw \l_@@_tmp_box {#1}
521 \raggedright
522 \ignorespaces
523 }
524 % \end{macrocode}
525 % \end{macro}
526 %
527 % \begin{environment}{overlayarea}
528 % An initial approach: quite similar to a column.
529 % \begin{macrocode}
530 \NewDocumentEnvironment { overlayarea } { m m }
531 { \@@_overprint_begin:n {#1} }
532 {
533 \vbox_set_end:
534 \vbox_to_ht:nn {#2}
535 {
536 \box_use_drop:N \l_@@_tmp_box
537 \vfil
538 }
539 \par
540 }
541 % \end{macrocode}
542 % \end{environment}
543 %
544 % \begin{variable}{\l_@@_overprint_int}
545 % Track the overprints on a slide: as the slide forms a group, we do not need
546 % to worry about resetting.
547 % \begin{macrocode}
548 \int_new:N \l_@@_overprint_int
549 % \end{macrocode}
550 % \end{variable}
551 %
552 % \begin{macro}[EXP]{\@@_frame_overprint:}
553 % To refer to the current overprint environment within the document:
554 % needed in the \texttt{.aux} so avoids using non-letters.
555 % \begin{macrocode}
556 \cs_new:Npn \@@_frame_overprint:
557 {
558 \int_to_Roman:n \g_@@_frame_int
559 \int_to_roman:n \l_@@_overprint_int
560 }
561 % \end{macrocode}
562 % \end{macro}
563 %
564 % \begin{environment}{overprint}
565 % \begin{macro}{\@@_overprint_save_ht:}
566 % \begin{macro}{\@@_overprint_check_ht:n}
567 % For overprinting, in contrast to \cls{beamer} we use a two-pass approach
568 % to save the size at the end of the run: this means you can use \cs{only}
569 % for example in overprinting.
570 % \begin{macrocode}
571 \NewDocumentEnvironment { overprint } { O { \textwidth } }
572 { \@@_overprint_begin:n {#1} }
573 {
574 \vbox_set_end:
575 \int_incr:N \l_@@_overprint_int
576 \@@_overprint_save_ht:
577 \cs_if_exist:cTF
578 { overprint@ \@@_frame_overprint: }
579 {
580 \dim_compare:vNnTF
581 { overprint@ \@@_frame_overprint: }
582 > { \box_ht:N \l_@@_tmp_box }
583 {
584 \vbox_to_ht:vn
585 { overprint@ \@@_frame_overprint: }
586 {
587 \box_use_drop:N \l_@@_tmp_box
588 \vfil
589 }
590 }
591 { \box_use_drop:N \l_@@_tmp_box }
592 }
593 { \box_use_drop:N \l_@@_tmp_box }
594 \par
595 }
596 % \end{macrocode}
597 % As there is no clear end-point for overprinting, we need to be careful to
598 % keep the current width separate from the saved one. The rest is then about
599 % saving to the \texttt{.aux} file and helping out the user.
600 % \begin{macrocode}
601 \cs_new_protected:Npn \@@_overprint_save_ht:
602 {
603 \tl_if_exist:cF { g_@@_overprint_ \@@_frame_overprint: _tl }
604 {
605 \tl_new:c { g_@@_overprint_ \@@_frame_overprint: _tl }
606 \tl_gset:cn { g_@@_overprint_ \@@_frame_overprint: _tl }
607 { 0pt }
608 }
609 \tl_gset:ce { g_@@_overprint_ \@@_frame_overprint: _tl }
610 {
611 \dim_max:vn { g_@@_overprint_ \@@_frame_overprint: _tl }
612 { \box_ht:N \l_@@_tmp_box }
613 }
614 \legacy_if:nT { @filesw }
615 {
616 \iow_now:Ne \@auxout
617 {
618 \gdef \exp_not:c { overprint@ \@@_frame_overprint: }
619 {
620 \exp_not:v { g_@@_overprint_ \@@_frame_overprint: _tl }
621 }
622 }
623 }
624 \hook_gput_code:nne { enddocument / afterlastpage } { talk }
625 { \@@_overprint_check_ht:n { \@@_frame_overprint: } }
626 }
627 \cs_new_protected:Npn \@@_overprint_check_ht:n #1
628 {
629 \bool_lazy_and:nnF
630 { \exp_not:N \cs_if_exist_p:c { overprint@ #1 } }
631 {
632 \dim_compare_p:vNv { overprint@ #1 } = { g_@@_overprint_ #1 _tl }
633 }
634 {
635 \msg_warning:nn { talk } { overprint-ht }
636 \cs_gset_protected:Npn \@@_overprint_check_ht:n ##1 { }
637 }
638 }
639 \msg_new:nnn { talk } { overprint-ht }
640 {
641 Overprint~area~height~has~changed:\\
642 rerun~LaTeX.
643 }
644 % \end{macrocode}
645 % \end{macro}
646 % \end{macro}
647 % \end{environment}
648 %
649 % \subsection{Adding overlays to existing commands}
650 %
651 % \begin{macro}
652 % {
653 % \textbf ,
654 % \textit ,
655 % \textmd ,
656 % \textnormal ,
657 % \textrm ,
658 % \textsc ,
659 % \textsf ,
660 % \textsl ,
661 % \texttt ,
662 % \textup ,
663 % \emph
664 % }
665 % \begin{macro}
666 % {
667 % \stdtextbf ,
668 % \stdtextit ,
669 % \stdtextmd ,
670 % \stdtextnormal ,
671 % \stdtextrm ,
672 % \stdtextsc ,
673 % \stdtextsf ,
674 % \stdtextsl ,
675 % \stdtexttt ,
676 % \stdtextup ,
677 % \stdemph
678 % }
679
680 % \begin{macro}{\@@_textcmd_eqiv:n}
681 % Make the standard text commands overlay-aware. To keep the spacing
682 % unchanged when the command is not active, we use the same approach as
683 % the kernel does for inserting the right grouping.
684 % \begin{macrocode}
685 \tl_map_inline:nn
686 {
687 \textbf
688 \textit
689 \textmd
690 \textnormal
691 \textrm
692 \textsc
693 \textsf
694 \textsl
695 \texttt
696 \textup
697 \emph
698 }
699 {
700 \ExpandArgs { c } \NewCommandCopy { std \cs_to_str:N #1 } #1
701 \ExpandArgs { Nne } \RenewDocumentCommand #1
702 { D <> { all } +m }
703 {
704 \exp_not:N \@@_if_overlay:nTF {##1}
705 { \exp_not:c { std \cs_to_str:N #1 } }
706 { \exp_not:N \@@_textcmd_eqiv:n }
707 {##2}
708 }
709 }
710 \cs_new_protected:Npn \@@_textcmd_eqiv:n #1
711 {
712 \mode_if_math:TF
713 { { \mbox {#1} } }
714 {
715 \mode_leave_vertical:
716 {#1}
717 }
718 }
719 % \end{macrocode}
720 % \end{macro}
721 % \end{macro}
722 % \end{macro}
723 %
724 % \begin{macro}{\includegraphics}
725 % \begin{macro}{\stdincludegraphics}
726 % Just wrap up the args and forward if appropriate. The star is |#1| here as
727 % that matches the documented behavior of starred commands generally.
728 % \begin{macrocode}
729 \RequirePackage { graphicx }
730 \NewCommandCopy \stdincludegraphics \includegraphics
731 \RenewDocumentCommand \includegraphics { s D <> { all } o o m }
732 {
733 \@@_if_overlay:nT {#2}
734 {
735 \use:e
736 {
737 \exp_not:N \stdincludegraphics
738 \IfBooleanT #1 { * }
739 \IfNoValueF {#3} { [ \exp_not:n { {#3} } ] }
740 \IfNoValueF {#4} { [ \exp_not:n { {#4} } ] }
741 }
742 {#5}
743 }
744 }
745 % \end{macrocode}
746 % \end{macro}
747 % \end{macro}
748 %
749 % \begin{macro}{\label}
750 % \begin{macro}{\@@_label:n}
751 % Here, we can't wrap the existing command up as we need the space hack, so
752 % it has to be declared from scratch. There is also a non-standard overlay
753 % default. At present, no special tricks as seen in \pkg{beamer}.
754 % \begin{macrocode}
755 \RenewDocumentCommand \label { D <> { 1 } m }
756 {
757 \@bsphack
758 \@@_if_overlay:nT {#1}
759 { \@@_label:n {#2} }
760 \@esphack
761 }
762 \cs_new_protected:Npn \@@_label:n #1
763 {
764 \begingroup
765 \UseHookWithArguments { label } { 1 } {#1}
766 \protected@write \@auxout { }
767 {
768 \string \newlabel {#1}
769 {
770 { \@currentlabel }
771 { \thepage }
772 { \@currentlabelname }
773 { \@currentHref }
774 { \@kernel@reserved@label@data }
775 }
776 }
777 \endgroup
778 }
779 % \end{macrocode}
780 % \end{macro}
781 % \end{macro}
782 % \begin{macro}{\std@label@in@display, \std@label@in@display}
783 % We also need to cover \cs{label@in@display}: a bit more awkward as this is
784 % a document command but not set up as such in \pkg{amsmath}. For the present,
785 % cross our fingers on this!
786 % \begin{macrocode}
787 \cs_new_eq:NN \std@label@in@display \label@in@display
788 \RenewDocumentCommand \label@in@display { D <> { 1 } m }
789 {
790 \@@_if_overlay:nT {#1}
791 { \std@label@in@display {#2} }
792 }
793 % \end{macrocode}
794 % \end{macro}
795 %
796 % \subsection{Overlay patching of third-party environments}
797 %
798 % To allow opacity to apply to the entirety of constructed graphics, we need to
799 % apply a transparency group around the whole thing. We need to do that by saving
800 % the input in an Xform object, which then allows the group to be applied.
801 %
802 % \begin{variable}{\g_@@_opacity_group_int}
803 % Each use needs an Xform object, which at present we have to track as
804 % there are no anonymous ones.
805 % \begin{macrocode}
806 \int_new:N \g_@@_opacity_group_int
807 % \end{macrocode}
808 % \end{variable}
809 %
810 % \begin{macro}{\@@_opacity_group_begin:, \@@_opacity_group_end:}
811 % A general mechanism to collect up an environment in a box, which we can
812 % then use as the source for an Xform object.
813 % \begin{macrocode}
814 \cs_new_protected:Npn \@@_opacity_group_begin:
815 { \begin { lrbox } \l_@@_tmp_box }
816 \cs_new_protected:Npn \@@_opacity_group_end:
817 {
818 \end { lrbox }
819 \mode_leave_vertical:
820 \int_gincr:N \g_@@_opacity_group_int
821 \exp_args:Ne \pdfxform_new:nnn
822 { talk.opacity \int_use:N \g_@@_opacity_group_int }
823 { /Group << /S /Transparency /K ~ false /I ~ false >> }
824 { \usebox \l_@@_tmp_box }
825 \exp_args:Ne \pdfxform_use:n
826 { talk.opacity \int_use:N \g_@@_opacity_group_int }
827 }
828 % \end{macrocode}
829 % \end{macro}
830 %
831 % At present, we only add code onto the main top-level functions. This is only
832 % applied in Lua\TeX{} due to restrictions on Xform structures in \pdfTeX{}.
833 % Here, we apply the collection code to the commands not the environment
834 % forms to deal with \enquote{direct} usage.
835 % \begin{macrocode}
836 \sys_if_engine_luatex:T
837 {
838 \AddToHook { cmd / pspicture / before } { \@@_opacity_group_begin: }
839 \AddToHook { cmd / endpspicture / after } { \@@_opacity_group_end: }
840 }
841 % \end{macrocode}
842 %
843 % \begin{macrocode}
844 %</class>
845 % \end{macrocode}
846 %
847 % \end{implementation}
848 %
849 % \PrintIndex