summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tagpdf/tagpdf.dtx
blob: ba473d7022f6c7398a2472e146403916204c8e77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
% \iffalse meta-comment
%
%% File: tagpdf.dtx
%
% Copyright (C) 2019-2020 Ulrike Fischer
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version.  The latest version
% of this license is in the file
%
%    https://www.latex-project.org/lppl.txt
%
% This file is part of the "tagpdf bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
%    https://github.com/u-fischer/tagpdf
%
% for those people who are interested.
%
% \fi
%
%    \begin{macrocode}
%<@@=tag>
%<*package>
\ProvidesExplPackage {tagpdf} {2021/05/14} {0.81}
  { A package to experiment with pdf tagging }

\bool_if:nF
  {
    \bool_lazy_and_p:nn
      {\cs_if_exist_p:N \pdfmanagement_if_active_p:}
      { \pdfmanagement_if_active_p: }
  }
  {  %error for now, perhaps warning later.
    \PackageError{tagpdf}
     {
       PDF~resource~management~is~no~active!\MessageBreak
       tagpdf~will~no~work.
     }
     {
       Activate~it~with \MessageBreak
       \string\RequirePackage{pdfmanagement-testphase}\MessageBreak
       \string\DeclareDocumentMetadata{<options>}\MessageBreak
       before~\string\documentclass
     }
  }

%\debug_on:n{check-declarations,check-expressions,deprecation}

%map internal tag to package name
\prop_if_exist:NT \g_msg_module_name_prop
  {
    \prop_gput:Nnn \g_msg_module_name_prop { tag }{ tagpdf }
  }

% storing internal names to my name space:
\cs_set_eq:NN \@@_tex_global:D              \tex_global:D

%%% package options
\bool_new:N\g_@@_mode_lua_bool

\DeclareOption {luamode}    { \sys_if_engine_luatex:T { \bool_gset_true:N \g_@@_mode_lua_bool } }
\DeclareOption {genericmode}{ \bool_gset_false:N\g_@@_mode_lua_bool }
\ExecuteOptions{luamode}
\ProcessOptions

%%% some packages
%references use l3ref-tmp
\RequirePackage{l3ref-tmp}
 %================
 % temporary code
 % ===============
 % faking the LastPage label:
 \cs_new_protected:Npn \@@_lastpagelabel:
   {
     \legacy_if:nT { @filesw }
       {
         \exp_args:NNnx \exp_args:NNx\iow_now:Nn \@auxout
            {
              \token_to_str:N \newlabeldata
                {@@_LastPage}
                {
                  {abspage} { \int_use:N \g_shipout_readonly_int}
                  {tagmcabs}{ \int_use:N \c@g_@@_MCID_abs_int }
                }
            }
       }
   }

 \AddToHook{enddocument/afterlastpage}
  {\@@_lastpagelabel:}

 % a command to override the general default. See issue in ref
 \cs_if_exist:NF \ref_value:nnn
   {
     \cs_new:Npn \ref_value:nnn #1#2#3
       {
         \exp_args:Nee
           \__ref_value:nnn
            { \tl_to_str:n {#1} } { \tl_to_str:n {#2} } {#3}
       }
     \cs_new:Npn \__ref_value:nnn #1#2#3
       {
         \tl_if_exist:cTF { g__ref_label_ #1 _ #2 _tl }
           { \tl_use:c { g__ref_label_ #1 _ #2 _tl } }
           {
             % test if attribute exist at all?
             #3
           }
       }
   }

 %=============
 % attributes
 %=============
\ref_attribute_gset:nnnn {tagstruct}    {0}{now}    { \int_use:N \c@g_@@_struct_abs_int }
\ref_attribute_gset:nnnn {tagstructobj} {}{now}
 {
  \exp_args:Ne
   \pdf_object_if_exist:nT {@@/struct/\int_use:N \c@g__tag_struct_abs_int}
    {
      \pdf_object_ref:e{@@/struct/\int_use:N \c@g_@@_struct_abs_int}
    }
 }
 % replace by abspage??
\ref_attribute_gset:nnnn {tagabspage}{0}{shipout}{ \int_use:N \g_shipout_readonly_int }
\ref_attribute_gset:nnnn {tagmcabs } {0}{now}    { \int_use:N \c@g_@@_MCID_abs_int }
\ref_attribute_gset:nnnn {tagmcid }  {0}{now}    { \int_use:N \g_@@_MCID_tmp_bypage_int }
%============
% lists
%============
\clist_const:Nn \c_@@_refmc_clist     {tagabspage,tagmcabs,tagmcid} %mc is new!!
\clist_const:Nn \c_@@_refstruct_clist {tagstruct,tagstructobj}
%=================
% command to set a label
%================
\cs_generate_variant:Nn \ref_label:nn { nv }
\cs_new_protected:Npn \@@_ref_label:nn #1 #2 %#1 label, #2 name of list mc or struct
  {
    \@bsphack
    \ref_label:nv {#1}{c_@@_ref#2_clist}
    \@esphack
  }
%==============
% command to retrieve the value
%===============
\cs_new:Npn \@@_ref_value:nnn #1 #2 #3 %#1 label, #2 attribute, #3 default
  {
    \ref_value:nnn {#1}{#2}{#3}
  }
%===============
% the LastPage label has a different name, so we need a special command for now
% =============
\cs_new:Npn \@@_ref_value_lastpage:nn #1 #2
  {
    \ref_value:nnn {@@_LastPage}{#1}{#2}
  }

% as ref doesn't expand label names we need variants:
\cs_generate_variant:Nn \@@_ref_label:nn {en}
\cs_generate_variant:Nn \@@_ref_value:nnn {enn}

\RequirePackage{etoolbox}
%\RequirePackage{l3pdf}
%\RequirePackage{pdfescape} %check if needed
%\RequirePackage{pdftexcmds}%check if needed (expandable commands!)

%\RequirePackage{l3str-convert}
\cs_generate_variant:Nn \str_set_convert:Nnnn {Nonn, Noon, Nnon }




%%% tagpdfsetup,
%%% TODO: checks need to be improved
\int_new:N  \l_@@_loglevel_int
\tl_new:N   \l_@@_tree_tabs_order_tl

\keys_define:nn { @@ / setup }
  {
    activate-mc     .bool_gset:N = \g_@@_active_mc_bool,
    activate-tree   .bool_gset:N = \g_@@_active_tree_bool,
    activate-struct .bool_gset:N = \g_@@_active_struct_bool,
    activate-all    .meta:n ={activate-mc,activate-tree,activate-struct},
    check-tags      .bool_gset:N = \g_@@_check_tags_bool,
    check-tags      .initial:n  = true,
    log             .choice:,
    log / none      .code:n = {\int_set:Nn \l_@@_loglevel_int { 0 }},
    log / v         .code:n = {\int_set:Nn \l_@@_loglevel_int { 1 }},
    log / vv        .code:n = {\int_set:Nn \l_@@_loglevel_int { 2 }},
    log / vvv       .code:n = {\int_set:Nn \l_@@_loglevel_int { 3 }},
    log / all       .code:n = {\int_set:Nn \l_@@_loglevel_int { 10 }},
    tagunmarked     .bool_gset:N = \g_@@_tagunmarked_bool,
    tagunmarked     .initial:n  = true,
    tabsorder       .choice:,
    tabsorder / row       .code:n = %{\tl_set:Nn \l_@@_tree_tabs_order_tl {/Tabs/R}},
      \pdfmanagement_add:nnn { Page } {Tabs}{/R},
    tabsorder / column    .code:n = %{\tl_set:Nn \l_@@_tree_tabs_order_tl {/Tabs/C}},
      \pdfmanagement_add:nnn { Page } {Tabs}{/C},
    tabsorder / structure .code:n = %{\tl_set:Nn \l_@@_tree_tabs_order_tl {/Tabs/S}},
      \pdfmanagement_add:nnn { Page } {Tabs}{/S},
    tabsorder / none      .code:n = %{\tl_set:Nn \l_@@_tree_tabs_order_tl {}},
      \pdfmanagement_remove:nn {Page} {Tabs},
    tabsorder       .initial:n = structure,
    uncompress      .code:n = {\pdf_uncompress:  },
    global-mc .code:n =
      {
        \cs_set_eq:NN\@@_attribute_set:Nn \@@_attribute_gset:Nn
        \cs_set_eq:NN\@@_attribute_unset:N\@@_attribute_gunset:N
      }
  }
%need to think about the right place ...
%\AtBeginDocument
\hook_gput_code:nnn{begindocument}{tagpdf}
  {
    \bool_if:NT \g_@@_active_struct_bool
      {
         \pdfmanagement_add:nnn { Catalog / MarkInfo } { Marked } { true }
      }
    \keys_define:nn { @@ / setup }
     {
       global-mc .code:n={}
     }
  }
% escape commands are a bit engine specific so have been moved to the backend files.
% commands to escape strings so that they can be safely used in pdf
% currently not much used. But will be needed later, when alt and actualtext are added.
% we probably need the equivalent \pdfescapestring, \pdfescapename \pdfescapehex
% the commands of pdfescape adds an additional layout to allow for babel shorthands
%\cs_set_eq:NN \@@_pdf_escape_string:Nn \EdefEscapeString
%\cs_set_eq:NN \@@_pdf_escape_name:Nn   \EdefEscapeName
%\cs_set_eq:NN \@@_pdf_escape_hex:Nn    \EdefEscapeHex

%\cs_set_eq:NN \@@_pdf_escape_string:n \EdefEscapeString
%\cs_set_eq:NN \@@_pdf_escape_name:Nn   \EdefEscapeName

%escape command. They are backend specific as \pdf@escapehex would ignore most chars
%outside the "pdflatex" range





% a hook for later code and an absolute page counter
% should be executed before counters are resetted.
% is it used?
\cs_new:Nn   \@@_finish_page_hook: { }

%\AtBeginShipout

\hook_gput_code:nnn
  { shipout/before }
  { tagpdf/cnt }
  {
    \@@_finish_page_hook:
    %\int_gincr:N \g_@@_abspage_int
  }


%testing the engines and loading the backend files
\sys_if_engine_xetex:T
  { %lets try with xelatex ...
    %\PackageError { tagpdf } { xelatex~is~not~supported~-~aborting } {}
    %\tex_endinput:D
    \file_input:n {tagpdf-pdftex.def}
  }

\sys_if_engine_luatex:T
  {
    \file_input:n {tagpdf-luatex.def}
  }

\sys_if_engine_pdftex:T
  {
    \file_input:n {tagpdf-pdftex.def}
  }

\sys_if_output_dvi:T
  {
    %\PackageError { tagpdf } { dvi~output~is~not~supported~-~aborting }{}
    %\tex_endinput:D
  }

\cs_generate_variant:Nn \@@_prop_gput:Nnn      { Nxn , Nxx, Nnx , cnn, cxn, cnx, cno}
\cs_generate_variant:Nn \@@_seq_gput_right:Nn  { Nx  , No, cn, cx }
\cs_generate_variant:Nn \@@_prop_new:N   { c }
\cs_generate_variant:Nn \@@_seq_new:N    { c }
\cs_generate_variant:Nn \@@_seq_show:N   { c }
\cs_generate_variant:Nn \@@_prop_show:N  { c }
\cs_generate_variant:Nn \prop_gput:Nnn {Nxx}
\cs_generate_variant:Nn \prop_put:Nnn  {Nxx}

\cs_generate_variant:Nn \pdffile_embed_stream:nnn {nxx,oxx}
\cs_generate_variant:Nn \pdf_object_ref:n {e}


% few temp tl
\tl_new:N \g_@@_tmpa_tl
\tl_new:N \l_@@_tmpa_tl
\tl_new:N \l_@@_tmpb_tl
\tl_new:N \l_@@_tmpc_tl
\tl_new:N \l_@@_tmpd_tl
\tl_new:N \l_@@_tmpe_tl
\str_new:N \l_@@_tmpa_str

% helper function to get the propcount.
% use as \prop_map_function:NN PROP { \@@_prop_count:nn -1 }
\cs_new:Nn\@@_prop_count:nn { + 1 }

%% Loading the tagpdf sub packages
\RequirePackage { tagpdf-checks-code }
\RequirePackage { tagpdf-user }
\RequirePackage { tagpdf-tree-code }
\RequirePackage { tagpdf-roles-code }
\RequirePackage { tagpdf-attr-code }
% mc-code is split:
\RequirePackage { tagpdf-mc-code-shared }
\bool_if:NTF \g_@@_mode_lua_bool
  {
   \RequirePackage {tagpdf-mc-code-lua}
  }
  {
   \RequirePackage { tagpdf-mc-code-generic } %
  }

\RequirePackage { tagpdf-struct-code }
\RequirePackage { tagpdf-space-code }
%</package>
%    \end{macrocode}
%
%    \begin{macrocode}
%<*user>
\ProvidesExplPackage {tagpdf-user} {2021/05/14} {0.81}
  {tagpdf - user commands}
%    \end{macrocode}

% \begin{macro}{\tagpdfsetup}
%    \begin{macrocode}
\NewDocumentCommand \tagpdfsetup { m }
  {
    \keys_set:nn { @@ / setup } { #1 }
  }

\cs_set_eq:NN\tagpdfifluatexTF \sys_if_engine_luatex:TF
\cs_set_eq:NN\tagpdfifluatexT  \sys_if_engine_luatex:T
\cs_set_eq:NN\tagpdfifpdftexT  \sys_if_engine_pdftex:T
%    \end{macrocode}
% \end{macro}
% We need a command to stop tagging in some places.
%
% \begin{macro}{ \tag_stop_group_begin:, \tag_stop_group_end: }
%    \begin{macrocode}
\bool_new:N \l_@@_stop_bool

\prg_new_conditional:Nnn \@@_if_stop: {p,T,F,TF}
  {
    \bool_if:NTF \l_@@_stop_bool
      { \prg_return_true:  }
      { \prg_return_false: }
  }

\prg_new_eq_conditional:NNn \tag_if_stop: \@@_if_stop: {p,T,F,TF}

\cs_new_protected:Npn \@@_stop:
  {
    \bool_set_true:N \l_@@_stop_bool
    \cs_set_eq:NN \tag_mc_begin:n     \use_none:n
    \cs_set_eq:NN \tag_mc_end:        \prg_do_nothing:
    \cs_set_eq:NN \tag_mc_use:n       \use_none:n
    \cs_set_eq:NN \tag_struct_begin:n \use_none:n
    \cs_set_eq:NN \tag_struct_end:    \prg_do_nothing:
    \cs_set_eq:NN \tag_struct_use:n   \use_none:n
  }

\cs_new_protected:Npn \tag_stop_group_begin:
  {
    \group_begin:
    \@@_stop:
  }

\cs_set_eq:NN \tag_stop_group_end: \group_end:
%    \end{macrocode}
% \end{macro}
% We need a command to stop tagging in some places.
%
% \begin{macro}{ \tagpdfget, \tag_get:n  }
% This is a generic command to retrieve data. Currently
% the only sensible value for the argument is |mc_tag|
%    \begin{macrocode}
\cs_new:Npn \tagpdfget #1   { \use:c {@@_get_data_#1: } }
\cs_new:Npn \tag_get:n #1   { \use:c {@@_get_data_#1: } }

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\tagmcifinTF}
% This is a test if an mc is open or not. It is mostly of
% importance for pdflatex as lualatex doesn't mind much if a mc tag is not
% correctly closed.
%    \begin{macrocode}
\NewDocumentCommand \tagmcifinTF { m m }
  {
    \@@_mc_if_in:TF { #1 } { #2 }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{tagmcartifact}
%    \begin{macrocode}
\NewDocumentEnvironment{tagmcartifact}{m}
 {
  \tag_mc_artifact_group_begin:n { #1}\ignorespaces
 }
 {
  \tag_mc_artifact_group_end:
 }

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\tagmcbegin,\tagmcend,\tagmcuse  }
%    \begin{macrocode}
\NewDocumentCommand \tagmcbegin { m }
  {
    \tag_mc_begin:n {#1}\ignorespaces
  }


\NewDocumentCommand \tagmcend {  }
  {
    \if_mode_horizontal: \unskip \fi: %
    \tag_mc_end:
  }

\NewDocumentCommand \tagmcuse { m }
  {
    \tag_mc_use:n {#1}
  }

%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\tagstructbegin,\tagstructend,\tagstructuse  }
%
% These are structure related user commands
%    \begin{macrocode}
\NewDocumentCommand \tagstructbegin { m }
  {
    \tag_struct_begin:n {#1}
  }

\NewDocumentCommand \tagstructend {  }
  {
   \tag_struct_end:
  }

\NewDocumentCommand \tagstructuse { m }
  {
    \tag_struct_use:n {#1}
  }

%    \end{macrocode}
% \end{macro}
%
% \section{Debugging}
%
% \begin{macro}{\showtagpdfmcdata,\showtagpdfattributes }
% This commands are lua only
%    \begin{macrocode}
\NewDocumentCommand\showtagpdfmcdata { O {\@@_tag_get_mc_abs_cnt:} }
  {
    \bool_if:NT \g_@@_mode_lua_bool
      {
        \sys_if_engine_luatex:T
          {
            \directlua{ltx.@@.trace.show_all_mc_data(#1)}
          }
      }
  }

\NewDocumentCommand\showtagpdfattributes { }
  {
    \bool_if:NT \g_@@_mode_lua_bool
      {
        \sys_if_engine_luatex:T
          {
            \directlua
              {
                ltx.@@.trace.log
                 (
                   "showtagpdfattributes:
                    MC=>abscnt=\@@_get_mc_abs_cnt:
                    =>attr=\the\l_@@_mc_cnt_attr=>tag="
                    ..
                    tostring(ltx.@@.func.get_tag_from (\the\l_@@_mc_type_attr))
                    ..
                    "=\the\l_@@_mc_type_attr",0
                 )
             }
            \ignorespaces
          }
      }
   }

\NewDocumentCommand\showtagstack {}
  {
    \seq_show:N \g_@@_struct_tag_stack_seq
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{  }
%    \begin{macrocode}
\sys_if_engine_luatex:T
  {
    \NewDocumentCommand\pdffakespace { }
      {
        \@@_fakespace:
      }
  }
%    \end{macrocode}
% \end{macro}
% \section{Paratagging}
%  The following are some simple commands to enable/disable paratagging.
%  Probably one should add some checks if we are already in a paragraph.
%    \begin{macrocode}
\bool_new:N \l_@@_para_bool
\bool_new:N \l_@@_para_show_bool
\int_new:N \g_@@_para_int

\keys_define:nn { @@ / setup }
  {
    paratagging      .bool_set:N = \l_@@_para_bool,
    paratagging-show .bool_set:N = \l_@@_para_show_bool,
  }

\AddToHook{para/begin}
  {
   \int_gincr:N \g_@@_para_int
   \bool_if:NT \l__tag_para_bool
     {
       \tag_struct_begin:n {tag=P}
       \bool_if:NT \l_@@_para_show_bool
        { \tag_mc_begin:n{artifact}
          \llap{\color_select:n{red}\tiny\int_use:N\g_@@_para_int\ }
          \tag_mc_end:
        }
       \tag_mc_begin:n {tag=P}
     }
  }
\AddToHook{para/end}
  {
    \bool_if:NT \l__tag_para_bool
      {
        \tag_mc_end:
        \bool_if:NT \l_@@_para_show_bool
          { \tag_mc_begin:n{artifact}
            \rlap{\color_select:n{red}\tiny\ \int_use:N\g_@@_para_int}
            \tag_mc_end:
          }
        \tag_struct_end:
      }
  }


\newcommand\tagpdfparaOn {\bool_set_true:N \l__tag_para_bool}
\newcommand\tagpdfparaOff{\bool_set_false:N \l__tag_para_bool}

%    \end{macrocode}
% \section{Links}
% We need to close and reopen mc-chunks around links.
% With luatex the push/pop command must be outside groups,
% so we add also code to the generic commands in the hyperref driver.
%    \begin{macrocode}
\cs_generate_variant:Nn \pdfannot_dict_put:nnn {nnx}
\hook_gput_code:nnn
  {pdfannot/link/URI/before}
  {tagpdf}
  {
    \bool_if:NT \g_@@_active_struct_bool
      {
        \tag_mc_end_push:
        \tag_struct_begin:n { tag=Link }
        \tag_mc_begin:n { tag=Link }
        \pdfannot_dict_put:nnx
          { link/URI }
          { StructParent }
          { \int_use:N\c@g_@@_parenttree_obj_int }
       }
  }

\hook_gput_code:nnn
  {pdfannot/link/URI/after}
  {tagpdf}
  {
    \bool_if:NT \g_@@_active_struct_bool
      {
        \@@_struct_finish_link:
        \tag_mc_end:
        \tag_struct_end:
        \tag_mc_begin_pop:n{}
      }
  }

\hook_gput_code:nnn
  {pdfannot/link/GoTo/before}
  {tagpdf}
  {
    \bool_if:NT \g_@@_active_struct_bool
      {
        \tag_mc_end_push:
        \tag_struct_begin:n{tag=Link}
        \tag_mc_begin:n{tag=Link}
        \pdfannot_dict_put:nnx
          { link/GoTo }
          { StructParent }
          { \int_use:N\c@g_@@_parenttree_obj_int }
       }
  }

\hook_gput_code:nnn
  {pdfannot/link/GoTo/after}
  {tagpdf}
  {
    \bool_if:NT \g_@@_active_struct_bool
      {
        \@@_struct_finish_link:
        \tag_mc_end:
        \tag_struct_end:
        \tag_mc_begin_pop:n{}
      }
  }

\hook_gput_code:nnn
 {cmd/url/before}
 {tagpdf}
 {\tag_mc_end_push:}

\hook_gput_code:nnn
 {cmd/url/after}
 {tagpdf}
 {\tag_mc_begin_pop:n{}}

\hook_gput_code:nnn
 {cmd/href/before}
 {tagpdf}
 {\tag_mc_end_push:}

\hook_gput_code:nnn
 {cmd/href/after}
 {tagpdf}
 {\tag_mc_begin_pop:n{}}

\hook_gput_code:nnn
 {cmd/hrefurl/before}
 {tagpdf}
 {\tag_mc_end_push:}

\hook_gput_code:nnn
 {cmd/hrefurl/after}
 {tagpdf}
 {\tag_mc_begin_pop:n{}}

%this will go when references are improved
\hook_gput_code:nnn
 {cmd/T@ref/before}
 {tagpdf}
 {\tag_mc_end_push:}

\hook_gput_code:nnn
 {cmd/T@ref/after}
 {tagpdf}
 {\tag_mc_begin_pop:n{}}

\hook_gput_code:nnn
 {cmd/T@pageref/before}
 {tagpdf}
 {\tag_mc_end_push:}

\hook_gput_code:nnn
 {cmd/T@pageref/after}
 {tagpdf}
 {\tag_mc_begin_pop:n{}}

\hook_gput_code:nnn
 {cmd/T@nameref/before}
 {tagpdf}
 {\tag_mc_end_push:}

\hook_gput_code:nnn
 {cmd/T@nameref/after}
 {tagpdf}
 {\tag_mc_begin_pop:n{}}
% "alternative descriptions " for PAX3. How to get better text here??
\pdfannot_dict_put:nnn
 { link/URI }
 { Contents }
 { (url) }

\pdfannot_dict_put:nnn
 { link/GoTo }
 { Contents }
 { (ref) }

%    \end{macrocode}
%</user>
%