%%
%% This is file `documentmetadata-support.ltx',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% documentmetadata-support.dtx  (with options: `code')
%% 
%% This is a generated file.
%% 
%% Copyright 2021-2026 LaTeX Project
%% 
%% This file was generated from file(s) of the  `LaTeX-lab Bundle'.
%% ------------------------------------------------------------------------------------
%% 
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%    http://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2008 or later.
%% 
%% This file may only be distributed together with a copy of the LaTeX
%% `LaTeX-lab Bundle'. You may however distribute the `LaTeX-lab Bundle'
%% without such generated files.
%% 
%% The newest sources can be found below
%% 
%%    https://github.com/latex3/latex2e/blob/develop/required/latex-lab
%% 
%% Issues may be reported at
%% 
%%    https://github.com/latex3/latex2e/issues
%% 
%% 
%% File: documentmetadata-support.dtx
\def\documentmetadatasupportversion{1.1b}
\def\documentmetadatasupportdate{2026-05-02}

\RequirePackage{pdfmanagement-init}
\ExplSyntaxOn\makeatletter

\clist_if_exist:NF \g__pdfmanagement_firstaidoff_clist
  { \clist_new:N \g__pdfmanagement_firstaidoff_clist }
\tl_if_exist:NF \g__pdfmanagement_testphase_tl
 { \tl_new:N \g__pdfmanagement_testphase_tl }
\cs_new_protected:Npn \@kernel@before@DocumentMetadata
  {
    \ifx\Umathcode\@undefined
    \fontencoding{T1}
    \renewcommand\encodingdefault{T1}
    \fi
  }

\cs_set_protected:Npn \DocumentMetadata #1
  {
    \cs_if_eq:NNTF \documentclass \@twoclasseserror
      { \msg_error:nn { meta } { after-class } }
      {
        \@kernel@before@DocumentMetadata
        \bool_gset_true:N \g__pdfmanagement_active_bool
        \keys_set_groups:nnn { document / metadata} {init}{ #1 }
        %if no backend has been loaded force it now:
        \str_if_exist:NF \c_sys_backend_str
          {
            \sys_load_backend:n {}
          }
        \ExplSyntaxOn\makeatletter
          \file_input:n {l3backend-testphase-\c_sys_backend_str.def}
        \ExplSyntaxOff\makeatother
          \pdf_version_gset:n { 2.0 }
          \keys_set_groups:nnn { document / metadata} {pdf}{ #1 }
          \RequirePackage{latex-lab-testphase-latest}
          \AddToDocumentProperties [document]{tagging}{inactive}
          \AddToDocumentProperties [document]{tagging/para}{inactive}
        \keys_set_exclude_groups:nnn  { document / metadata } { init,pdf } { #1 }
        \tl_if_empty:eTF{\GetDocumentProperty{document/language}}
         {
           \tl_set:Ne\l__pdfmanagement_tmpa_tl{\GetDocumentProperty{document/lang}}
           \tl_if_empty:NTF\l__pdfmanagement_tmpa_tl
            {\AddToDocumentProperties[document]{language}{en-Latn-US}}
            {
             \keys_set:ne{document/metadata}{language=\l__pdfmanagement_tmpa_tl}
             \__pdfmanagement_update_BCPdata:
            }
         }
         {
           \__pdfmanagement_update_BCPdata:
         }
        \g@addto@macro\@kernel@after@begindocument
         {
           \pdfdict_get:nnN {g__pdf_Core/Catalog}{Lang}\l__pdfmanagement_tmpa_tl
           \quark_if_no_value:NT\l__pdfmanagement_tmpa_tl
            {
              \tl_if_empty:eTF { \BCPdata{main.language} }
               { \tl_set:Ne \l__pdfmanagement_tmpb_tl { \BCPdata{language} } }
               { \tl_set:Ne \l__pdfmanagement_tmpb_tl { \BCPdata{main.language} } }
              \exp_last_unbraced:Ne
               \AddToDocumentProperties{[document]{lang}{\l__pdfmanagement_tmpb_tl}}
              \pdfmanagement_add:nne {Catalog} {Lang}{(\l__pdfmanagement_tmpb_tl)}
            }
         }
        \hook_use_once:n {pdfmanagement/add}
        \cs_set_protected:Npn \DocumentMetadata ##1
          {
            \@latex@error
              {Two~\noexpand\DocumentMetadata~declarations}%
              {The~document~may~use~only~one~\noexpand\DocumentMetadata~declaration.}
          }
        \g__pdfmanagement_testphase_tl
        \RequirePackage{pdfmanagement-firstaid}
      }
  }

\clist_map_inline:nn
 {
   pdfmanagement-init.sty,
   color-ltx.sty,
   xcolor-patches-tmp-ltx.sty,
   tagpdf-base.sty,
   latex-lab-testphase-latest.sty,
   tagpdf.sty,
   tagpdf-mc-code-generic.sty,
   tagpdf-mc-code-lua.sty,
   luamml-patches-kernel.sty,
   luamml-patches-amsmath.sty,
   latex-lab-enumitem.sty,
   latex-lab-kernel-changes.sty,
   latex-lab-testphase-names.sty,
   latex-lab-testphase-new-or-2.sty,
   latex-lab-testphase-block.sty,
   latex-lab-testphase-context.sty,
   latex-lab-testphase-sec.sty,
   latex-lab-testphase-sec-template.sty,
   latex-lab-testphase-toc.sty,
   latex-lab-testphase-minipage.sty,
   latex-lab-testphase-graphic.sty,
   latex-lab-testphase-float.sty,
   latex-lab-testphase-bib.sty,
   latex-lab-testphase-text.sty,
   latex-lab-testphase-marginpar.sty,
   latex-lab-testphase-title.sty,
   latex-lab-testphase-table.sty,
   latex-lab-testphase-math.sty,
   latex-lab-testphase-firstaid.sty,
   latex-lab-testphase-tikz.sty,
   pdfmanagement-firstaid.sty,
    }
 {\expandafter\chardef\csname t@status@#1\endcsname8\relax }
\tl_new:c {l__tag_status_0_tl}
\tl_new:c {l__tag_status_1_tl}
\tl_new:c {l__tag_status_2_tl}
\tl_new:c {l__tag_status_3_tl}
\tl_new:c {l__tag_status_4_tl}
\tl_new:c {l__tag_status_-1_tl}
\cs_new_protected:Npn\__tag_status_sort:
 {
   \clist_map_inline:Nn\g__tag_status_filelist_tl
     {
       \filename@parse{##1}
       \cs_if_exist:cTF { t@status@##1 }
         {
          \str_if_eq:onF{\filename@ext}{cls}
           {
            \tl_put_right:cn
              {l__tag_status_\int_use:c { t@status@##1 }_tl}
              {~~##1\iow_newline:}
           }
         }
         {
          \str_if_eq:onT{\filename@ext}{sty}
           {
             \tl_put_right:cn
               {l__tag_status_-1_tl}
               {~~##1\iow_newline:}
           }
         }
     }
 }
\cs_new_protected:Npn \__tag_status_type:nn #1 #2
 {
   \iow_term:n{~~#2}
   \iow_term:n{~~--------------------------}
   \tl_if_empty:cTF{l__tag_status_#1_tl}
    {
      \iow_term:e{~~NONE\iow_newline:}
    }
    {
      \iow_term:e{\tl_use:c{l__tag_status_#1_tl}}
    }
 }
\cs_new_protected:Npn \__tag_status_log:
 {
   \file_if_exist_input:n {latex-tagging-status.ltx}
   \AddToHookNext{class/before}
     {
       \tl_const:Ne \c__tag_current_class_tl{\@currname.\@currext}
       \tl_const:Ne \c__tag_status_class_tl
        {
          \cs_if_exist:cTF { t@status@\@currname.\@currext }
           {
             \int_case:nn { \int_use:c { t@status@\@currname.\@currext } }
              {
                {0}{unknown}
                {1}{unsupported}
                {2}{currently~incompatible}
                {3}{partially~compatible}
                {4}{compatible}
              }
           }
           { not~in~the~status~list}
        }
     }
   \AddToHook{begindocument}{\tl_gset_eq:NN \g__tag_status_filelist_tl\@filelist}
   \AddToHook{enddocument/info}
     {
      \iow_term:n{}
      \iow_term:n
       {======================================}
      \iow_term:n{~~Status~report~of~the~tagging~support}
      \iow_term:n{======================================}
      \iow_term:n{~~Details~at~https://latex3.github.io/tagging-project/tagging-status}
      \iow_term:n{~~Report~erroneous~entries~at~https://github.com/latex3/tagging-project}
      \iow_term:n{}
      \iow_term:n{~~A.~CLASS}
      \iow_term:n{~~********}
      \iow_term:n{}
      \iow_term:e{~~\c__tag_current_class_tl\c_space_tl is~\c__tag_status_class_tl}
      \iow_term:n{}
      \iow_term:n{~~B.~PACKAGES,~LIBRARIES,~etc}
      \iow_term:n{~~***********}
      \iow_term:n{}
      \__tag_status_sort:
      \__tag_status_type:nn{1}{1.~Unsupported}
      \__tag_status_type:nn{2}{2.~Currently~incompatible}
      \__tag_status_type:nn{3}{3.~Partially~compatible}
      \__tag_status_type:nn{4}{4.~Compatible}
      \__tag_status_type:nn{0}{5.~Unknown}
      \__tag_status_type:nn{-1}{6.~Unclassified~files~with~extension~.sty}
       \iow_term:n{====================================}
      \iow_term:n{~~End~of~status~report}
      \iow_term:n{====================================}
    }
 }
\cs_generate_variant:Nn \text_bcp_parse:n {e}
\cs_new_protected:Npn\__pdfmanagement_update_BCPdata:
 {
   \tl_set:Ne\l__pdfmanagement_tmpa_tl { \text_bcp_parse:e{\GetDocumentProperty{document/language}} }
   \use:e
    {
     \exp_not:N\renewcommand*\exp_not:N\BCPdata[1]
      {
       \exp_not:N \str_case:nn {##1}
        {
         { language } %was en
           { \exp_last_unbraced:No\use_i:nnnnnnn { \l__pdfmanagement_tmpa_tl} }
         { region }   %was US
           { \exp_last_unbraced:No\use_iv:nnnnnnn { \l__pdfmanagement_tmpa_tl} }
         { script }   %was Latn
           { \exp_last_unbraced:No\use_iii:nnnnnnn { \l__pdfmanagement_tmpa_tl} }
         { tag }      %was en-US
           { \exp_last_unbraced:No\use_i:nnnnnnn { \l__pdfmanagement_tmpa_tl}-
             \exp_last_unbraced:No\use_iv:nnnnnnn { \l__pdfmanagement_tmpa_tl}
           }
        }
      }
   }
 }

\cs_new_protected:Npn \__pdfmanagement_language_set:n #1
 {
   \tl_if_head_eq_charcode:nNTF {#1}[ %]
    {
      \__pdfmanagement_language_set_aux:wn  #1
    }
    {
      \AddToDocumentProperties[document]{language}{#1}
      \keys_set:ne{document/metadata}{lang={#1}}
    }
 }

\cs_new_protected:Npn \__pdfmanagement_language_set_aux:wn [#1] #2
  {
     \AddToDocumentProperties[document]{language}{#2}
     \keys_set:ne{document/metadata}{lang={#1}}
  }
\keys_define:nn { document / metadata }
 {
   language      .code:n =
    {
      \__pdfmanagement_language_set:n {#1}
    },
   other-languages.code:n = {\AddToDocumentProperties [document]{other-languages}{#1}},
 }
\keys_define:nn { document / metadata }
  {
    backend .choices:nn =
      { dvipdfmx , dvips , dvisvgm , luatex , pdftex , pdfmode , xdvipdfmx , xetex }
      {
        \sys_load_backend:n {#1}
      },
    backend .groups:n = { init } ,
  }
\keys_define:nn { document / metadata }
 {
    ,check-tagging-status .choice:
    ,check-tagging-status / off .code:n = {}
    ,check-tagging-status / listfiles .code:n =
      {
        \__tag_status_log:
      }
    ,check-tagging-status .default:n = {listfiles}
 }
\keys_define:nn { document / metadata }
  {
    ,pdfversion .groups:n = { pdf }
    ,pdfstandard .groups:n = { pdf }
    ,lang .code:n =
      {
        \pdfmanagement_add:nnn {Catalog} {Lang}{(#1)}
        \AddToDocumentProperties[document]{lang}{#1}
      }
    ,testphase .multichoices:nn =
     {latest,tagpdf,phase-I,phase-II,phase-III}
     {
       \keys_set:nn
        {document / metadata}
        {tagging=on}
     }
    ,testphase .multichoices:nn =
     {math,new-or,sec,sec-template,toc,graphic,block,minipage,float,
      bib,context,text,firstaid,table,title,marginpar,tikz}
     {}
    ,testphase / unknown .code:n =
      {
        \tl_gput_right:Nn\g__pdfmanagement_testphase_tl
           {
             \tl_if_empty:eT{\GetDocumentProperties{document/testphase/#1}}
              {
                \AddToDocumentProperties [document]{testphase/#1}{loaded}
                \file_if_exist_input:nF {#1-latex-lab-testphase.ltx}
                 {
                  \msg_warning:nnn{meta}{latex-lab-pkg-missing}{#1}
                  \AddToDocumentProperties [document]{testphase/#1}{missing}
                 }
              }
           }
      }
  }
\cs_new_protected:Npn \__tag_document_set_tagging_off:
 {
    \sys_if_engine_luatex:F
     { \AddToHook{shipout/firstpage}[tagpdf/space]{} }
    \tagpdfsetup{activate/mc=false,activate/tree=false,
       activate/struct=false,activate/socket=false,
       activate/spaces=false,
       para/tagging=false,math/setup=}
    \AddToDocumentProperties [document]{tagging}{inactive}
    \AddToDocumentProperties [document]{tagging/para}{inactive}
    \AddToDocumentProperties [document]{tagging/interwordspace}{inactive}
    \tag_suspend:n {global}
           \cs_set_protected:Npn\tagpdfsetup##1{}
 }
\cs_new_protected:Npn \__tag_document_set_tagging_on:
 {
   \tagpdfsetup{activate,para/tagging,activate/spaces}
   \AddToDocumentProperties [document]{tagging}{active}
   \AddToDocumentProperties [document]{tagging/para}{active}
   \AddToDocumentProperties [document]{tagging/interwordspace}{active}
 }
\cs_new_eq:NN \__tag_document_set_tagging:\__tag_document_set_tagging_off:
\AddToHookNext{class/before}{\__tag_document_set_tagging:}
\keys_define:nn { document / metadata }
  {
    ,tagging .choice:,
    ,tagging / on .code:n =
      {
        \cs_set_eq:NN \__tag_document_set_tagging:\__tag_document_set_tagging_on:
      }
    ,tagging / off .code:n =
      {
        \cs_set_eq:NN \__tag_document_set_tagging:\__tag_document_set_tagging_off:
      }
    ,tagging / draft .code:n =
      {
        \keys_set:nn { document / metadata }{ tagging=on }
        \AddToHook{shipout/lastpage}[tagging-setup]{\tagpdfsetup{activate/tree=false}}
        \DeclareHookRule{shipout/lastpage}{tagging-setup}{before}{tagpdf}
      }
    ,tagging-setup .code:n =
      {
        \keys_set:nn { document / metadata }{ tagging=on }
        \tl_gclear:N\g__pdfmanagement_testphase_tl
        \keys_set_groups:nnn{__tag/setup}{load}{#1}
        \AddToHook{class/before}
         {\keys_set_exclude_groups:nnn {__tag/setup}{load}{#1}}
      }
    ,debug .code:n =
      {
        \keys_set:nn { document / metadata / debug } {#1}
      }
    ,debug / para .code:n =
      {
        \AddToHook
          {
            package/tagpdf/after
          }
          {
             \tagpdfsetup{debug/show=para}
          }
      }
    ,debug / log .code:n =
      {
        \AddToHook
          {
           package/tagpdf/after
          }
          {
             \tagpdfsetup{debug/log=#1}
          }
      }
    ,debug / tagpdf .code:n =
      {
        \AddToHook
          {
           package/tagpdf/after
          }
          {
             \RequirePackage{tagpdf-debug}
          }
      }
    ,debug / uncompress .code:n =
      {
        \pdf_uncompress:
      }
    ,debug / pdfmanagement .bool_gset:N = \g__pdfmanagement_active_bool
    ,debug / firstaidoff .clist_gset:N = \g__pdfmanagement_firstaidoff_clist
    ,debug / BBox .code:n =
      {
        \AddToHook{package/latex-lab-testphase-graphic/after}
         { \bool_set_true:N \l__tag_graphic_debug_bool}
      }
  }
\keys_define:nn{__tag/setup}
 {
   ,modules .code:n =
     {
      \keys_set:nn { document / metadata }{testphase={#1}}
     }
   ,modules .groups:n = { load }
   ,extra-modules .code:n =
     {
       \keys_set:nn { document / metadata }{testphase={#1}}
     }
   ,extra-modules .groups:n = { load }
 }
\prop_gput:Nnn \g_msg_module_type_prop { meta } { LaTeX }
\prop_gput:Nnn \g_msg_module_name_prop { meta } { DocumentMetadata }

\msg_new:nnn { meta } { after-class }
             {
                \token_to_str:N \DocumentMetadata \c_space_tl
                should~be~used~only~before~\token_to_str:N\documentclass
             }
\msg_new:nnn { meta } { latex-lab-pkg-missing }
             {
               LaTeX-lab~package~'#1'~not~found.
              }
\ExplSyntaxOff\makeatother
\endinput
%%
%% End of file `documentmetadata-support.ltx'.
