Debian Codegraph @

texmf-dist/source/latex/tagpdf/tagpdf-tree.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: tagpdf-tree.dtx
4 %
5 % Copyright (C) 2019-2026 Ulrike Fischer
6 %
7 % It may be distributed and/or modified under the conditions of the
8 % LaTeX Project Public License (LPPL), either version 1.3c of this
9 % license or (at your option) any later version. The latest version
10 % of this license is in the file
11 %
12 % https://www.latex-project.org/lppl.txt
13 %
14 % This file is part of the "tagpdf bundle" (The Work in LPPL)
15 % and all files in that bundle must be distributed together.
16 %
17 % -----------------------------------------------------------------------
18 %
19 % The development version of the bundle can be found at
20 %
21 % https://github.com/latex3/tagpdf
22 %
23 % for those people who are interested.
24 %
25 %<*driver>
26 \DocumentMetadata{tagging=on}
27 \documentclass{l3in2edoc}
28 \usepackage{array,booktabs,caption}
29 \hypersetup{pdfauthor=Ulrike Fischer,
30 pdftitle=tagpdf-tree module (tagpdf)}
31 \begin{document}
32 \DocInput{\jobname.dtx}
33 \end{document}
34 %</driver>
35 % \fi
36 % \title{^^A
37 % The \pkg{tagpdf-tree} module\\ Commands trees and main dictionaries ^^A
38 % }
39 %
40 % \author{^^A
41 % Ulrike Fischer\thanks
42 % {^^A
43 % E-mail:
44 % \href{mailto:[email protected]}
45 % {[email protected]}^^A
46 % }^^A
47 % }
48 %
49 % \date{Version 1.0c, released 2026-05-17}
50 % \maketitle
51 % \begin{implementation}
52 % \begin{macrocode}
53 %<@@=tag>
54 %<*header>
55 \ProvidesExplPackage {tagpdf-tree-code} {2026-05-17} {1.0c}
56 {part of tagpdf - code related to writing trees and dictionaries to the pdf}
57 %</header>
58 % \end{macrocode}
59 % \section{Trees, pdfmanagement and finalization code}
60 %
61 % The code to finish the structure is in a hook.
62 % This will perhaps at the end be a kernel hook.
63 % TODO check right place for the code
64 % The pdfmanagement code is the kernel hook after
65 % shipout/lastpage so all code affecting it should be before.
66 % Objects can be written later, at least in pdf mode.
67 % \begin{macrocode}
68 %<*package>
69 \hook_gput_code:nnn{begindocument}{tagpdf}
70 {
71 \bool_if:NT \g_@@_active_tree_bool
72 {
73 \sys_if_output_pdf:TF
74 {
75 \AddToHook{enddocument/end} { \@@_finish_structure: }
76 }
77 {
78 \AddToHook{shipout/lastpage} { \@@_finish_structure: }
79 }
80 }
81 }
82 % \end{macrocode}
83 % \subsection{Check structure}
84 % \begin{macro}{\@@_tree_final_checks:}
85 % \begin{macrocode}
86 \cs_new_protected:Npn \@@_tree_final_checks:
87 {
88 \int_compare:nNnF {\seq_count:N\g_@@_struct_stack_seq}={1}
89 {
90 \msg_warning:nn {tag}{tree-struct-still-open}
91 \int_step_inline:nnn{2}{\seq_count:N\g_@@_struct_stack_seq}
92 {\tag_struct_end:}
93 }
94 \socket_use:n { tag/check/parent-child-end }
95 \msg_note:nn {tag}{tree-statistic}
96 }
97 % \end{macrocode}
98 % \end{macro}
99 %
100 % \subsection{Catalog: MarkInfo and StructTreeRoot and OpenAction}
101 % The StructTreeRoot and the MarkInfo entry must be added to the catalog.
102 % If there is an OpenAction entry we must update it,
103 % so that it contains also a structure destination.
104 % We do it late so that we can win, but before the pdfmanagement hook.
105 % \begin{macro}{@@/struct/1}
106 % This is the object for the root object, the StructTreeRoot
107 % \begin{macrocode}
108 \pdf_object_new_indexed:nn { @@/struct }{ 1 }
109 % \end{macrocode}
110 % \end{macro}
111 %
112 % \begin{variable}{\g_@@_tree_openaction_struct_tl}
113 % We need a variable that indicates which structure is wanted in the OpenAction. By default we use
114 % 2 (the Document structure).
115 % \begin{macrocode}
116 \tl_new:N \g_@@_tree_openaction_struct_tl
117 \tl_gset:Nn \g_@@_tree_openaction_struct_tl { 2 }
118 % \end{macrocode}
119 % \end{variable}
120 %
121 % \begin{macro}{viewer/startstructure (setup-key)}
122 % We also need an option to setup the start structure. So we setup a key
123 % which sets the variable to the current structure. This still requires
124 % hyperref to do most of the job, this should perhaps be changed.
125 % \begin{macrocode}
126 \keys_define:nn { @@ / setup }
127 {
128 viewer/startstructure .code:n =
129 {
130 \tl_gset:Ne \g_@@_tree_openaction_struct_tl {#1}
131 }
132 ,viewer/startstructure .default:n = { \int_use:N \c@g_@@_struct_abs_int }
133 }
134 % \end{macrocode}
135 % \end{macro}
136 % The OpenAction should only be updated if it is there. So we inspect the
137 % Catalog-prop:
138 % \begin{macrocode}
139 \cs_new_protected:Npn \@@_tree_update_openaction:
140 {
141 \prop_get:cnNT
142 { \__kernel_pdfdict_name:n { g__pdf_Core/Catalog } }
143 {OpenAction}
144 \l_@@_tmpa_tl
145 {
146 % \end{macrocode}
147 % we only do something if the OpenAction is an array (as set by hyperref)
148 % in other cases we hope that the author knows what they did.
149 % \begin{macrocode}
150 \tl_if_head_eq_charcode:eNT { \tl_trim_spaces:o { \l_@@_tmpa_tl } } [ %]
151 {
152 \seq_set_split:Nno\l_@@_tmpa_seq {/} {\l_@@_tmpa_tl}
153 \pdfmanagement_add:nne {Catalog} { OpenAction }
154 {
155 <<
156 /S/GoTo \c_space_tl
157 /D~\l_@@_tmpa_tl\c_space_tl
158 /SD~[\pdf_object_ref_indexed:nn{@@/struct}{\g_@@_tree_openaction_struct_tl}
159 % \end{macrocode}
160 % there should be always a /Fit etc in the array but better play safe here ...
161 % \begin{macrocode}
162 \int_compare:nNnTF{ \seq_count:N \l_@@_tmpa_seq } > {1}
163 { /\seq_item:Nn\l_@@_tmpa_seq{2} }
164 { ] }
165 >>
166 }
167 }
168 }
169 }
170 % \end{macrocode}
171 %
172 % \begin{macrocode}
173 \hook_gput_code:nnn{shipout/lastpage}{tagpdf}
174 {
175 \bool_if:NT \g_@@_active_tree_bool
176 {
177 \pdfmanagement_add:nnn { Catalog / MarkInfo } { Marked } { true }
178 \pdfmanagement_add:nne
179 { Catalog }
180 { StructTreeRoot }
181 { \pdf_object_ref_indexed:nn { @@/struct } { 1 } }
182 \@@_tree_update_openaction:
183 }
184 }
185 % \end{macrocode}
186 %
187 % \subsection{Writing the IDtree}
188 %
189 % The ID are currently quite simple: every structure has an ID build from
190 % the prefix ID together with the structure number padded with enough zeros to
191 % that we get directly an lexical order. We ship them out in bundles
192 % At first a seq to hold the references for the kids
193 % \begin{variable}{\g_@@_tree_id_pad_int}
194 % \begin{macrocode}
195 \int_new:N\g_@@_tree_id_pad_int
196 % \end{macrocode}
197 % \end{variable}
198 % Now we get the needed padding
199 % \begin{macrocode}
200 \cs_generate_variant:Nn \tl_count:n {e}
201 \hook_gput_code:nnn{begindocument}{tagpdf}
202 {
203 \int_gset:Nn\g_@@_tree_id_pad_int
204 {\tl_count:e { \@@_property_ref_lastpage:nn{tagstruct}{1000}}+1}
205 }
206
207 % \end{macrocode}
208 % This is the main code to write the tree it basically splits the
209 % existing structure numbers in chunks of length 50
210 % TODO consider is 50 is a good length.
211 % \begin{macrocode}
212 \cs_new_protected:Npn \@@_tree_write_idtree:
213 {
214 \tl_clear:N \l_@@_tmpa_tl
215 \tl_clear:N \l_@@_tmpb_tl
216 \int_zero:N \l_@@_tmpa_int
217 \int_step_inline:nnn {2} {\c@g_@@_struct_abs_int}
218 {
219 \int_incr:N\l_@@_tmpa_int
220 \tl_put_right:Ne \l_@@_tmpa_tl
221 {
222 \@@_struct_get_id:n{##1}~\pdf_object_ref_indexed:nn {@@/struct}{##1}~
223 }
224 \int_compare:nNnF {\l_@@_tmpa_int}<{50} %
225 {
226 \pdf_object_unnamed_write:ne {dict}
227 { /Limits~[\@@_struct_get_id:n{##1-\l_@@_tmpa_int+1}~\@@_struct_get_id:n{##1}]
228 /Names~[\l_@@_tmpa_tl]
229 }
230 \tl_put_right:Ne\l_@@_tmpb_tl {\pdf_object_ref_last:\c_space_tl}
231 \int_zero:N \l_@@_tmpa_int
232 \tl_clear:N \l_@@_tmpa_tl
233 }
234 }
235 \tl_if_empty:NF \l_@@_tmpa_tl
236 {
237 \pdf_object_unnamed_write:ne {dict}
238 {
239 /Limits~
240 [\@@_struct_get_id:n{\c@g_@@_struct_abs_int-\l_@@_tmpa_int+1}~
241 \@@_struct_get_id:n{\c@g_@@_struct_abs_int}]
242 /Names~[\l_@@_tmpa_tl]
243 }
244 \tl_put_right:Ne\l_@@_tmpb_tl {\pdf_object_ref_last:}
245 }
246 \pdf_object_unnamed_write:ne {dict}{/Kids~[\l_@@_tmpb_tl]}
247 \@@_prop_gput:cne
248 { g_@@_struct_1_prop }
249 { IDTree }
250 { \pdf_object_ref_last: }
251 }
252 % \end{macrocode}
253 %
254 % \subsection{Writing structure elements}
255 % The following commands are needed to write out the structure.
256 % \begin{macro}{\@@_tree_write_structtreeroot:}
257 % This writes out the root object.
258 % \begin{macrocode}
259 \cs_new_protected:Npn \@@_tree_write_structtreeroot:
260 {
261 \@@_prop_gput:cne
262 { g_@@_struct_1_prop }
263 { ParentTree }
264 { \pdf_object_ref:n { @@/tree/parenttree } }
265 \@@_prop_gput:cne
266 { g_@@_struct_1_prop }
267 { RoleMap }
268 { \pdf_object_ref:n { @@/tree/rolemap } }
269 \@@_struct_fill_kid_key:n { 1 }
270 \prop_gremove:cn { g_@@_struct_1_prop } {S}
271 \@@_struct_get_dict_content:nN { 1 } \l_@@_tmpa_tl
272 \pdf_object_write_indexed:nnne
273 { @@/struct } { 1 }
274 {dict}
275 {
276 \l_@@_tmpa_tl
277 }
278 % \end{macrocode}
279 % Better put S back, see https://github.com/latex3/tagging-project/issues/86
280 % \begin{macrocode}
281 \prop_gput:cnn { g_@@_struct_1_prop } {S}{ /StructTreeRoot }
282 }
283 % \end{macrocode}
284 % \end{macro}
285 %
286 % \begin{macro}{\@@_tree_write_structelements:}
287 % This writes out the other struct elems, the absolute number is in the counter.
288 % \begin{macrocode}
289 \cs_new_protected:Npn \@@_tree_write_structelements:
290 {
291 \int_step_inline:nnnn {2}{1}{\c@g_@@_struct_abs_int}
292 {
293 \@@_struct_write_obj:n { ##1 }
294 }
295 }
296 % \end{macrocode}
297 % \end{macro}
298 %
299 % \subsection{ParentTree}
300 % \begin{macro}{@@/tree/parenttree}
301 % The object which will hold the parenttree
302 % \begin{macrocode}
303 \pdf_object_new:n { @@/tree/parenttree }
304 % \end{macrocode}
305 % \end{macro}
306 % The ParentTree maps numbers to objects or (if the number represents a page)
307 % to arrays of objects. The numbers refer to two distinct types of entries:
308 % page streams and real objects like annotations.
309 % The numbers must be distinct and ordered.
310 % So we rely on abspage for the pages and put the real objects at the end.
311 % We use a counter to have a chance to get the correct number
312 % if code is processed twice.
313 %
314 % \begin{macro}{\c@g_@@_parenttree_obj_int}
315 % This is a counter for the real objects. It starts at the absolute last page
316 % value. It relies on l3ref.
317 % \begin{macrocode}
318 \int_new:N \c@g_@@_parenttree_obj_int
319 \hook_gput_code:nnn{begindocument}{tagpdf}
320 {
321 \int_gset:Nn
322 \c@g_@@_parenttree_obj_int
323 { \@@_property_ref_lastpage:nn{abspage}{100} }
324 }
325 % \end{macrocode}
326 % \end{macro}
327 % We store the number/object references in a tl-var. If more structure is needed
328 % one could switch to a seq.
329 % \begin{variable}{ \g_@@_parenttree_objr_tl }
330 % \begin{macrocode}
331 \tl_new:N \g_@@_parenttree_objr_tl
332 % \end{macrocode}
333 % \end{variable}
334 %
335 % \begin{macro}{ \@@_parenttree_add_objr:nn }
336 % This command stores a StructParent number and a objref into the tl var.
337 % This is only for objects like annotations, pages are handled elsewhere.
338 % \begin{macrocode}
339 \cs_new_protected:Npn \@@_parenttree_add_objr:nn #1 #2 %#1 StructParent number, #2 objref
340 {
341 \tl_gput_right:Ne \g_@@_parenttree_objr_tl
342 {
343 #1 \c_space_tl #2 ^^J
344 }
345 }
346 % \end{macrocode}
347 % \end{macro}
348 %
349 % \begin{variable}{\l_@@_parenttree_content_tl}
350 % A tl-var which will get the page related parenttree content.
351 % \begin{macrocode}
352 \tl_new:N \l_@@_parenttree_content_tl
353 % \end{macrocode}
354 % \end{variable}
355 %
356 % \begin{macro}{\@@_tree_fill_parenttree:}
357 % This is the main command to assemble the page related entries of the parent tree.
358 % It wanders through the pages and the mcid numbers and collects all mcid of one page.
359 % \begin{macrocode}
360 \cs_new_protected:Npn \@@_tree_parenttree_rerun_msg: {}
361 \cs_new_protected:Npn \@@_tree_fill_parenttree:
362 {
363 \int_step_inline:nnnn{1}{1}{\@@_property_ref_lastpage:nn{abspage}{-1}} %not quite clear if labels are needed. See lua code
364 { %page ##1
365 \prop_clear:N \l_@@_tmpa_prop
366 \int_step_inline:nnnn{1}{1}{\@@_property_ref_lastpage:nn{tagmcabs}{-1}}
367 {
368 %mcid####1
369 \int_compare:nT
370 {\property_ref:enn{mcid-####1}{tagabspage}{-1}=##1} %mcid is on current page
371 {% yes
372 \prop_get:NnNT
373 \g_@@_mc_parenttree_prop
374 {####1}
375 \l_@@_tmpa_tl
376 {
377 \prop_put:Nee
378 \l_@@_tmpa_prop
379 {\property_ref:enn{mcid-####1}{tagmcid}{-1}}
380 {\l_@@_tmpa_tl}
381 }
382 }
383 }
384 \tl_put_right:Ne\l_@@_parenttree_content_tl
385 {
386 \int_eval:n {##1-1}\c_space_tl
387 [\c_space_tl %]
388 }
389 \int_step_inline:nnnn %####1
390 {0}
391 {1}
392 { \prop_count:N \l_@@_tmpa_prop -1 }
393 {
394 \prop_get:NnNTF \l_@@_tmpa_prop {####1} \l_@@_tmpa_tl
395 {% page#1:mcid##1:\l_@@_tmpa_tl :content
396 \tl_put_right:Ne \l_@@_parenttree_content_tl
397 {
398 \prop_if_exist:cTF { g_@@_struct_ \l_@@_tmpa_tl _prop }
399 {
400 \pdf_object_ref_indexed:nn { @@/struct }{ \l_@@_tmpa_tl }
401 }
402 {
403 null
404 }
405 \c_space_tl
406 }
407 }
408 {
409 \cs_set_protected:Npn \@@_tree_parenttree_rerun_msg:
410 {
411 \msg_warning:nn { tag } {tree-mcid-index-wrong}
412 }
413 }
414 }
415 \tl_put_right:Nn
416 \l_@@_parenttree_content_tl
417 {%[
418 ]^^J
419 }
420 }
421 }
422 % \end{macrocode}
423 % \end{macro}
424 %
425 % \begin{macro}{\@@_tree_lua_fill_parenttree:}
426 % This is a special variant for luatex.
427 % lua mode must/can do it differently.
428 % \begin{macrocode}
429 \cs_new_protected:Npn \@@_tree_lua_fill_parenttree:
430 {
431 \tl_set:Nn \l_@@_parenttree_content_tl
432 {
433 \lua_now:e
434 {
435 ltx.@@.func.output_parenttree
436 (
437 \int_use:N\g_shipout_readonly_int
438 )
439 }
440 }
441 }
442 % \end{macrocode}
443 % \end{macro}
444 %
445 % \begin{macro}{\@@_tree_write_parenttree:}
446 % This combines the two parts and writes out the object.
447 % TODO should the check for lua be moved into the backend code?
448 % \begin{macrocode}
449 \cs_new_protected:Npn \@@_tree_write_parenttree:
450 {
451 \bool_if:NTF \g_@@_mode_lua_bool
452 {
453 \@@_tree_lua_fill_parenttree:
454 }
455 {
456 \@@_tree_fill_parenttree:
457 }
458 \@@_tree_parenttree_rerun_msg:
459 \tl_put_right:No \l_@@_parenttree_content_tl { \g_@@_parenttree_objr_tl }
460 \pdf_object_write:nne { @@/tree/parenttree }{dict}
461 {
462 /Nums\c_space_tl [\l_@@_parenttree_content_tl]
463 }
464 }
465 % \end{macrocode}
466 % \end{macro}
467 %
468 % \subsection{Rolemap dictionary}
469 % The Rolemap dictionary describes relations between new tags and standard types.
470 % The main part here is handled in the role module, here we only define the
471 % command which writes it to the PDF.
472 % \begin{variable}{@@/tree/rolemap}
473 % At first we reserve again an object.
474 % Rolemap is also used in PDF 2.0 as a fallback.
475 % \begin{macrocode}
476 \pdf_object_new:n { @@/tree/rolemap }
477 % \end{macrocode}
478 % \end{variable}
479 %
480 % \begin{macro}{\@@_tree_write_rolemap:}
481 % This writes out the rolemap, basically it simply pushes out
482 % the dictionary which has been filled in the role module.
483 % \begin{macrocode}
484 \cs_new_protected:Npn \@@_tree_write_rolemap:
485 {
486 \bool_if:NT \g_@@_role_add_mathml_bool
487 {
488 \prop_map_inline:Nn \g_@@_role_NS_mathml_prop
489 {
490 \prop_gput:Nnn \g_@@_role_rolemap_prop {##1}{Span}
491 }
492 }
493 \prop_map_inline:Nn\g_@@_role_rolemap_prop
494 {
495 \tl_if_eq:nnF {##1}{##2}
496 {
497 \pdfdict_gput:nne {g_@@_role/RoleMap_dict}
498 {##1}
499 {\pdf_name_from_unicode_e:n{##2}}
500 }
501 }
502 \pdf_object_write:nne { @@/tree/rolemap }{dict}
503 {
504 \pdfdict_use:n{g_@@_role/RoleMap_dict}
505 }
506 }
507 % \end{macrocode}
508 % \end{macro}
509 %
510 % \subsection{Classmap dictionary}
511 % Classmap and attributes are setup in the struct module, here is only the
512 % code to write it out. It should only done if values have been used.
513 % \begin{macro}{\@@_tree_write_classmap:}
514 % \begin{macrocode}
515 \cs_new_protected:Npn \@@_tree_write_classmap:
516 {
517 \tl_clear:N \l_@@_tmpa_tl
518 % \end{macrocode}
519 % We process the older sec for compatibility with the table code.
520 % TODO: check if still needed
521 % \begin{macrocode}
522 \seq_map_inline:Nn \g_@@_attr_class_used_seq
523 {
524 \prop_gput:Nnn \g_@@_attr_class_used_prop {##1}{}
525 }
526 \prop_map_inline:Nn \g_@@_attr_class_used_prop
527 {
528 \prop_get:NnNT \g_@@_attr_entries_prop {##1} \l_@@_tmpb_tl
529 {
530 \tl_put_right:Ne \l_@@_tmpa_tl
531 {
532 ##1\c_space_tl
533 <<
534 \l_@@_tmpb_tl
535 >>
536 \iow_newline:
537 }
538 }
539 }
540 \tl_if_empty:NF
541 \l_@@_tmpa_tl
542 {
543 \pdf_object_new:n { @@/tree/classmap }
544 \pdf_object_write:nne
545 { @@/tree/classmap }
546 {dict}
547 { \l_@@_tmpa_tl }
548 \@@_prop_gput:cne
549 { g_@@_struct_1_prop }
550 { ClassMap }
551 { \pdf_object_ref:n { @@/tree/classmap } }
552 }
553 }
554 % \end{macrocode}
555 % \end{macro}
556 % \subsection{Namespaces}
557 % Namespaces are handle in the role module, here is the code to write them out.
558 % Namespaces are only relevant for pdf2.0.
559 % \begin{variable}{@@/tree/namespaces}
560 % \begin{macrocode}
561 \pdf_object_new:n { @@/tree/namespaces }
562 % \end{macrocode}
563 % \end{variable}
564 % \begin{macro}{\@@_tree_write_namespaces:}
565 % \begin{macrocode}
566 \cs_new_protected:Npn \@@_tree_write_namespaces:
567 {
568 \pdf_version_compare:NnF < {2.0}
569 {
570 \prop_map_inline:Nn \g_@@_role_NS_prop
571 {
572 \pdfdict_if_empty:nF {g_@@_role/RoleMapNS_##1_dict}
573 {
574 \pdf_object_write:nne {@@/RoleMapNS/##1}{dict}
575 {
576 \pdfdict_use:n {g_@@_role/RoleMapNS_##1_dict}
577 }
578 \pdfdict_gput:nne{g_@@_role/Namespace_##1_dict}
579 {RoleMapNS}{\pdf_object_ref:n {@@/RoleMapNS/##1}}
580 }
581 \pdf_object_write:nne{tag/NS/##1}{dict}
582 {
583 \pdfdict_use:n {g_@@_role/Namespace_##1_dict}
584 }
585 }
586 \pdf_object_write:nne {@@/tree/namespaces}{array}
587 {
588 \prop_map_tokens:Nn \g_@@_role_NS_prop{\use_ii:nn}
589 }
590 }
591 }
592 % \end{macrocode}
593 % \end{macro}
594 % \subsection{Finishing the structure}
595 % This assembles the various parts.
596 % TODO (when tabular are done or if someone requests it): IDTree
597 % \begin{macro}{ \@@_finish_structure: }
598 % \begin{macrocode}
599 \hook_new:n {tagpdf/finish/before}
600 \cs_new_protected:Npn \@@_finish_structure:
601 {
602 \bool_if:NT\g_@@_active_tree_bool
603 {
604 \hook_use:n {tagpdf/finish/before}
605 \@@_tree_final_checks:
606 \iow_term:n{Package~tagpdf~Info:~writing~ParentTree}
607 \@@_check_benchmark_tic:
608 \@@_tree_write_parenttree:
609 \@@_check_benchmark_toc:
610 \iow_term:n{Package~tagpdf~Info:~writing~IDTree}
611 \@@_check_benchmark_tic:
612 \@@_tree_write_idtree:
613 \@@_check_benchmark_toc:
614 \iow_term:n{Package~tagpdf~Info:~writing~RoleMap}
615 \@@_check_benchmark_tic:
616 \@@_tree_write_rolemap:
617 \@@_check_benchmark_toc:
618 \iow_term:n{Package~tagpdf~Info:~writing~ClassMap}
619 \@@_check_benchmark_tic:
620 \@@_tree_write_classmap:
621 \@@_check_benchmark_toc:
622 \iow_term:n{Package~tagpdf~Info:~writing~NameSpaces}
623 \@@_check_benchmark_tic:
624 \@@_tree_write_namespaces:
625 \@@_check_benchmark_toc:
626 \iow_term:n{Package~tagpdf~Info:~writing~StructElems}
627 \@@_check_benchmark_tic:
628 \@@_tree_write_structelements: %this is rather slow!!
629 \@@_check_benchmark_toc:
630 \iow_term:n{Package~tagpdf~Info:~writing~Root}
631 \@@_check_benchmark_tic:
632 \@@_tree_write_structtreeroot:
633 \@@_check_benchmark_toc:
634 }
635 }
636 %</package>
637 % \end{macrocode}
638 % \end{macro}
639 %
640 % \subsection{StructParents entry for Page}
641 % We need to add to the Page resources the |StructParents| entry, this is simply the
642 % absolute page number.
643 % \begin{macrocode}
644 %<*package>
645 \hook_gput_code:nnn{begindocument}{tagpdf}
646 {
647 \bool_if:NT\g_@@_active_tree_bool
648 {
649 \hook_gput_code:nnn{shipout/before} { tagpdf/structparents }
650 {
651 \pdfmanagement_add:nne
652 { Page }
653 { StructParents }
654 { \int_eval:n { \g_shipout_readonly_int} }
655 }
656 }
657 }
658 %</package>
659 % \end{macrocode}
660 % \end{implementation}
661 % \PrintIndex