%%
%% This is file `tagpdf-debug.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% tagpdf.dtx  (with options: `debug')
%% tagpdf-checks.dtx  (with options: `debug')
%% tagpdf-user.dtx  (with options: `debug')
%% tagpdf-mc-shared.dtx  (with options: `debug')
%% tagpdf-tree.dtx  (with options: `debug')
%% tagpdf-roles.dtx  (with options: `debug')
%% tagpdf-struct.dtx  (with options: `debug')
%% tagpdf-space.dtx  (with options: `debug')
%% 
%% Copyright (C) 2019-2024 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.
%% 
%% File: tagpdf.dtx
\ProvidesExplPackage {tagpdf-debug} {2025-03-26} {0.99p}
  { debug code for tagpdf }
\@ifpackageloaded{tagpdf}{}{\PackageWarning{tagpdf-debug}{tagpdf~not~loaded,~quitting}\endinput}
\prop_gput:Nnn \g_msg_module_type_prop { tag / debug} {}
\prop_gput:Nnn \g_msg_module_name_prop { tag / debug }{tagpdf~DEBUG}
\cs_set_protected:Npn \tag_stop:
  {
     \msg_note:nne {tag / debug }{tag-suspend}{ \int_use:N \l__tag_tag_stop_int }
    \int_incr:N \l__tag_tag_stop_int
    \bool_set_false:N \l__tag_active_struct_bool
    \bool_set_false:N \l__tag_active_mc_bool
    \bool_set_false:N \l__tag_active_socket_bool
    \__tag_stop_para_ints:
  }
\cs_set_protected:Npn \tag_start:
  {
    \int_if_zero:nF { \l__tag_tag_stop_int } { \int_decr:N \l__tag_tag_stop_int }
    \int_if_zero:nT { \l__tag_tag_stop_int }
      {
        \bool_set_true:N \l__tag_active_struct_bool
        \bool_set_true:N \l__tag_active_mc_bool
        \bool_set_true:N \l__tag_active_socket_bool
        \__tag_start_para_ints:
      }
    \msg_note:nne {tag / debug }{tag-resume}{ \int_use:N \l__tag_tag_stop_int }
  }
\cs_set_eq:NN\tagstop\tag_stop:
\cs_set_eq:NN\tagstart\tag_start:
\cs_set_protected:Npn \tag_suspend:n #1
  {
    \msg_note:nnee {tag / debug }{tag-suspend}
       { \int_use:N \l__tag_tag_stop_int }{\exp_not:n{#1}}
    \int_incr:N \l__tag_tag_stop_int
    \bool_set_false:N \l__tag_active_struct_bool
    \bool_set_false:N \l__tag_active_mc_bool
    \bool_set_false:N \l__tag_active_socket_bool
    \__tag_stop_para_ints:
  }
\cs_set_eq:NN \tag_stop:n \tag_suspend:n
\cs_set_protected:Npn \tag_resume:n #1
  {
    \int_if_zero:nF { \l__tag_tag_stop_int } { \int_decr:N \l__tag_tag_stop_int }
    \int_if_zero:nT { \l__tag_tag_stop_int }
      {
        \bool_set_true:N \l__tag_active_struct_bool
        \bool_set_true:N \l__tag_active_mc_bool
        \bool_set_true:N \l__tag_active_socket_bool
        \__tag_start_para_ints:
      }
    \msg_note:nnee {tag / debug }{tag-resume}
       { \int_use:N \l__tag_tag_stop_int }{\exp_not:n{#1}}
  }
\cs_set_eq:NN \tag_start:n \tag_resume:n
\bool_if:NTF \g__tag_mode_lua_bool
  {
   \RequirePackage {tagpdf-debug-lua}
  }
  {
   \RequirePackage {tagpdf-debug-generic} %
  }
%% File: tagpdf-checks.dtx

\msg_new:nnn { tag/debug } { show-struct }
  {
    =========================\\
    The~structure~#1~
    \tl_if_empty:nTF {#2}
      { is~empty \\>~ . }
      { contains: #2  }
    \\
  }
\msg_new:nnn { tag/debug } { show-kids }
  {
    The~structure~has~the~following~kids:
    \tl_if_empty:nTF {#2}
      { \\>~ NONE }
      { #2  }
    \\
    =========================
  }
\msg_new:nnn { tag / debug } {mc-begin} { MC~begin~#1~with~options:~\tl_to_str:n{#2}~[\msg_line_context:] }
\msg_new:nnn { tag / debug } {mc-end}   { MC~end~#1~[\msg_line_context:] }

\cs_new_protected:Npn \__tag_debug_mc_begin_insert:n #1
 {
   \int_compare:nNnT { \l__tag_loglevel_int } > {0}
     {
        \msg_note:nnnn { tag / debug } {mc-begin} {inserted} { #1 }
     }
 }
\cs_new_protected:Npn \__tag_debug_mc_begin_ignore:n #1
 {
   \int_compare:nNnT { \l__tag_loglevel_int } > {0}
     {
        \msg_note:nnnn { tag / debug } {mc-begin } {ignored} { #1 }
     }
 }
\cs_new_protected:Npn \__tag_debug_mc_end_insert:
 {
   \int_compare:nNnT { \l__tag_loglevel_int } > {0}
     {
        \msg_note:nnn { tag / debug } {mc-end} {inserted}
     }
 }
\cs_new_protected:Npn \__tag_debug_mc_end_ignore:
 {
   \int_compare:nNnT { \l__tag_loglevel_int } > {0}
     {
        \msg_note:nnn { tag / debug } {mc-end } {ignored}
     }
 }
\msg_new:nnn { tag / debug } {struct-begin}
  {
    Struct~\tag_get:n{struct_num}~begin~#1~with~options:~\tl_to_str:n{#2}~\\[\msg_line_context:]
  }
\msg_new:nnn { tag / debug } {struct-end}
  {
    Struct~end~#1~[\msg_line_context:]
  }
\msg_new:nnn { tag / debug } {struct-end-wrong}
  {
    Struct~end~'#1'~doesn't~fit~start~'#2'~[\msg_line_context:]
  }

\cs_new_protected:Npn \__tag_debug_struct_begin_insert:n #1
 {
   \int_compare:nNnT { \l__tag_loglevel_int } > {0}
     {
        \msg_note:nnnn { tag / debug } {struct-begin} {inserted} { #1 }
        \seq_log:N \g__tag_struct_tag_stack_seq
     }
 }
\cs_new_protected:Npn \__tag_debug_struct_begin_ignore:n #1
 {
   \int_compare:nNnT { \l__tag_loglevel_int } > {0}
     {
        \msg_note:nnnn { tag / debug } {struct-begin } {ignored} { #1 }
     }
 }
\cs_new_protected:Npn \__tag_debug_struct_end_insert:
 {
   \int_compare:nNnT { \l__tag_loglevel_int } > {0}
     {
        \msg_note:nnn { tag / debug } {struct-end} {inserted}
        \seq_log:N \g__tag_struct_tag_stack_seq
     }
 }
\cs_new_protected:Npn \__tag_debug_struct_end_ignore:
 {
   \int_compare:nNnT { \l__tag_loglevel_int } > {0}
     {
        \msg_note:nnn { tag / debug } {struct-end } {ignored}
     }
 }
\cs_new_protected:Npn \__tag_debug_struct_end_check:n #1
 {
   \int_compare:nNnT { \l__tag_loglevel_int } > {0}
    {
      \seq_get:NNT \g__tag_struct_tag_stack_seq \l__tag_tmpa_tl
        {
          \str_if_eq:eeF
           {#1}
           {\exp_last_unbraced:NV\use_i:nn \l__tag_tmpa_tl}
           {
             \msg_warning:nnee { tag/debug }{ struct-end-wrong }
              {#1}
              {\exp_last_unbraced:NV\use_i:nn \l__tag_tmpa_tl}
           }
        }
     }
 }
\msg_new:nnn { tag / debug } {tag-suspend}
  {
    \int_if_zero:nTF
      {#1}
      {Tagging~suspended}
      {Tagging~(not)~suspended~(already~inactive)}\\
    level:~#1~==>~\int_eval:n{#1+1}\tl_if_empty:nF{#2}{,~label:~#2}~[\msg_line_context:]
  }
\msg_new:nnn { tag / debug } {tag-resume}
  {
    \int_if_zero:nTF
      {#1}
      {Tagging~resumed}
      {Tagging~(not)~resumed}\\
    level:~\int_eval:n{#1+1}~==>~#1\tl_if_empty:nF{#2}{,~label:~#2}~[\msg_line_context:]
  }
%% File: tagpdf-user.dtx





\keys_define:nn { __tag / show }
  {
    ,debug/structures .code:n =
      {
        \int_step_inline:nnn{#1}{\c@g__tag_struct_abs_int}
           {
            \msg_term:nneeee
                   { tag/debug } { show-struct }
                   { ##1 }
                   {
                     \prop_map_function:cN
                       {g__tag_struct_debug_##1_prop}
                       \msg_show_item_unbraced:nn
                   }
                   { } { }
            \msg_term:nneeee
                   { tag/debug } { show-kids }
                   {  ##1 }
                   {
                     \seq_map_function:cN
                       {g__tag_struct_debug_kids_##1_seq}
                       \msg_show_item_unbraced:n
                   }
                   { } { }
          }
      }
    ,debug/structures .default:n = 1
  }
%% File: tagpdf-mc-shared.dtx
%% File: tagpdf-tree.dtx
%% File: tagpdf-roles.dtx
%% File: tagpdf-struct.dtx
\cs_set_protected:Npn \__tag_struct_prop_gput:nnn #1 #2 #3
 {
   \__tag_prop_gput:cnn
        { g__tag_struct_#1_prop }{#2}{#3}
\prop_gput:cnn { g__tag_struct_debug_#1_prop } {#2} {#3}
 }
\cs_generate_variant:Nn \__tag_struct_prop_gput:nnn {onn,nne,nee,nno}

\prop_new:c { g__tag_struct_debug_1_prop }
\seq_new:c  { g__tag_struct_debug_kids_1_seq }
\prop_gset_eq:cc { g__tag_struct_debug_1_prop }{ g__tag_struct_1_prop }
\prop_gremove:cn { g__tag_struct_debug_1_prop }{Namespaces}
\cs_set_protected:Npn \__tag_struct_kid_mc_gput_right:nn #1 #2
  {
    \__tag_seq_gput_right:ce
      { g__tag_struct_kids_#1_seq }
      {
        \__tag_struct_mcid_dict:n {#2}
      }
    \seq_gput_right:cn
      { g__tag_struct_debug_kids_#1_seq }
      {
        MC~#2
      }
    \__tag_seq_gput_right:cn
      { g__tag_struct_kids_#1_seq }
      {
        \prop_item:Nn \g__tag_struct_cont_mc_prop {#2}
      }
  }
\cs_set_protected:Npn\__tag_struct_kid_struct_gput_right:nn #1 #2
%%#1 num of parent struct, #2 kid struct
  {
    \__tag_seq_gput_right:ce
      { g__tag_struct_kids_#1_seq }
      {
        \pdf_object_ref_indexed:nn { __tag/struct }{ #2 }
      }
    \seq_gput_right:cn
      { g__tag_struct_debug_kids_#1_seq }
      {
        Struct~#2
      }
  }
\cs_set_protected:Npn\__tag_struct_kid_struct_gput_left:nn #1 #2
%%#1 num of parent struct, #2 kid struct
  {
    \__tag_seq_gput_left:ce
      { g__tag_struct_kids_#1_seq }
      {
        \pdf_object_ref_indexed:nn { __tag/struct }{ #2 }
      }
    \seq_gput_left:cn
      { g__tag_struct_debug_kids_#1_seq }
      {
        Struct~#2
      }
  }
\cs_set_protected:Npn\__tag_struct_kid_OBJR_gput_right:nnn #1 #2 #3
%%#1 num of parent struct,#2 obj reference,#3 page object reference
  {
    \pdf_object_unnamed_write:nn
      { dict }
      {
        /Type/OBJR/Obj~#2/Pg~#3
      }
    \__tag_seq_gput_right:ce
      { g__tag_struct_kids_#1_seq }
      {
        \pdf_object_ref_last:
      }
    \seq_gput_right:ce
      { g__tag_struct_debug_kids_#1_seq }
      {
        OBJR~reference
      }
  }
\cs_set_protected:Npn \tag_struct_begin:n #1 %#1 key-val
  {
\__tag_check_if_active_struct:TF
      {
        \group_begin:
        \int_gincr:N \c@g__tag_struct_abs_int
        \__tag_prop_new:c  { g__tag_struct_\int_eval:n { \c@g__tag_struct_abs_int }_prop }
         \prop_new:c { g__tag_struct_debug_\int_eval:n {\c@g__tag_struct_abs_int}_prop }
        \__tag_new_output_prop_handler:n {\int_eval:n { \c@g__tag_struct_abs_int }}
        \__tag_seq_new:c  { g__tag_struct_kids_\int_eval:n { \c@g__tag_struct_abs_int }_seq}
         \seq_new:c { g__tag_struct_debug_kids_\int_eval:n {\c@g__tag_struct_abs_int}_seq }
          \pdf_object_new_indexed:nn { __tag/struct }
            { \c@g__tag_struct_abs_int }
         \__tag_struct_prop_gput:nnn
            { \int_use:N \c@g__tag_struct_abs_int }
            { Type }
            { /StructElem }
         \tl_if_empty:NF \l__tag_struct_lang_tl
           {
             \__tag_struct_prop_gput:nne
              { \int_use:N \c@g__tag_struct_abs_int }
              { Lang }
              { (\l__tag_struct_lang_tl) }
           }
         \__tag_struct_prop_gput:nnn
            { \int_use:N \c@g__tag_struct_abs_int }
            { Type }
            { /StructElem }

        \tl_set:Nn \l__tag_struct_stack_parent_tmpa_tl {-1}
        \keys_set:nn { __tag / struct} { #1 }
        \__tag_struct_set_tag_info:eVV
          { \int_use:N \c@g__tag_struct_abs_int }
           \g__tag_struct_tag_tl
           \g__tag_struct_tag_NS_tl
        \__tag_check_structure_has_tag:n { \int_use:N \c@g__tag_struct_abs_int }
        \int_compare:nNnT { \l__tag_struct_stack_parent_tmpa_tl } = { -1 }
          {
            \seq_get:NNF
              \g__tag_struct_stack_seq
              \l__tag_struct_stack_parent_tmpa_tl
              {
                \msg_error:nn { tag } { struct-faulty-nesting }
              }
           }
        \seq_gpush:NV \g__tag_struct_stack_seq        \c@g__tag_struct_abs_int
        \__tag_role_get:VVNN
          \g__tag_struct_tag_tl
          \g__tag_struct_tag_NS_tl
          \l__tag_struct_roletag_tl
          \l__tag_struct_roletag_NS_tl
         \__tag_struct_prop_gput:nne
           { \int_use:N \c@g__tag_struct_abs_int }
           { rolemap }
           {
             {\l__tag_struct_roletag_tl}{\l__tag_struct_roletag_NS_tl}
           }
        \str_case:VnTF \l__tag_struct_roletag_tl
         {
           {Part} {}
           {Div}  {}
           {NonStruct} {}
         }
         {
           \prop_get:cnNT
            { g__tag_struct_ \l__tag_struct_stack_parent_tmpa_tl _prop }
            { parentrole }
            \l__tag_get_tmpc_tl
            {
              \__tag_struct_prop_gput:nno
                { \int_use:N \c@g__tag_struct_abs_int }
                { parentrole }
                {
                  \l__tag_get_tmpc_tl
                }
            }
         }
         {
            \__tag_struct_prop_gput:nne
              { \int_use:N \c@g__tag_struct_abs_int }
              { parentrole }
              {
                {\l__tag_struct_roletag_tl}{\l__tag_struct_roletag_NS_tl}
              }
         }
        \seq_gpush:Ne \g__tag_struct_tag_stack_seq
          {{\g__tag_struct_tag_tl}{\l__tag_struct_roletag_tl}}
        \tl_gset:NV   \g__tag_struct_stack_current_tl \c@g__tag_struct_abs_int
        %\seq_show:N   \g__tag_struct_stack_seq
        \bool_if:NF
          \l__tag_struct_elem_stash_bool
          {
            \__tag_struct_get_parentrole:eNN
              {\l__tag_struct_stack_parent_tmpa_tl}
              \l__tag_get_parent_tmpa_tl
              \l__tag_get_parent_tmpb_tl
            \__tag_check_parent_child:VVVVN
              \l__tag_get_parent_tmpa_tl
              \l__tag_get_parent_tmpb_tl
              \g__tag_struct_tag_tl
              \g__tag_struct_tag_NS_tl
              \l__tag_parent_child_check_tl
            \int_compare:nNnT {\l__tag_parent_child_check_tl}<0
              {
                \prop_get:cnN
                  { g__tag_struct_ \l__tag_struct_stack_parent_tmpa_tl _prop}
                  {S}
                  \l__tag_tmpa_tl
                \quark_if_no_value:NT\l__tag_tmpa_tl{\tl_set:Nn \l__tag_tmpa_tl{UNKNOWN}}
                \msg_warning:nneee
                 { tag }
                 {role-parent-child}
                 { \l__tag_get_parent_tmpa_tl/\l__tag_get_parent_tmpb_tl }
                 { \g__tag_struct_tag_tl/\g__tag_struct_tag_NS_tl  }
                 { not~allowed~
                   (struct~\l__tag_struct_stack_parent_tmpa_tl,~\l__tag_tmpa_tl
                    \c_space_tl-->~struct~\int_eval:n {\c@g__tag_struct_abs_int})
                 }
                \cs_set_eq:NN \l__tag_role_remap_tag_tl \g__tag_struct_tag_tl
                \cs_set_eq:NN \l__tag_role_remap_NS_tl \g__tag_struct_tag_NS_tl
                \__tag_role_remap:
                \cs_gset_eq:NN \g__tag_struct_tag_tl \l__tag_role_remap_tag_tl
                \cs_gset_eq:NN  \g__tag_struct_tag_NS_tl \l__tag_role_remap_NS_tl
                \__tag_struct_set_tag_info:eVV
                  { \int_use:N \c@g__tag_struct_abs_int }
                    \g__tag_struct_tag_tl
                    \g__tag_struct_tag_NS_tl
              }
             \__tag_struct_prop_gput:nne
              { \int_use:N \c@g__tag_struct_abs_int }
              { P }
              {
                \pdf_object_ref_indexed:nn { __tag/struct} { \l__tag_struct_stack_parent_tmpa_tl }
              }
            %record this structure as kid:
            %\tl_show:N \g__tag_struct_stack_current_tl
            %\tl_show:N \l__tag_struct_stack_parent_tmpa_tl
            \use:c { __tag_struct_kid_struct_gput_ \l__tag_struct_addkid_tl :ee }
               { \l__tag_struct_stack_parent_tmpa_tl }
               { \g__tag_struct_stack_current_tl }
            %\prop_show:c { g__tag_struct_\g__tag_struct_stack_current_tl _prop }
            %\seq_show:c {g__tag_struct_kids_\l__tag_struct_stack_parent_tmpa_tl _seq}
          }
           \prop_gset_eq:cc
             { g__tag_struct_debug_\int_eval:n {\c@g__tag_struct_abs_int}_prop }
             { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop }
           \prop_gput:cne
             { g__tag_struct_debug_\int_eval:n {\c@g__tag_struct_abs_int}_prop }
             { P }
             {
               \bool_if:NTF \l__tag_struct_elem_stash_bool
                 {no~parent:~stashed}
                 {
                   parent~structure:~\l__tag_struct_stack_parent_tmpa_tl\c_space_tl =~
                   \prop_item:cn{ g__tag_struct_\l__tag_struct_stack_parent_tmpa_tl _prop }{S}
                 }
             }
           \prop_gput:cne
             { g__tag_struct_debug_\int_eval:n {\c@g__tag_struct_abs_int}_prop }
             { NS }
             { \g__tag_struct_tag_NS_tl }
        %\prop_show:c { g__tag_struct_\g__tag_struct_stack_current_tl _prop }
        %\seq_show:c {g__tag_struct_kids_\l__tag_struct_stack_parent_tmpa_tl _seq}
 \__tag_debug_struct_begin_insert:n { #1 }
        \group_end:
     }
{ \__tag_debug_struct_begin_ignore:n { #1 }}
  }
\cs_set_protected:Nn \tag_struct_end:
  { %take the current structure num from the stack:
    %the objects are written later, lua mode hasn't all needed info yet
    %\seq_show:N \g__tag_struct_stack_seq
\__tag_check_if_active_struct:TF
      {
        \seq_gpop:NN   \g__tag_struct_tag_stack_seq \l__tag_tmpa_tl
        \seq_gpop:NNTF \g__tag_struct_stack_seq \l__tag_tmpa_tl
          {
            \__tag_check_info_closing_struct:o { \g__tag_struct_stack_current_tl }
          }
          { \__tag_check_no_open_struct: }
        % get the previous one, shouldn't be empty as the root should be there
        \seq_get:NNTF \g__tag_struct_stack_seq \l__tag_tmpa_tl
          {
            \tl_gset:NV   \g__tag_struct_stack_current_tl \l__tag_tmpa_tl
          }
          {
            \__tag_check_no_open_struct:
          }
       \seq_get:NNT \g__tag_struct_tag_stack_seq \l__tag_tmpa_tl
          {
            \tl_gset:Ne \g__tag_struct_tag_tl
              { \exp_last_unbraced:NV\use_i:nn \l__tag_tmpa_tl }
            \prop_get:NVNT\g__tag_role_tags_NS_prop \g__tag_struct_tag_tl\l__tag_tmpa_tl
             {
               \tl_gset:Ne \g__tag_struct_tag_NS_tl { \l__tag_tmpa_tl }
             }
          }
\__tag_debug_struct_end_insert:
      }
{\__tag_debug_struct_end_ignore:}
  }

\cs_set_protected:Npn \tag_struct_end:n #1
 {
    \__tag_check_if_active_struct:T{\__tag_debug_struct_end_check:n{#1}}
   \tag_struct_end:
 }
\cs_set_protected:Npn \tag_struct_use:n #1 %#1 is the label
  {
    \__tag_check_if_active_struct:T
      {
        \prop_if_exist:cTF
          { g__tag_struct_\property_ref:enn{tagpdfstruct-#1}{tagstruct}{unknown}_prop } %
          {
            \__tag_check_struct_used:n {#1}
            %add the label structure as kid to the current structure (can be the root)
            \__tag_struct_kid_struct_gput_right:ee
              { \g__tag_struct_stack_current_tl }
              { \property_ref:enn{tagpdfstruct-#1}{tagstruct}{1} }
            %add the current structure to the labeled one as parents
            \__tag_prop_gput:cne
              { g__tag_struct_\property_ref:enn{tagpdfstruct-#1}{tagstruct}{1}_prop }
              { P }
              {
                \pdf_object_ref_indexed:nn { __tag/struct } { \g__tag_struct_stack_current_tl }
              }
           \prop_gput:cne
             { g__tag_struct_debug_\property_ref:enn{tagpdfstruct-#1}{tagstruct}{1}_prop }
             { P }
             {
               parent~structure:~\g__tag_struct_stack_current_tl\c_space_tl=~
               \g__tag_struct_tag_tl
             }
             \__tag_struct_get_parentrole:eNN
              {\property_ref:enn{tagpdfstruct-#1}{tagstruct}{1}}
              \l__tag_tmpa_tl
              \l__tag_tmpb_tl
            \__tag_check_parent_child:VVVVN
              \g__tag_struct_tag_tl
              \g__tag_struct_tag_NS_tl
              \l__tag_tmpa_tl
              \l__tag_tmpb_tl
              \l__tag_parent_child_check_tl
            \int_compare:nNnT {\l__tag_parent_child_check_tl}<0
              {
                \cs_set_eq:NN \l__tag_role_remap_tag_tl \g__tag_struct_tag_tl
                \cs_set_eq:NN \l__tag_role_remap_NS_tl \g__tag_struct_tag_NS_tl
                \__tag_role_remap:
                \cs_gset_eq:NN \g__tag_struct_tag_tl \l__tag_role_remap_tag_tl
                \cs_gset_eq:NN  \g__tag_struct_tag_NS_tl \l__tag_role_remap_NS_tl
                \__tag_struct_set_tag_info:eVV
                  { \int_use:N \c@g__tag_struct_abs_int }
                    \g__tag_struct_tag_tl
                    \g__tag_struct_tag_NS_tl
              }
          }
          {
            \msg_warning:nnn{ tag }{struct-label-unknown}{#1}
          }
      }
  }
\cs_set_protected:Npn \tag_struct_use_num:n #1 %#1 is structure number
  {
    \__tag_check_if_active_struct:T
      {
        \prop_if_exist:cTF
          { g__tag_struct_#1_prop } %
          {
            \prop_get:cnNT
              {g__tag_struct_#1_prop}
              {P}
              \l__tag_tmpa_tl
              {
                \msg_warning:nnn { tag } {struct-used-twice} {#1}
              }
            %add the \#1 structure as kid to the current structure (can be the root)
            \__tag_struct_kid_struct_gput_right:ee
              { \g__tag_struct_stack_current_tl }
              { #1 }
            %add the current structure to \#1 as parent
             \__tag_struct_prop_gput:nne
              { #1 }
              { P }
              {
                \pdf_object_ref_indexed:nn { __tag/struct }{ \g__tag_struct_stack_current_tl }
              }
           \prop_gput:cne
             { g__tag_struct_debug_#1_prop }
             { P }
             {
               parent~structure:~\g__tag_struct_stack_current_tl\c_space_tl=~
               \g__tag_struct_tag_tl
             }
             \__tag_struct_get_parentrole:eNN
              {#1}
              \l__tag_tmpa_tl
              \l__tag_tmpb_tl
            \__tag_check_parent_child:VVVVN
              \g__tag_struct_tag_tl
              \g__tag_struct_tag_NS_tl
              \l__tag_tmpa_tl
              \l__tag_tmpb_tl
              \l__tag_parent_child_check_tl
            \int_compare:nNnT {\l__tag_parent_child_check_tl}<0
              {
                \cs_set_eq:NN \l__tag_role_remap_tag_tl \g__tag_struct_tag_tl
                \cs_set_eq:NN \l__tag_role_remap_NS_tl \g__tag_struct_tag_NS_tl
                \__tag_role_remap:
                \cs_gset_eq:NN \g__tag_struct_tag_tl \l__tag_role_remap_tag_tl
                \cs_gset_eq:NN  \g__tag_struct_tag_NS_tl \l__tag_role_remap_NS_tl
                \__tag_struct_set_tag_info:eVV
                  { \int_use:N \c@g__tag_struct_abs_int }
                    \g__tag_struct_tag_tl
                    \g__tag_struct_tag_NS_tl
              }
          }
          {
            \msg_warning:nnn{ tag }{struct-label-unknown}{#1}
          }
      }
  }

%% File: tagpdf-space.dtx
%% 
%%
%% End of file `tagpdf-debug.sty'.
