Debian Codegraph @

texmf-dist/tex/latex/pdfmanagement/latex-lab-testphase-bookmark.sty

raw
1 %%
2 %% This is file `latex-lab-testphase-bookmark.sty',
3 %% generated with the docstrip utility.
4 %%
5 %% The original source files were:
6 %%
7 %% latex-lab-bookmark.dtx (with options: `package')
8 %%
9 %% Copyright (C) 2019-2026 The LaTeX Project
10 %%
11 %% It may be distributed and/or modified under the conditions of
12 %% the LaTeX Project Public License (LPPL), either version 1.3c of
13 %% this license or (at your option) any later version. The latest
14 %% version of this license is in the file:
15 %%
16 %% https://www.latex-project.org/lppl.txt
17 %%
18 %% This file is part of the "LaTeX PDF management bundle" (The Work in LPPL)
19 %% and all files in that bundle must be distributed together.
20 %%
21 %% File: latex-lab-bookmark.dtx (C) Copyright 2026 LaTeX Project
22 \def\ltlabbookmarkdate{2026-02-18}
23 \def\ltlabbookmarkversion{0.95}
24
25
26 \ProvidesExplPackage{latex-lab-testphase-bookmark}{2026-05-26}{0.97c}
27 {PDF bookmarks with kernel methods}%
28 \int_new:N \g__hyp_outline_currentlevel_int
29 \int_new:N \l__hyp_outline_level_int
30 \intarray_new:Nn \g__hyp_outline_level_intarray {2000} %TODO size??
31 \intarray_gset:Nnn \g__hyp_outline_level_intarray {1}{0}
32 \int_new:N \l__hyp_outline_depth_int
33 \tl_new:N \l__hyp_outline_title_tl
34 \tl_new:N \l__hyp_outline_action_data_tl
35 \tl_new:N \l__hyp_outline_action_dest_data_tl
36 \tl_new:N \l__hyp_outline_action_view_tl
37 \bool_new:N \l__hyp_outline_keeplevel_bool
38 \seq_new:N \l__hyp_outline_type_seq
39 \bitset_new:Nn \l__hyp_outline_action_bitset
40 {
41 goto = 1,
42 gotor = 2,
43 named = 3,
44 uri = 4,
45 raw = 5,
46 namedest = 6,
47 pagedest = 7
48 }
49 \bitset_set_true:Nn \l__hyp_outline_action_bitset { goto }
50
51 \int_new:N \l__hyp_outline_tmpa_int
52 \int_new:N \l__hyp_outline_rellevel_tmpa_int
53 \tl_new:N \l__hyp_outline_parent_tmpa_tl
54 \seq_new:N \l__hyp_outline_tmpa_seq
55 \tl_new:N \l__hyp_outline_tmpa_tl
56 \str_new:N \g__hyp_outline_tmpa_str
57 \socket_new:nn {hyp/outline/title}{2}
58 \socket_new_plug:nnn {hyp/outline/title}{pdfstringdef}
59 {
60 \pdfstringdef#2{#1}
61 }
62 \socket_new_plug:nnn {hyp/outline/title}{default}
63 {
64 \pdf_purify:nN {#1}#2
65 \pdf_string_from_unicode:nVN {utf16/string-raw} #2 #2
66 }
67 \socket_assign_plug:nn {hyp/outline/title}{default}
68 \regex_const:Nn \c__hyp_outline_dest_startview_regex
69 {
70 \A\ *
71 (?:
72 (?:XYZ (?:\ +(?:(?:\d+|\d*\.\d+)|null)){3}\ )
73 |
74 (?:Fit\b|FitB\b)
75 |
76 (?:(?:FitH|FitV|FitBH|FitBV)(?:\ +(?:\d+|\d*\.\d+)|\ +null){1})
77 |
78 (?:FitR (?:\ +\d+|\ +\d*\.\d+){4}\ )
79 )
80 }
81
82 \msg_new:nnn
83 { hyp /outline }
84 { invalid-view-value }
85 {
86 Invalid~value~'#1'~of~'#2' \\
87 is~replaced~by~'Fit'~\msg_line_context:.
88 }
89
90 \msg_new:nnn {hyp/outline}{no-action}
91 {
92 bookmark~action~missing!\\
93 Use~one~of~'dest',~'gotor',~'named',~'uri',~or~'rawaction'
94 }
95 \socket_new:nn {hyp/outline/numberformat}{0}
96 \socket_new_plug:nnn {hyp/outline/numberformat}{false}
97 {
98 \text_declare_purify_equivalent:Nn\numberline\use_none:n
99 \text_declare_purify_equivalent:Nn\booknumberline\use_none:n
100 \text_declare_purify_equivalent:Nn\partnumberline\use_none:n
101 \text_declare_purify_equivalent:Nn\chapternumberline\use_none:n
102 \cs_set_eq:NN\numberline\use_none:n
103 \cs_set_eq:NN\booknumberline\use_none:n
104 \cs_set_eq:NN\partnumberline\use_none:n
105 \cs_set_eq:NN\chapternumberline\use_none:n
106 }
107 \cs_new:Npn \__hyp_outline_use_numberline:n #1 {#1\c_space_tl}
108 \socket_new_plug:nnn {hyp/outline/numberformat}{true}
109 {
110 \text_declare_purify_equivalent:Nn\numberline \__hyp_outline_use_numberline:n
111 \text_declare_purify_equivalent:Nn\booknumberline \__hyp_outline_use_numberline:n
112 \text_declare_purify_equivalent:Nn\partnumberline \__hyp_outline_use_numberline:n
113 \text_declare_purify_equivalent:Nn\chapternumberline\__hyp_outline_use_numberline:n
114 \cs_set_eq:NN \numberline \__hyp_outline_use_numberline:n
115 \cs_set_eq:NN\booknumberline \__hyp_outline_use_numberline:n
116 \cs_set_eq:NN\partnumberline \__hyp_outline_use_numberline:n
117 \cs_set_eq:NN\chapternumberline\__hyp_outline_use_numberline:n
118 }
119 \keys_define:nn {hyp/outline}
120 {
121 ,bold .choice:
122 ,bold / true .code:n = \bitset_set_true:Nn \l_pdfoutline_F_bitset {Bold}
123 ,bold /false .code:n = \bitset_set_false:Nn\l_pdfoutline_F_bitset {Bold}
124 ,bold .default:n = true
125 ,italic .choice:
126 ,italic / true .code:n = \bitset_set_true:Nn\l_pdfoutline_F_bitset {Italic}
127 ,italic /false .code:n = \bitset_set_false:Nn\l_pdfoutline_F_bitset {Italic}
128 ,italic .default:n = true
129 ,numbered .code:n =
130 { \socket_assign_plug:nn { hyp/outline/numberformat } {#1}}
131 ,numbered .default:n = true
132 ,numbered .initial:n = false
133 ,bookmarksnumbered .meta:n = {numbered}
134 ,color .tl_set:N = \l_pdfoutline_color_tl
135
136 ,open .bool_set:N = \l_pdfoutline_open_bool
137 ,depth .code:n =
138 {
139 \cs_if_exist:cTF {toclevel@#1}
140 { \int_set:Nn \l__hyp_outline_depth_int { \use:c {toclevel@#1} } }
141 { \int_set:Nn \l__hyp_outline_depth_int { #1 } }
142 }
143 ,bookmarksdepth .meta:n = { depth = #1 }
144 ,depth .initial:n = {\int_use:N \c_max_int}
145 ,openlevel .int_set:N = \l_pdfoutline_open_int
146 ,bookmarksopenlevel .meta:n = { openlevel = #1 }
147 ,level .code:n =
148 {
149 \cs_if_exist:cTF {toclevel@#1}
150 { \int_set:Nn \l__hyp_outline_level_int { \use:c {toclevel@#1} } }
151 { \int_set:Nn \l__hyp_outline_level_int { #1 } }
152 }
153 ,rellevel .code:n =
154 {
155 \int_set:Nn
156 \l__hyp_outline_level_int
157 { \g__hyp_outline_currentlevel_int + #1 }
158 }
159 ,keeplevel .bool_set:N = \l__hyp_outline_keeplevel_bool
160 ,startatroot .code:n =
161 {
162 \int_set:Nn \l__hyp_outline_level_int { -1000 }
163 \bool_if:NF \l__hyp_outline_keeplevel_bool
164 {
165 \int_gset:Nn \g__hyp_outline_currentlevel_int {#1}
166 \bool_set_true:NF \l__hyp_outline_keeplevel_bool
167 }
168 }
169 ,startatroot .default:n = 0
170 ,dest .code:n =
171 {
172 \int_compare:nNnTF
173 { \bitset_item:Nn \l__hyp_outline_action_bitset {gotor} } = {1}
174 {
175 \bitset_clear:N \l__hyp_outline_action_bitset
176 \bitset_set_true:Nn \l__hyp_outline_action_bitset { gotor }
177 }
178 {
179 \bitset_clear:N \l__hyp_outline_action_bitset
180 \bitset_set_true:Nn \l__hyp_outline_action_bitset { goto }
181 }
182 \bitset_set_true:Nn \l__hyp_outline_action_bitset { namedest }
183 \tl_set:Nn\l__hyp_outline_action_dest_data_tl {#1}
184 }
185 ,dest .default:n = Doc-Start
186 ,goto .code:n =
187 {
188 \bitset_clear:N \l__hyp_outline_action_bitset
189 \bitset_set_true:Nn \l__hyp_outline_action_bitset { goto }
190 \bitset_set_true:Nn \l__hyp_outline_action_bitset { namedest }
191 \tl_set:Nn\l__hyp_outline_action_dest_data_tl {#1}
192 }
193 ,gotor .code:n =
194 {
195 \int_compare:nNnTF
196 { \bitset_item:Nn \l__hyp_outline_action_bitset {pagedest} } = {1}
197 {
198 \bitset_clear:N \l__hyp_outline_action_bitset
199 \bitset_set_true:Nn \l__hyp_outline_action_bitset { pagedest }
200 }
201 {
202 \bitset_clear:N \l__hyp_outline_action_bitset
203 \bitset_set_true:Nn \l__hyp_outline_action_bitset { namedest }
204 }
205 \bitset_set_true:Nn \l__hyp_outline_action_bitset { gotor }
206 \tl_set:Nn\l__hyp_outline_action_data_tl {#1}
207 }
208 ,named .choices:nn =
209 {FirstPage, NextPage, PrevPage, LastPage}
210 {
211 \bitset_clear:N \l__hyp_outline_action_bitset
212 \bitset_set_true:Nn \l__hyp_outline_action_bitset { named }
213 \tl_set:Nn \l__hyp_outline_action_data_tl {/#1}
214 }
215 ,page .code:n =
216 {
217 \int_compare:nNnTF
218 { \bitset_item:Nn \l__hyp_outline_action_bitset {gotor} } = {1}
219 {
220 \bitset_clear:N \l__hyp_outline_action_bitset
221 \bitset_set_true:Nn \l__hyp_outline_action_bitset { gotor }
222 }
223 {
224 \bitset_clear:N \l__hyp_outline_action_bitset
225 \bitset_set_true:Nn \l__hyp_outline_action_bitset { goto }
226 }
227 \bitset_set_true:Nn \l__hyp_outline_action_bitset { pagedest }
228 \tl_set:Nn \l__hyp_outline_action_dest_data_tl {#1}
229 }
230 ,page .default:n = 1
231 ,rawaction .code:n =
232 {
233 \bitset_clear:N \l__hyp_outline_action_bitset
234 \bitset_set_true:Nn \l__hyp_outline_action_bitset { uri }
235 \tl_set:Nn\l__hyp_outline_action_data_tl {#1}
236 }
237 ,view .code:n =
238 {
239 \tl_set:Ne \l__hyp_outline_tmpa_tl {#1~null~null~null~}
240 \exp_args:NNV
241 \regex_extract_once:NnNTF
242 \c__hyp_outline_dest_startview_regex
243 \l__hyp_outline_tmpa_tl
244 \l__hyp_outline_tmpa_seq
245 {
246 \tl_set:Ne \l__hyp_outline_action_view_tl {/\seq_item:Nn \l__hyp_outline_tmpa_seq {1}}
247 }
248 {
249 \msg_warning:nnnn {hyp/outline}{invalid-view-value}{#1}{view}
250 \tl_set:Nn \l__hyp_outline_action_view_tl {Fit}
251 }
252 }
253 ,uri .code:n =
254 {
255 \bitset_clear:N \l__hyp_outline_action_bitset
256 \bitset_set_true:Nn \l__hyp_outline_action_bitset { uri }
257 \pdf_purify:nN{#1}\l__hyp_outline_action_data_tl
258 \pdf_string_from_unicode:nVN
259 { utf8/URI } \l__hyp_outline_action_data_tl \l__hyp_outline_action_data_tl
260 }
261 ,lists .code:n =
262 { \seq_set_from_clist:Nn \l__hyp_outline_type_seq { #1 } }
263 ,lists .initial:n = toc
264 ,bookmarkstype .meta:n = {lists={#1}}
265 }
266 \NewDocumentCommand\bookmarksetup{m}{\keys_set:nn{hyp/outline}{#1}}
267 \NewHook{bookmark}
268 \NewDocumentCommand\bookmarksetupnext{m}{\AddToHookNext{bookmark}{\bookmarksetup{#1}}}
269 \cs_new:Npn\bookmarkget #1 {\use:c{__hyp_bookmarkget_#1:}}
270 \cs_new:Npn\__hyp_bookmarkget_level:{\int_use:N\l__hyp_outline_level_int}
271 \NewDocumentCommand\bookmark{O{}m}
272 {
273 \bool_if:NT \l_pdfoutline_active_bool
274 {
275 \group_begin:
276 \keys_set:nn {hyp/outline} { #1 }
277 \UseHook{bookmark}
278 \socket_use:nnn{hyp/outline/title}{#2}\l__hyp_outline_title_tl
279 \int_compare:nNnF {\l__hyp_outline_level_int} > {\l__hyp_outline_depth_int}
280 {
281 \__hyp_outline_bookmark_aux:
282 }
283 \group_end:
284 }
285 }
286 \cs_new_protected:Npn \__hyp_outline_bookmark_aux:
287 {
288 \__hyp_outline_calc_rellevel:NN \l__hyp_outline_level_int \l__hyp_outline_rellevel_tmpa_int
289 \bool_if:NF\l__hyp_outline_keeplevel_bool
290 {
291 \int_gset:Nn \g__hyp_outline_currentlevel_int { \l__hyp_outline_level_int }
292 }
293 \int_compare:nNnTF
294 {
295 \bitset_item:Nn \l__hyp_outline_action_bitset {goto} *
296 \bitset_item:Nn \l__hyp_outline_action_bitset {namedest}
297 } = {1}
298 {
299 \pdfoutline_goto:nee
300 { \l__hyp_outline_rellevel_tmpa_int } %level
301 { \l__hyp_outline_action_dest_data_tl }
302 { \l__hyp_outline_title_tl }
303 }
304 {
305 \int_case:nnF { \bitset_to_arabic:N \l__hyp_outline_action_bitset }
306 {
307 { 65 } % goto (1) + pagedest (65)
308 {
309 \pdfoutline_action:nee
310 { \l__hyp_outline_rellevel_tmpa_int }
311 { /S/GoTo~
312 /D
313 [
314 \pdf_pageobject_ref:n { \l__hyp_outline_action_dest_data_tl }~
315 \l__hyp_outline_action_view_tl
316 ]
317 }
318 { \l__hyp_outline_title_tl }
319 }
320 { 34 } % gotor (2) + namedest (32)
321 {
322 \pdfoutline_action:nee
323 { \l__hyp_outline_rellevel_tmpa_int }
324 { /S/GoToR~
325 /F ( \l__hyp_outline_action_data_tl ) %Todo check format
326 /D ( \l__hyp_outline_action_dest_data_tl ) %Todo check format
327 }
328 { \l__hyp_outline_title_tl }
329 }
330 { 66 } % gotor (2) + pagedest (64)
331 {
332 \pdfoutline_action:nee
333 { \l__hyp_outline_rellevel_tmpa_int }
334 { /S/GoToR~
335 /F ( \l__hyp_outline_action_data_tl ) %Todo check format
336 /D
337 [
338 \pdf_pageobject_ref:n { \l__hyp_outline_action_dest_data_tl }~
339 \l__hyp_outline_action_view_tl
340 ]
341 }
342 { \l__hyp_outline_title_tl }
343
344 }
345 { 4 } % named (4)
346 {
347 \pdfoutline_action:nee
348 { \l__hyp_outline_rellevel_tmpa_int }
349 { /S/Named~
350 /N \l__hyp_outline_action_data_tl %TODO check formt
351 }
352 { \l__hyp_outline_title_tl }
353
354 }
355 { 8 } % uri (8)
356 {
357 \pdfoutline_action:nee
358 { \l__hyp_outline_rellevel_tmpa_int }
359 { /S/URI~
360 /URI \l__hyp_outline_action_data_tl %TODO check formt
361 }
362 { \l__hyp_outline_title_tl }
363 }
364 { 16 } % raw (16)
365 {
366 \pdfoutline_action:nee
367 { \l__hyp_outline_rellevel_tmpa_int }
368 {
369 \l__hyp_outline_action_data_tl %TODO check formt
370 }
371 { \l__hyp_outline_title_tl }
372 }
373 }
374 { \msg_error:nn {hyp/outline}{no-action} }
375 }
376 \intarray_gset:Nnn
377 \g__hyp_outline_level_intarray
378 { \pdfoutline_id_ref_last: }
379 { \g__hyp_outline_currentlevel_int }
380 } %
381 \cs_new_protected:Npn\__hyp_outline_calc_rellevel:NN #1 #2 % #1 the requested level, #2 the return value
382 {
383 \int_compare:nNnTF
384 { #1 }
385 <
386 { \g__hyp_outline_currentlevel_int }
387 {
388 \int_set:Nn #2 { 0 }
389 \tl_set:Ne \l__hyp_outline_parent_tmpa_tl
390 { \pdfoutline_parent_ref:n { \pdfoutline_id_ref_last: } }
391 \int_compare:nNnTF
392 { \l__hyp_outline_parent_tmpa_tl } > { 0 }
393 {
394 \int_set:Nn \l__hyp_outline_tmpa_int
395 {
396 \intarray_item:Nn
397 \g__hyp_outline_level_intarray
398 { \l__hyp_outline_parent_tmpa_tl }
399 }
400 }
401 { \int_set_eq:NN \l__hyp_outline_tmpa_int #1 }
402 \int_do_while:nNnn
403 { \l__hyp_outline_tmpa_int }
404 >
405 { #1 }
406 {
407 \int_case:nn
408 {
409 \int_sign:n
410 { \l__hyp_outline_tmpa_int-#1 }
411 }
412 {
413 { 0 } { \int_decr:N #2 }
414 { 1 }
415 {
416 \int_decr:N #2
417 \tl_set:Ne \l__hyp_outline_parent_tmpa_tl
418 { \pdfoutline_parent_ref:n { \l__hyp_outline_parent_tmpa_tl } }
419 \int_compare:nNnTF
420 { \l__hyp_outline_parent_tmpa_tl } > { 1 }
421 {
422 \int_set:Nn \l__hyp_outline_tmpa_int
423 {
424 \intarray_item:Nn
425 \g__hyp_outline_level_intarray
426 { \l__hyp_outline_parent_tmpa_tl }
427 }
428 }
429 {
430 % root
431 \int_set_eq:NN \l__hyp_outline_tmpa_int #1
432 }
433 }
434 }
435 }
436 \int_if_zero:nT {\l__hyp_outline_tmpa_int-#1}{\int_decr:N #2}
437 }
438 {
439 \int_set:Nn #2
440 { #1 - \g__hyp_outline_currentlevel_int }
441 }
442 }
443 \disable@package@load{bookmark}{\RequirePackage{hyperref}}
444 \DeclareHookRule{package/hyperref/after}%
445 {latex-lab-testphase-bookmark}{voids}{latex-lab-testphase-sec-template}
446 \DeclareHookRule{package/hyperref/after}%
447 {latex-lab-testphase-bookmark}{voids}{latex-lab-testphase-sec}
448 \DeclareHookRule{package/hyperref/after}%
449 {latex-lab-testphase-bookmark}{voids}{latex-lab-testphase-toc}
450
451 \AddToHook{package/hyperref/after}
452 {
453 \RemoveFromHook{cmd/addcontentsline/before}[hyp]
454 \AddToHookWithArguments{cmd/addcontentsline/before}[hyp/outline]
455 { \__hyp_addcontentsline_bookmark:nnn {#1}{#2}{#3} }
456 \providecommand\addcontentslinebookmark{}
457 \providecommand\addcontentslinebookmarkOff{}
458 \RenewCommandCopy\addcontentslinebookmark\__hyp_addcontentsline_bookmark:nnn
459 \renewcommand\addcontentslinebookmarkOff
460 {
461 \bool_if:NTF \l_pdfoutline_active_bool
462 {
463 \def\addcontentslinebookmarkReset{\bool_set_true:N\l_pdfoutline_active_bool}
464 }
465 {
466 \let\addcontentslinebookmarkReset\relax
467 }
468 \bool_set_false:N\l_pdfoutline_active_bool
469 }
470 \legacy_if:nF{Hy@bookmarks}{\bool_set_false:N\l_pdfoutline_active_bool}
471 \renewcommand*{\pdfbookmark}[3][0]{%
472 \bookmark[level=#1,dest={#3.#1}]{#2}%
473 \hyper@anchorstart{#3.#1}\hyper@anchorend}
474 \def\currentpdfbookmark#1#2#3{%
475 \bookmark[rellevel=0,dest={#3.#1}]{#2}%
476 \hyper@anchorstart{#3.#1}\hyper@anchorend}
477 \def\subpdfbookmark#1#2#3{%
478 \bookmark[rellevel=1,dest={#3.#1}]{#2}%
479 \hyper@anchorstart{#3.#1}\hyper@anchorend}
480 \def\belopdfbookmark#1#2#3{%
481 \bookmark[keeplevel,rellevel=1,dest={#3.#1}]{#2}%
482 \hyper@anchorstart{#3.#1}\hyper@anchorend}
483 \keys_define:nn{hyp}
484 {bookmarksdepth .meta:nn = {hyp/outline}{depth=#1},
485 bookmarksopen .meta:nn = {hyp/outline}{open},
486 bookmarksopenlevel .meta:nn = {hyp/outline}{openlevel=#1},
487 bookmarksnumbered .meta:nn = {hyp/outline}{numbered}}
488 }
489 \DeclareHookRule{package/hyperref/after}{latex-lab-testphase-bookmark}{after}{latex-lab-testphase-toc}
490 \cs_new_protected:Npn \__hyp_addcontentsline_bookmark:nnn #1 #2 #3 %%#1 toc type, #2 level, #3 content
491 {
492 \seq_if_in:NeT \l__hyp_outline_type_seq { #1 }
493 {
494 \tl_if_empty:NT\@currentHref
495 { \MakeLinkTarget[page] {} }
496 \tl_if_exist:cF { toclevel@#2 }
497 {
498 \tl_new:c { toclevel@#2 }
499 \tl_gset:cn { toclevel@#2 } { 0 }
500 % message
501 }
502 \group_begin:
503 \socket_use:n{hyp/outline/numberformat}
504 \bookmark[level=#2,dest={\HyperDestNameFilter{\@currentHref}}]{#3}
505 \group_end:
506 }
507 }
508
509 %%
510 %%
511 %% End of file `latex-lab-testphase-bookmark.sty'.