Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 % File: ltx-talk-decode.dtx Copyright (C) 2023-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-decode} -- Decoding overlay specs^^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-decode} 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 % \begin{variable}{\l_@@_decode_overlays_bool}
77 % The result from decoding: are we on the current slide. This may well be
78 % better handled by moving to a |TF| signature: to be explored.
79 % \begin{macrocode}
80 \bool_new:N \l_@@_decode_overlays_bool
81 % \end{macrocode}
82 % \end{variable}
83 %
84 % \begin{variable}{\g_@@_pauses_int, \c@pauses, \thepauses}
85 % The automatically-incremented value for the relative overlay value.
86 % \begin{macrocode}
87 \int_new:N \g_@@_pauses_int
88 \cs_new_eq:NN \c@pauses \g_@@_pauses_int
89 \cs_new:Npn \thepauses { \@arabic \g_@@_pauses_int }
90 % \end{macrocode}
91 % \end{variable}
92 %
93 % \begin{variable}{\l_@@_decode_modes_bool}
94 % Tracks whether at least one mode was given with no overlays: this means
95 % that the specification selects only included modes.
96 % \begin{macrocode}
97 \bool_new:N \l_@@_decode_modes_bool
98 % \end{macrocode}
99 % \end{variable}
100 %
101 % \begin{variable}{\l_@@_decode_step_bool}
102 % Tracks whether to step \cs{g_@@_pauses_int}.
103 % \begin{macrocode}
104 \bool_new:N \l_@@_decode_step_bool
105 % \end{macrocode}
106 % \end{variable}
107 %
108 % \begin{variable}{\l_@@_decode_arg_str}
109 % For error usage.
110 % \begin{macrocode}
111 \str_new:N \l_@@_decode_arg_str
112 % \end{macrocode}
113 % \end{variable}
114 %
115 % \begin{variable}{\l_@@_decode_overlays_clist, \l_@@_decode_overlays_str}
116 % The decoded overlay specification: will have only absolute slide numbers
117 % present, potentially along with ranges.
118 % \begin{macrocode}
119 \clist_new:N \l_@@_decode_overlays_clist
120 \str_new:N \l_@@_decode_overlays_str
121 % \end{macrocode}
122 % \end{variable}
123 %
124 % \begin{variable}{\l_@@_decode_action_str}
125 % The action which is active, if any.
126 % \begin{macrocode}
127 \str_new:N \l_@@_decode_action_str
128 % \end{macrocode}
129 % \end{variable}
130 %
131 % \begin{variable}
132 % {
133 % \l_@@_decode_actions_bool ,
134 % \l_@@_decode_actions_clist ,
135 % \l_@@_decode_actions_str
136 % }
137 % For the actions versions of overlay tracking.
138 % \begin{macrocode}
139 \bool_new:N \l_@@_decode_actions_bool
140 \clist_new:N \l_@@_decode_actions_clist
141 \str_new:N \l_@@_decode_actions_str
142 % \end{macrocode}
143 % \end{variable}
144 %
145 % \begin{macro}
146 % {\@@_decode_parse:n, \@@_decode_parse_auxi:n, \@@_decode_parse_auxii:n}
147 % \begin{macro}{\@@_decode_parse:w}
148 % First a simple check for an entirely blank argument: if that's the case,
149 % there is no additional overlay to consider. Then deal with any category
150 % code issues before looping over blocks divided by \verb"|" tokens.
151 % \begin{macrocode}
152 \cs_new_protected:Npn \@@_decode_parse:n #1
153 { \exp_args:Ne \@@_decode_parse_auxi:n {#1} }
154 \cs_new_protected:Npn \@@_decode_parse_auxi:n #1
155 {
156 \str_clear:N \l_@@_decode_action_str
157 \bool_lazy_or:nnTF
158 { \tl_if_blank_p:n {#1} }
159 { \str_if_eq_p:nn {#1} { all } }
160 { \bool_set_true:N \l_@@_decode_overlays_bool }
161 {
162 \str_set:Nn \l_@@_decode_arg_str {#1}
163 \bool_set_false:N \l_@@_decode_actions_bool
164 \bool_set_false:N \l_@@_decode_overlays_bool
165 \bool_set_false:N \l_@@_decode_modes_bool
166 \exp_args:No \@@_decode_parse_auxii:n { \l_@@_decode_arg_str }
167 }
168 }
169 % \end{macrocode}
170 % Stepping the value assigned to |+| is done in the outer loop, as within one
171 % overlay expression it always takes the same value. If the \pkg{amsmath}
172 % \tn{ifmeasuring@} flag is on, the overlay counter is not advanced.
173 % \begin{macrocode}
174 \cs_new_protected:Npn \@@_decode_parse_auxii:n #1
175 {
176 \bool_set_false:N \l_@@_decode_step_bool
177 \@@_decode_parse:w #1 | \q_recursion_tail | \q_recursion_stop
178 \bool_if:NT \l_@@_decode_step_bool
179 {
180 \legacy_if:nF { measuring@ }
181 { \int_gincr:N \g_@@_pauses_int }
182 }
183 }
184 % \end{macrocode}
185 % The end-of-loop test here covers the case where the active mode is not
186 % mentioned at all in the specification.
187 % \begin{macrocode}
188 \cs_new_protected:Npn \@@_decode_parse:w #1 |
189 {
190 \quark_if_recursion_tail_stop_do:nn {#1}
191 {
192 \bool_lazy_and:nnT
193 { \str_if_empty_p:N \l_@@_decode_overlays_str }
194 { ! \l_@@_decode_modes_bool }
195 { \bool_set_true:N \l_@@_decode_overlays_bool }
196 }
197 \exp_args:Ne \@@_decode_mode:n
198 { \tl_trim_spaces:n {#1} }
199 \@@_decode_parse:w
200 }
201 % \end{macrocode}
202 % \end{macro}
203 % \end{macro}
204 %
205 % \begin{variable}{\c_@@_modes_clist}
206 % The possible modes: detokenized as that is applied up-front in decoding.
207 % \begin{macrocode}
208 \clist_const:Ne \c_@@_modes_clist
209 {
210 \tl_to_str:n { article } ,
211 \tl_to_str:n { handout } ,
212 \tl_to_str:n { projector }
213 }
214 % \end{macrocode}
215 % \end{variable}
216 %
217 % \begin{macro}{\@@_decode_mode:n}
218 % \begin{macro}{\@@_decode_mode:w}
219 % \begin{macro}{\@@_decode_mode_aux:n}
220 % Check if the mode is known and current. If we find an action but have no
221 % overlay details, they are filled in with a \verb|*|. Notice that if
222 % we get a hit here for the mode test, there is no overlay part: we therefore
223 % have a spec that excludes other modes.
224 % \begin{macrocode}
225 \cs_new_protected:Npe \@@_decode_mode:n #1
226 {
227 \clist_if_in:NnTF \exp_not:N \c_@@_modes_clist {#1}
228 {
229 \bool_set_true:N \exp_not:N \l_@@_decode_modes_bool
230 \exp_not:N \str_if_eq:VnT
231 \exp_not:N \l_@@_mode_str {#1}
232 { \bool_set_true:N \exp_not:N \l_@@_decode_overlays_bool }
233 }
234 {
235 \exp_not:N \@@_decode_mode:w #1 \tl_to_str:n { : : }
236 \exp_not:N \q_stop
237 }
238 }
239 \use:e
240 {
241 \cs_new_protected:Npe \exp_not:N \@@_decode_mode:w
242 #1 \token_to_str:N :
243 #2 \token_to_str:N :
244 #3 \exp_not:N \q_stop
245 }
246 {
247 \exp_not:N \tl_if_blank:nTF {#2}
248 {
249 \exp_not:N \@@_decode_mode:nn
250 { \tl_to_str:n { projector } } {#1}
251 }
252 { \exp_not:N \@@_decode_mode:nn {#1} {#2} }
253 }
254 \cs_new_protected:Npn \@@_decode_mode:nn #1#2
255 {
256 \str_if_eq:VnTF \l_@@_mode_str {#1}
257 {
258 \@@_decode_action:n {#2}
259 \str_if_empty:NT \l_@@_decode_overlays_str
260 { \@@_decode_overlays:nn { overlays } { * } }
261 }
262 {
263 \tl_if_blank:nT {#2}
264 { \bool_set_true:N \l_@@_decode_modes_bool }
265 }
266 }
267 % \end{macrocode}
268 % \end{macro}
269 % \end{macro}
270 % \end{macro}
271 %
272 % \begin{macro}{\@@_decode_action:n}
273 % \begin{macro}{\@@_decode_action:w}
274 % Here, we have two valid possibilities: no action specification at all,
275 % or from the known list. If we don't find one of those outcomes, we can
276 % issue an error.
277 % \begin{macrocode}
278 \cs_new_protected:Npe \@@_decode_action:n #1
279 {
280 \exp_not:N \@@_decode_action:w
281 #1 \tl_to_str:n { @ @ } \exp_not:N \q_stop
282 }
283 \use:e
284 {
285 \cs_new_protected:Npn \exp_not:N \@@_decode_action:w
286 #1 \tl_to_str:n { @ } #2 \tl_to_str:n { @ } #3 \exp_not:N \q_stop
287 }
288 {
289 \tl_if_blank:nTF {#2}
290 {
291 \str_if_empty:NTF \l_@@_decode_action_str
292 { \@@_decode_overlays:nn { overlays } {#1} }
293 {
294 \msg_error:nnV { talk } { misplaced-action-spec }
295 \l_@@_decode_arg_str
296 }
297 }
298 {
299 \cs_if_exist:cTF { @@_action_ #1 :N }
300 {
301 \str_if_empty:NTF \l_@@_decode_action_str
302 {
303 \str_set:Nn \l_@@_decode_action_str {#1}
304 \tl_if_blank:nF {#2}
305 { \@@_decode_overlays:nn { actions } {#2} }
306 }
307 {
308 \msg_error:nnV { talk } { duplicate-action-spec }
309 \l_@@_decode_arg_str
310 }
311 }
312 {
313 \msg_error:nnV { talk } { bad-action-spec }
314 \l_@@_decode_arg_str
315 }
316 }
317 }
318 % \end{macrocode}
319 % \end{macro}
320 % \end{macro}
321 %
322 % \begin{macro}{\@@_decode_overlays:nn}
323 % \begin{macro}{\@@_decode_overlays:nN}
324 % \begin{macro}{\@_decode_overlay_+:nw, \@@_decode_overlay_.:nw}
325 % \begin{macro}{\@@_decode_overlay_aux:nNN}
326 % \begin{macro}{\@@_decode_overlay_offset:nNnN}
327 % \begin{macro}{\@@_decode_overlay_offset:nNn}
328 % The loop here needs to replace all |+| and |.| characters by the current
329 % automatic value, allowing for any offsets. Stepping the value assigned
330 % here is done in the outer loop (see above).
331 % \begin{macrocode}
332 \cs_new_protected:Npn \@@_decode_overlays:nn #1#2
333 {
334 \str_clear:c { l_@@_decode_ #1 _str }
335 \@@_decode_overlays:nN {#1} #2 \q_recursion_tail \q_recursion_stop
336 \@@_decode_check:n {#1}
337 }
338 \cs_new_protected:Npn \@@_decode_overlays:nN #1#2
339 {
340 \quark_if_recursion_tail_stop:N #2
341 \cs_if_exist_use:cF { @@_decode_overlay_ #2 :nw }
342 {
343 \str_put_right:cn { l_@@_decode_ #1 _str } {#2}
344 \@@_decode_overlays:nN
345 }
346 {#1}
347 }
348 \cs_new_protected:cpn { @@_decode_overlay_+:nw } #1
349 {
350 \bool_set_true:N \l_@@_decode_step_bool
351 \@@_decode_overlay_aux:nNN {#1} 1
352 }
353 \cs_new_protected:cpn { @@_decode_overlay_.:nw } #1
354 { \@@_decode_overlay_aux:nNN {#1} 0 }
355 % \end{macrocode}
356 % The look-ahead for an offset to a relative specification. If the
357 % end-of-loop is reached, the value still needs to be inserted: to
358 % share auxiliaries, that is done by using the same function as elsewhere,
359 % so the end-of-loop markers are re-inserted. Otherwise, there is a check
360 % to see if the next token is a |(|.
361 % \begin{macrocode}
362 \cs_new_protected:Npn \@@_decode_overlay_aux:nNN #1#2#3
363 {
364 \quark_if_recursion_tail_stop_do:Nn #3
365 {
366 \@@_decode_overlay_offset:nNn {#1} #2 { 0 }
367 \q_recursion_tail \q_recursion_stop
368 }
369 \token_if_eq_meaning:NNTF #3 ( % )
370 { \@@_decode_overlay_offset:nNnN {#1} #2 { } }
371 { \@@_decode_overlay_offset:nNn {#1} #2 { 0 } #3 }
372 }
373 % \end{macrocode}
374 % For the end of an offset, any valid overlay specification must have a
375 % closing |)|, so this time the end-of-loop case is an error. Otherwise
376 % simply collect up tokens until the closing |)| is found.
377 % \begin{macrocode}
378 \cs_new_protected:Npn \@@_decode_overlay_offset:nNnN #1#2#3#4
379 {
380 \quark_if_recursion_tail_stop_do:Nn #4
381 {
382 \msg_error:nnV { talk } { bad-action-spec }
383 \l_@@_decode_arg_str
384 } % (
385 \token_if_eq_meaning:NNTF #4 )
386 { \@@_decode_overlay_offset:nNn {#1} #2 {#3} }
387 { \@@_decode_overlay_offset:nNnN {#1} #2 {#3#4} }
388 }
389 % \end{macrocode}
390 % Overlay values can never be negative: this is enforced here.
391 % \begin{macrocode}
392 \cs_new_protected:Npn \@@_decode_overlay_offset:nNn #1#2#3
393 {
394 \str_put_right:ce { l_@@_decode_ #1 _str }
395 { \int_max:nn { 0 } { #3 + \g_@@_pauses_int + #2 } }
396 \@@_decode_overlays:nN {#1}
397 }
398 % \end{macrocode}
399 % \end{macro}
400 % \end{macro}
401 % \end{macro}
402 % \end{macro}
403 % \end{macro}
404 % \end{macro}
405 %
406 % \begin{macro}{\@@_decode_check:n}
407 % \begin{macro}{\@@_decode_check:nw}
408 % \begin{macro}{\@@_decode_check_single:nn}
409 % \begin{macro}{\@@_decode_check_range:nnn}
410 % At this stage we have a fully \enquote{written out} overlay specification,
411 % and need to work out if the current slide is included. We need to look at
412 % each entry in the comma-separated list to sort this out. First we filter
413 % out the case of a |*|, then it's a question of working out whether each
414 % entry is a single number or a range, and if the latter, whether it's
415 % open at either the start or the end.
416 % \begin{macrocode}
417 \cs_new_protected:Npn \@@_decode_check:n #1
418 {
419 \clist_set:cv { l_@@_decode_ #1 _clist } { l_@@_decode_ #1 _str }
420 \clist_if_in:cnTF { l_@@_decode_ #1 _clist } { * }
421 { \bool_set_true:c { l_@@_decode_ #1 _bool } }
422 {
423 \clist_map_inline:cn { l_@@_decode_ #1 _clist }
424 { \@@_decode_check:nw {#1} 0 ##1 - - \q_stop }
425 }
426 }
427 % \end{macrocode}
428 % If |#4| is empty, both of the \enquote{filler} |-| tokens were consumed: we
429 % have a single value. Otherwise there is a range: the setup above ensures
430 % that there will be a starting value in all cases due to the leading |0|, but
431 % there may not be an end one.
432 % \begin{macrocode}
433 \cs_new_protected:Npn \@@_decode_check:nw #1#2 - #3 - #4 \q_stop
434 {
435 \tl_if_empty:nTF {#4}
436 { \@@_decode_check_single:nn {#1} {#2} }
437 {
438 \tl_if_blank:nTF {#3}
439 { \@@_decode_check_range:nnn {#1} {#2} { \c_max_int } }
440 { \@@_decode_check_range:nnn {#1} {#2} {#3} }
441 }
442 }
443 \cs_new_protected:Npn \@@_decode_check_single:nn #1#2
444 {
445 \int_compare:nNnTF \g_@@_slide_int = {#2}
446 { \bool_set_true:c { l_@@_decode_ #1 _bool } }
447 {
448 \int_compare:nNnT {#2} > \g_@@_slide_int
449 { \bool_gset_true:N \g_@@_slide_continue_bool }
450 }
451 }
452 % \end{macrocode}
453 % TODO: In the following we might want to add a check whether the range was
454 % given with |#2| being smaller than |#3|, to be decided upon.
455 % \begin{macrocode}
456 \cs_set_protected:Npn \@@_decode_check_range:nnn #1#2#3
457 {
458 \int_compare:nNnF \g_@@_slide_int > {#3}
459 {
460 \int_compare:nNnTF \g_@@_slide_int < {#2}
461 { \bool_gset_true:N \g_@@_slide_continue_bool }
462 {
463 \bool_set_true:c { l_@@_decode_ #1 _bool }
464 \bool_lazy_and:nnT
465 { \int_compare_p:nNn \g_@@_slide_int < {#3} }
466 { \int_compare_p:nNn {#3} < \c_max_int }
467 { \bool_gset_true:N \g_@@_slide_continue_bool }
468 \clist_map_break:
469 }
470 }
471 }
472 % \end{macrocode}
473 % \end{macro}
474 % \end{macro}
475 % \end{macro}
476 % \end{macro}
477 %
478 % \begin{macrocode}
479 \msg_new:nnnn { talk } { bad-action-spec }
480 { Bad~overlay~specification~"#1". }
481 {
482 The~overlay~specification~given~doesn't~follow~the~pattern~described~in~
483 the~ltx-talk~manual:~it~has~been~ignored.
484 }
485 \msg_new:nnnn { talk } { duplicate-action-spec }
486 { Duplicate~action~in~overlay~specification~"#1". }
487 {
488 The~overlay~specification~contains~more~than~one~action:
489 ltx-talk~only~supports~a~single~action~in~one~overlay.
490 }
491 \msg_new:nnnn { talk } { misplaced-action-spec }
492 { Misplaced~action~in~overlay~specification~"#1". }
493 {
494 The~overlay~specification~contains~an~action~before~the~overlay~
495 part(s):~this~is~not~supported.
496 }
497 % \end{macrocode}
498 %
499 % \begin{macrocode}
500 %</class>
501 % \end{macrocode}
502 %
503 % \end{implementation}
504 %
505 % \PrintIndex