From 9fc4fc7a3e0c2a085bf32447278e741e6667b206 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 23 Feb 2021 22:24:07 +0000 Subject: tagpdf (23feb21) git-svn-id: svn://tug.org/texlive/trunk@57857 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/latex/tagpdf/tagpdf-attr-code.sty | 217 +++-- .../tex/latex/tagpdf/tagpdf-checks-code.sty | 330 ++++--- .../tex/latex/tagpdf/tagpdf-deprecated.def | 24 + .../texmf-dist/tex/latex/tagpdf/tagpdf-luatex.def | 273 ++---- .../tex/latex/tagpdf/tagpdf-mc-code-generic.sty | 506 +++++----- .../tex/latex/tagpdf/tagpdf-mc-code-lua.sty | 585 ++++++------ .../tex/latex/tagpdf/tagpdf-mc-code-shared.sty | 121 ++- .../texmf-dist/tex/latex/tagpdf/tagpdf-pdftex.def | 147 +-- .../tex/latex/tagpdf/tagpdf-roles-code.sty | 236 ++--- .../tex/latex/tagpdf/tagpdf-space-code.sty | 98 +- .../tex/latex/tagpdf/tagpdf-struct-code.sty | 1010 +++++++++++--------- .../tex/latex/tagpdf/tagpdf-tree-code.sty | 448 +++++---- Master/texmf-dist/tex/latex/tagpdf/tagpdf-user.sty | 193 ++-- Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua | 643 +++++++------ Master/texmf-dist/tex/latex/tagpdf/tagpdf.sty | 367 ++++--- .../tex/latex/tagpdf/tagpdfdocu-patches.sty | 195 ++-- 16 files changed, 2874 insertions(+), 2519 deletions(-) create mode 100644 Master/texmf-dist/tex/latex/tagpdf/tagpdf-deprecated.def (limited to 'Master/texmf-dist/tex/latex') diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-attr-code.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-attr-code.sty index 9bb57f2bb38..03bfb78a98d 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-attr-code.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-attr-code.sty @@ -1,110 +1,129 @@ -\ProvidesExplPackage {tagpdf-attr-code} {2019/07/02} {0.61} - {part of tagpdf - code related to attributes and attribute classes} +%% +%% This is file `tagpdf-attr-code.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf-struct.dtx (with options: `attr') +%% +%% Copyright (C) 2019 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-struct.dtx -% the obj is written in tagpdf-tree-code. +\ProvidesExplPackage {tagpdf-attr-code} {2021/02/23} {0.80} + {part of tagpdf - code related to attributes and attribute classes} -\seq_new:N \g__uftag_attr_class_used_seq -\prop_new:N \g__uftag_attr_objnum_prop %will contain obj num of used attributes -\prop_new:N \g__uftag_attr_entries_prop -\tl_new:N \g__uftag_attr_class_content_tl -\tl_new:N \l__uftag_attr_objtmp_tl -\tl_new:N \l__uftag_attr_value_tl +\seq_new:N \g__tag_attr_class_used_seq +\prop_new:N \g__tag_attr_objref_prop %will contain obj num of used attributes +\prop_new:N \g__tag_attr_entries_prop +\tl_new:N \g__tag_attr_class_content_tl +\tl_new:N \l__tag_attr_objtmp_tl +\tl_new:N \l__tag_attr_value_tl -\cs_new_protected:Nn \__uftag_attr_new_entry:nn %#1:name, #2: content - { - \prop_gput:Nnn \g__uftag_attr_entries_prop - {#1}{#2} - } +\cs_new_protected:Nn \__tag_attr_new_entry:nn %#1:name, #2: content + { + \prop_gput:Nnn \g__tag_attr_entries_prop + {#1}{#2} + } -\keys_define:nn { uftag / setup } - { - newattribute .code:n = - { - \__uftag_attr_new_entry:nn #1 - } - } - - -% the key for the structure: -\keys_define:nn { uftag / struct } -{ - attribute-class .code:n = - { - \clist_set:No \l_tmpa_clist { #1 } - \seq_set_from_clist:NN \l_tmpa_seq \l_tmpa_clist - \seq_map_inline:Nn \l_tmpa_seq - { - \prop_if_in:NnF \g__uftag_attr_entries_prop {##1} +\keys_define:nn { __tag / setup } + { + newattribute .code:n = { - \msg_error:nnn { uftag } { attr-unknown } { ##1 } + \__tag_attr_new_entry:nn #1 } - \seq_gput_left:Nn\g__uftag_attr_class_used_seq { ##1} - } - \seq_set_map:NNn \l_tmpb_seq \l_tmpa_seq - { - /##1 - } - \tl_set:Nx \l_tmpa_tl - { - \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{[} - \seq_use:Nn \l_tmpb_seq { \c_space_tl } - \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{]} - } - \int_compare:nT { \seq_count:N \l_tmpa_seq > 0 } - { - \__uftag_prop_gput:cnx - { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop } - { C } - { \l_tmpa_tl } - %\prop_show:c { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop } - } - } -} + } -\keys_define:nn { uftag / struct } - { - attribute .code:n = % A property (attribute, value currently a dictionary) - { - \clist_set:No \l_tmpa_clist { #1 } - \seq_set_from_clist:NN \l_tmpa_seq \l_tmpa_clist - \tl_set:Nx \l__uftag_attr_value_tl - { - \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{[} +\keys_define:nn { __tag / struct } + { + attribute-class .code:n = + { + \clist_set:No \l_tmpa_clist { #1 } + \seq_set_from_clist:NN \l_tmpa_seq \l_tmpa_clist + \seq_map_inline:Nn \l_tmpa_seq + { + \prop_if_in:NnF \g__tag_attr_entries_prop {##1} + { + \msg_error:nnn { tag } { attr-unknown } { ##1 } + } + \seq_gput_left:Nn\g__tag_attr_class_used_seq { ##1} + } + \seq_set_map:NNn \l_tmpb_seq \l_tmpa_seq + { + /##1 + } + \tl_set:Nx \l_tmpa_tl + { + \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{[} + \seq_use:Nn \l_tmpb_seq { \c_space_tl } + \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{]} + } + \int_compare:nT { \seq_count:N \l_tmpa_seq > 0 } + { + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { C } + { \l_tmpa_tl } + %\prop_show:c { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + } } - \seq_map_inline:Nn \l_tmpa_seq - { - \prop_if_in:NnF \g__uftag_attr_entries_prop {##1} - { - \msg_error:nnn { uftag } { attr-unknown } { ##1 } - } - \prop_if_in:NnF \g__uftag_attr_objnum_prop {##1} - { - \__uftag_pdfreserveobjnum:N \l_tmpa_tl - \__uftag_pdfuseobjnum:Nx \l_tmpa_tl - { - \prop_item:Nn\g__uftag_attr_entries_prop {##1} - } - \prop_gput:NnV \g__uftag_attr_objnum_prop {##1} {\l_tmpa_tl} - } - \tl_put_right:Nx \l__uftag_attr_value_tl + } + +\keys_define:nn { __tag / struct } + { + attribute .code:n = % A property (attribute, value currently a dictionary) { - \c_space_tl - \prop_item:Nn \g__uftag_attr_objnum_prop {##1} - \c_space_tl 0 \c_space_tl R - } - % \tl_show:N \l__uftag_attr_value_tl - } - \tl_put_right:Nx \l__uftag_attr_value_tl - { - \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{]} - } - % \tl_show:N \l__uftag_attr_value_tl - \__uftag_prop_gput:cnx - { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop } - { A } - { \l__uftag_attr_value_tl } - }, - } -\endinput + \clist_set:No \l_tmpa_clist { #1 } + \seq_set_from_clist:NN \l_tmpa_seq \l_tmpa_clist + \tl_set:Nx \l__tag_attr_value_tl + { + \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{[}%] + } + \seq_map_inline:Nn \l_tmpa_seq + { + \prop_if_in:NnF \g__tag_attr_entries_prop {##1} + { + \msg_error:nnn { tag } { attr-unknown } { ##1 } + } + \prop_if_in:NnF \g__tag_attr_objref_prop {##1} + {%\prop_show:N \g__tag_attr_entries_prop + \pdf_object_unnamed_write:nx + { dict } + { + \prop_item:Nn\g__tag_attr_entries_prop {##1} + } + \prop_gput:Nnx \g__tag_attr_objref_prop {##1} {\pdf_object_ref_last:} + } + \tl_put_right:Nx \l__tag_attr_value_tl + { + \c_space_tl + \prop_item:Nn \g__tag_attr_objref_prop {##1} + } + % \tl_show:N \l__tag_attr_value_tl + } + \tl_put_right:Nx \l__tag_attr_value_tl + { %[ + \int_compare:nT { \seq_count:N \l_tmpa_seq > 1 }{]}% + } + % \tl_show:N \l__tag_attr_value_tl + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { A } + { \l__tag_attr_value_tl } + }, + } +%% +%% +%% End of file `tagpdf-attr-code.sty'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-checks-code.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-checks-code.sty index 6d224c4164a..d11f1fdda2f 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-checks-code.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-checks-code.sty @@ -1,188 +1,208 @@ -\ProvidesExplPackage {tagpdf-checks-code} {2019/07/02} {0.61} +%% +%% This is file `tagpdf-checks-code.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf-checks.dtx (with options: `checks') +%% +%% Copyright (C) 2019 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-checks.dtx +\ProvidesExplPackage {tagpdf-checks-code} {2021/02/23} {0.80} {part of tagpdf - code related to checks and messages} -%messages +\msg_new:nnn { tag } {mc-nested} { nested~marked~content~found~-~mcid~#1 } +\msg_new:nnn { tag } {mc-tag-missing} { required~tag~missing~-~mcid~#1 } +\msg_new:nnn { tag } {mc-label-unknown} { label~#1~unknown~-~rerun } +\msg_new:nnn { tag } {mc-used-twice} { mc~#1~has~been~already~used } +\msg_new:nnn { tag } {mc-not-open} { there~is~no~mc~to~end~at~#1 } -% mc -\msg_new:nnn {uftag} {mc-nested} { nested~marked~content~found~-~mcid~#1 } -\msg_new:nnn {uftag} {mc-tag-missing} { required~tag~missing~-~mcid~#1 } -\msg_new:nnn {uftag} {mc-label-unknown} { label~#1~unknown~-~rerun } -\msg_new:nnn {uftag} {mc-used-twice} { mc~#1~has~been~already~used } -\msg_new:nnn {uftag} {mc-not-open} { there~is~no~mc~to~end~at~#1 } +\msg_new:nnn { tag } {struct-no-objnum} { objnum~missing~for~structure~#1 } +\msg_new:nnn { tag } {struct-faulty-nesting} { there~is~no~open~structure~on~the~stack } +\msg_new:nnn { tag } {struct-missing-tag} { a~structure~must~have~a~tag! } +\msg_new:nnn { tag } {struct-show-closing} { closing~structure~#1~tagged~\prop_item:cn{g__tag_struct_#1_prop}{S} } +\msg_new:nnn { tag } {struct-used-twice} { structure~with~label~#1~has~already~been~used} +\msg_new:nnn { tag } {struct-label-unknown} { structure~with~label~#1~is~unknown~rerun} -% structures -\msg_new:nnn {uftag} {struct-no-objnum} { objnum~missing~for~structure~#1 } -\msg_new:nnn {uftag} {struct-faulty-nesting} { there~is~no~open~structure~on~the~stack } -\msg_new:nnn {uftag} {struct-missing-tag} { a~structure~must~have~a~tag! } -\msg_new:nnn {uftag} {struct-show-closing} { closing~structure~#1~tagged~\prop_item:cn{g__uftag_struct_#1_prop}{S} } -\msg_new:nnn {uftag} {struct-used-twice} { structure~with~label~#1~has~already~been~used} -\msg_new:nnn {uftag} {struct-label-unknown} { structure~with~label~#1~is~unknown~rerun} +\msg_new:nnn { tag } {attr-unknown} { attribute~#1~is~unknown} -% attributes -\msg_new:nnn {uftag} {attr-unknown} { attribute~#1~is~unknown} +\msg_new:nnn { tag } {role-missing} { tag~#1~has~no~role~assigned } +\msg_new:nnn { tag } {role-unknown} { role~#1~is~not~known } +\msg_new:nnn { tag } {role-unknown-tag} { tag~#1~is~not~known } +\msg_new:nnn { tag } {role-new-tag} { adding~new~tag~#1~mapped~to~role~#2 } +\msg_new:nnn { tag } {tree-mcid-index-wrong} {something~is~wrong~with~the~mcid} -%Roles -\msg_new:nnn {uftag} {role-missing} { tag~#1~has~no~role~assigned } -\msg_new:nnn {uftag} {role-unknown} { role~#1~is~not~known } -\msg_new:nnn {uftag} {role-unknown-tag} { tag~#1~is~not~known } -\msg_new:nnn {uftag} {role-new-tag} { adding~new~tag~#1~mapped~to~role~#2 } +\msg_new:nnn { tag } {obj-write-num} {write~obj~#1~to~pdf} +\msg_new:nnn { tag } {sys-no-interwordspace} {engine~#1~doesn't~support~the~interword~spaces} -% trees -\msg_new:nnn {uftag} {tree-mcid-index-wrong} {something~is~wrong~with~the~mcid} -% obj -\msg_new:nnn {uftag} {obj-write-num} {write~obj~#1~to~pdf} - - -%checks -%structures +\cs_new:Nn \__tag_check_structure_has_tag:n %#1 struct num %_protected? + { + \prop_if_in:cnF { g__tag_struct_#1_prop } + {S} + { + \msg_error:nn { tag } {struct-missing-tag} + } + } -\cs_new:Nn \__uftag_check_structure_has_tag:n %#1 struct num - { - \prop_if_in:cnF { g__uftag_struct_#1_prop } - {S} - { - \msg_error:nn {uftag} {struct-missing-tag} - } - } +\cs_new:Nn \__tag_check_structure_tag:N %_protected? + { + \prop_if_in:NoF \g__tag_role_tags_prop {#1} + { + \msg_warning:nnx { tag } {role-unknown-tag} {#1} + } + } -\cs_new:Nn \__uftag_check_structure_tag:N - { - \prop_if_in:NoF \g__uftag_role_tags_prop {#1} - { - \msg_warning:nnx {uftag} {role-unknown-tag} {#1} - } - } +\cs_new_protected:Nn \__tag_check_info_closing_struct:n %#1 struct num + { + \msg_info:nnn { tag } {struct-show-closing} {#1} + } -\cs_new:Nn \__uftag_check_info_closing_struct:n %#1 struct num - { - \msg_info:nnn {uftag} {struct-show-closing} {#1} - } +\cs_generate_variant:Nn \__tag_check_info_closing_struct:n {o,x} -\cs_generate_variant:Nn \__uftag_check_info_closing_struct:n {o,x} +\cs_new_protected:Nn \__tag_check_no_open_struck: + { + \msg_error:nn { tag } {struct-faulty-nesting} + } -\cs_new:Nn \__uftag_check_no_open_struck: - { - \msg_error:nn {uftag} {struct-faulty-nesting} - } +\cs_new_protected:Nn \__tag_check_struct_used:n %#1 label + { + \prop_get:cnNT + {g__tag_struct_\__tag_ref_value:enn{tagpdfstruct-#1}{tagstruct}{unknown}_prop} + {P} + \l_tmpa_tl + { + \msg_warning:nnn { tag } {struct-used-twice} {#1} + } + } -\cs_new:Nn \__uftag_check_struct_used:n %#1 label - { - \prop_get:cnNT - {g__uftag_struct_\zref@extractdefault{tagpdfstruct-#1}{tagstruct}{unknown}_prop} - {P} - \l_tmpa_tl - { \msg_warning:nnn {uftag} {struct-used-twice} {#1} } - } -%roles +\cs_new_protected:Nn \__tag_check_add_tag_role:nn %#1 tag, #2 role + { + \tl_if_empty:nTF {#2} + { + \msg_warning:nnn { tag } {role-missing} {#1} + } + { + \prop_get:NnNTF \g__tag_role_tags_prop {#2} \l_tmpa_tl + { + \msg_info:nnnn { tag } {role-new-tag} {#1} {#2} + } + { + \msg_warning:nnn { tag } {role-unknown} {#2} + } + } + } -\cs_new:Nn \__uftag_check_add_tag_role:nn %#1 tag, #2 role - { - \tl_if_empty:nTF {#2} +\cs_new_protected:Nn \__tag_check_mc_if_nested: { - \msg_warning:nnn {uftag} {role-missing} {#1} + \__tag_mc_if_in:T + { + \msg_warning:nnx { tag } {mc-nested} { \__tag_get_mc_abs_cnt: } + } } + +\cs_new_protected:Nn \__tag_check_mc_if_open: { - \prop_get:NnNF \g__uftag_role_tags_prop {#2} \l_tmpa_tl - { - \msg_warning:nnn {uftag} {role-unknown} {#2} - } - { - \msg_info:nnnn {uftag} {role-new-tag} {#1} {#2} - } + \__tag_mc_if_in:F + { + \msg_warning:nnx { tag } {mc-not-open} { \__tag_get_mc_abs_cnt: } + } } - } - -%mc -\cs_new:Nn \__uftag_check_mc_if_nested: - { - \__uftag_mc_if_in:T - { - \msg_warning:nnx {uftag} {mc-nested} { \__uftag_get_mc_abs_cnt: } - } - } - -\cs_new:Nn \__uftag_check_mc_if_open: - { - \__uftag_mc_if_in:F - { - \msg_warning:nnx {uftag} {mc-not-open} { \__uftag_get_mc_abs_cnt: } - } - } - -\cs_new:Nn \__uftag_check_mc_tag:N - { - \tl_if_empty:NT #1 - { - \msg_error:nnx {uftag} {mc-tag-missing} { \__uftag_get_mc_abs_cnt: } - } - \prop_if_in:NoF \g__uftag_role_tags_prop {#1} - { - \msg_warning:nnx {uftag} {role-unknown-tag} {#1} - } - } - -\seq_new:N \g__uftag_check_mc_used_seq -\cs_new:Nn \__uftag_check_mc_used:n - { - \seq_if_in:NnTF \g__uftag_check_mc_used_seq {#1} - { - \msg_warning:nnn {uftag} {mc-used-twice} {#1} - } - { - \seq_gput_right:Nx \g__uftag_check_mc_used_seq {#1} - } - } - - - -\cs_new:Nn \__uftag_check_show_MCID_by_page: - { - \tl_set:Nx \l__uftag_tmpa_tl + +\cs_new:Nn \__tag_check_mc_tag:N %protected?? { - \zref@extractdefault - {LastPage} {abspage} {-1} + \tl_if_empty:NT #1 + { + \msg_error:nnx { tag } {mc-tag-missing} { \__tag_get_mc_abs_cnt: } + } + \prop_if_in:NoF \g__tag_role_tags_prop {#1} + { + \msg_warning:nnx { tag } {role-unknown-tag} {#1} + } } - \int_step_inline:nnnn {1}{1} + +\seq_new:N \g__tag_check_mc_used_seq +\cs_new_protected:Nn \__tag_check_mc_used:n { - \l__uftag_tmpa_tl + \seq_if_in:NnTF \g__tag_check_mc_used_seq {#1} + { + \msg_warning:nnn { tag } {mc-used-twice} {#1} + } + { + \seq_gput_right:Nx \g__tag_check_mc_used_seq {#1} + } } + +\cs_new_protected:Nn \__tag_check_show_MCID_by_page: { - \seq_clear:N \l_tmpa_seq - \int_step_inline:nnnn {1}{1} - { - \zref@extractdefault - {LastPage} {tagmcabs} {-1} - } - { - \int_compare:nT - { - \zref@extractdefault - {mcid-####1} {tagabspage} {-1} - = ##1 - } - { - \seq_gput_right:Nx \l_tmpa_seq + \tl_set:Nx \l__tag_tmpa_tl { - Page##1-####1-\zref@extractdefault - {mcid-####1} {tagmcid} {-1} + \__tag_ref_value_lastpage:nn + {abspage} + {-1} + } + \int_step_inline:nnnn {1}{1} + { + \l__tag_tmpa_tl + } + { + \seq_clear:N \l_tmpa_seq + \int_step_inline:nnnn + {1} + {1} + { + \__tag_ref_value_lastpage:nn + {tagmcabs} + {-1} + } + { + \int_compare:nT + { + \__tag_ref_value:enn + {mcid-####1} + {tagabspage} + {-1} + = + ##1 + } + { + \seq_gput_right:Nx \l_tmpa_seq + { + Page##1-####1- + \__tag_ref_value:enn + {mcid-####1} + {tagmcid} + {-1} + } + } + } + \seq_show:N \l_tmpa_seq } - } - } - \seq_show:N \l_tmpa_seq } - } -\cs_new:Nn \__uftag_check_record_pdfobj_num:n - { - \int_compare:nT { \l__uftag_loglevel_int >= 3 } - { - \msg_info:nnx {uftag} {obj-write-num} {#1} - } - } +\cs_new:Nn \__tag_check_record_pdfobj_num:n %protected? + { + \int_compare:nT { \l__tag_loglevel_int >= 3 } + { + \msg_info:nnx { tag } {obj-write-num} {#1} + } + } -\endinput +%% +%% +%% End of file `tagpdf-checks-code.sty'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-deprecated.def b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-deprecated.def new file mode 100644 index 00000000000..23b95e67664 --- /dev/null +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-deprecated.def @@ -0,0 +1,24 @@ +%% +%% This is file `tagpdf-deprecated.def', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf.dtx (with options: `deprecated') +%% +%% Copyright (C) 2019 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 +%% +%% +%% End of file `tagpdf-deprecated.def'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-luatex.def b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-luatex.def index 5cb16c5216c..d1f772d4279 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-luatex.def +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-luatex.def @@ -1,196 +1,101 @@ -\ProvidesExplFile {tagpdf-luatex.def} {2019/07/02} {0.61} +%% +%% This is file `tagpdf-luatex.def', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf-backend.dtx (with options: `luatex') +%% +%% Copyright (C) 2019 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-backend.dtx +\ProvidesExplFile {tagpdf-luatex.def} {2021/02/23} {0.80} {tagpdf~driver~for~luatex} -%\newattribute \g__uftag_mc_type_attr %the value represent the type -%\newattribute \g__uftag_mc_cnt_attr %will hold the \c@g__uftag_MCID_abs_int value +\newattribute \l__tag_mc_type_attr %the value represent the type +\newattribute \l__tag_mc_cnt_attr %will hold the \c@g__tag_MCID_abs_int value -\newattribute \l__uftag_mc_type_attr %the value represent the type -\newattribute \l__uftag_mc_cnt_attr %will hold the \c@g__uftag_MCID_abs_int value +\newattribute \g__tag_interwordspace_attr +\newattribute \g__tag_interwordfont_attr -\newattribute \g__uftag_interwordspace_attr -\newattribute \g__uftag_interwordfont_attr - -% The lua code -% ensure that 10pt font has been loaded: { - \fontencoding{TU}\fontfamily{lmr}\fontseries{m}\fontshape{n}\fontsize{10pt}{10pt}\selectfont + \fontencoding{TU}\fontfamily{lmr}\fontseries{m}\fontshape{n}\fontsize{10pt}{10pt}\selectfont } \directlua { tagpdf=require('tagpdf.lua') } %%%% driver (lualatex) commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% these should be in expl3!!! -\cs_new:Nn \__uftag_pdf_startlink:{ \pdfextension startlink } -\cs_new:Nn \__uftag_pdf_endlink: { \pdfextension endlink } -\cs_new_protected:Nn \__uftag_pdf_lastlink: { \numexpr\pdffeedback lastlink\relax } -\cs_new:Nn \__uftag_pdf_catalog: { \pdfextension catalog } - -% needed for \str_set_convert:Nnon -\tl_new:N \g__uftag_inputencoding_tl -\tl_gset:Nn \g__uftag_inputencoding_tl {} - - -% literals -\cs_new:Nn \__uftag_pdfliteral_page:n {\__uftag_tex_pdfextension:D literal~page {#1}} -\cs_new:Nn \__uftag_pdfcatalog:n {\__uftag_tex_pdfextension:D catalog {#1}} - -%reserve an object num -\cs_new:Nn \__uftag_pdfreserveobjnum:N - { - % #1 = macro name to be populated with object number - \__uftag_tex_pdfextension:D~obj~reserveobjnum - \tl_set:Nx #1 { \__uftag_tex_pdffeedback:D lastobj }% - } - -% use an object num -\cs_new:Nn \__uftag_pdfuseobjnum:Nn - { - % #1 = macro with object number to be populated - % #2 = object contents, as valid PDF - % should #2 be filtered through \pdfstringdef ??? - \__uftag_tex_immediate:D \__uftag_tex_pdfextension:D~obj~useobjnum~#1~{ #2 }% - } - -\cs_new:Nn \__uftag_pdfuseobjnum:nn - { - % #1 = a number - % #2 = object contents, as valid PDF - % should #2 be filtered through \pdfstringdef ??? - \__uftag_tex_immediate:D \__uftag_tex_pdfextension:D~obj~useobjnum~#1~{ #2 }% - } - -% obj num of the dictionary for a page: -% the page count starts by 1 -% pages can referenced before they are actually created -% no error if the page later doesn't exist - -\cs_new:Nn \__uftag_store_pdfpageref:Nn - { - % #1 = macro name to be populated with current page object number - % #2 = number or counter identifying the required page - \tl_set:Nx #1 { \__uftag_tex_pdffeedback:D pageref~#2 }% - } - -% a global version of the command -\cs_new:Nn \__uftag_gstore_pdfpageref:Nn - { - \tl_gset:Nx #1 { \__uftag_tex_pdffeedback:D pageref~#2 }% - } - -\cs_new:Nn \__uftag_pdfobj:Nn - { - % #1 = macro name to refer to this object - % #2 = object contents, as valid PDF - % should #2 be filtered through \pdfstringdef ??? - \__uftag_tex_immediate:D \__uftag_tex_pdfextension:D~obj~{ #2 } - \tl_set:Nx #1 { \__uftag_tex_pdffeedback:D~lastobj }% - } - -% pdfpage**s**attr: for all pages -%% is global needed? Yes. Without it the setting is lost if issued in a group -% -\cs_new:Nn \__uftag_gset_pdfpagesattr:n - { - \__uftag_tex_global:D \__uftag_tex_pdfvariable:D~pagesattr { #1 } - } - -\cs_new:Nn \__uftag_gadd_pdfpagesattr:n - { - \exp_args:No \__uftag_gset_pdfpagesattr:n { \__uftag_tex_the:D \__uftag_tex_pdfvariable:D~pagesattr #1} - } - -% pdfpageattr for one page -% do we need an immediate version?? -\cs_new:Nn \__uftag_gset_pdfpageattr:n - { - \__uftag_tex_global:D \__uftag_tex_pdfvariable:D~pageattr { #1 } - } - -\cs_new:Nn \__uftag_gadd_pdfpageattr:n - { - \exp_args:No \__uftag_gset_pdfpageattr:n { \__uftag_tex_the:D \__uftag_tex_pdfvariable:D~pageattr #1} - } - -\cs_new:Nn \__uftag_get_pdfpageattr:N - { - \tl_set:No #1 { \__uftag_tex_the:D \__uftag_tex_pdfvariable:D~pageattr } - } - - -% I probably want also lua tables -% I put them in the uftag.tables namespaces -% The tables will be named like the variables but without backslash -% To access such a table with a dynamical name create a string and then use -% uftag.tables[string] -% Old code, I'm not quite sure if this was a good idea. Now I have mix of table in -% utftag.tables and uftag.mc/struct. And a lot is probably not needed. - -\cs_new:Nn \__uftag_luatex_get_table_name:Nn - { - \tl_set_rescan:Nnn #1 { \char_set_catcode_ignore:N \\ } { #2 } - } - - -\cs_new:Nn \__uftag_prop_new:N - { - \prop_new:N #1 - \__uftag_luatex_get_table_name:Nn \l_tmpa_tl { #1 } - \directlua { uftag.tables.\l_tmpa_tl = {} } - } - - -\cs_new:Nn \__uftag_seq_new:N - { - \seq_new:N #1 - \__uftag_luatex_get_table_name:Nn \l_tmpa_tl { #1 } - \directlua { uftag.tables.\l_tmpa_tl = {} } - } - - -\cs_new:Nn \__uftag_prop_gput:Nnn - { - \prop_gput:Nnn #1 { #2 } { #3 } - \__uftag_luatex_get_table_name:Nn \l_tmpa_tl { #1 } - \directlua { uftag.tables.\l_tmpa_tl["#2"] = "#3" } - } - - -\cs_new:Nn \__uftag_seq_gput_right:Nn - { - \seq_gput_right:Nn #1 { #2 } - \__uftag_luatex_get_table_name:Nn \l_tmpa_tl { #1 } - \directlua { table.insert(uftag.tables.\l_tmpa_tl, "#2") } - } - -%Hm not quite sure about the naming - -\cs_new:Npn \__uftag_seq_item:cn #1 #2 - { - \directlua { tex.print(uftag.tables.#1[#2]) } - } - -\cs_new:Npn \__uftag_prop_item:cn #1 #2 - { - \directlua { tex.print(uftag.tables.#1["#2"]) } - } - -%for debugging commands that show both the seq/prop and the lua tables -\cs_new:Nn \__uftag_seq_show:N - { - \seq_show:N #1 - \__uftag_luatex_get_table_name:Nn \l_tmpa_tl { #1 } - \directlua { uftag.trace.log ("lua~sequence~array~\l_tmpa_tl",1) } - \directlua { uftag.trace.show_seq (uftag.tables.\l_tmpa_tl) } - } - -\cs_new:Nn \__uftag_prop_show:N - { - \prop_show:N #1 - \__uftag_luatex_get_table_name:Nn \l_tmpa_tl { #1 } - \directlua {uftag.trace.log ("lua~property~table~\l_tmpa_tl",1) } - \directlua {uftag.trace.show_prop (uftag.tables.\l_tmpa_tl) } - } - -\endinput +\cs_new:Nn \__tag_luatex_get_table_name:Nn + { + \tl_set_rescan:Nnn #1 { \char_set_catcode_ignore:N \\ } { #2 } + } + +\cs_new:Nn \__tag_prop_new:N + { + \prop_new:N #1 + \__tag_luatex_get_table_name:Nn \l_tmpa_tl { #1 } + \directlua { ltx.__tag.tables.\l_tmpa_tl = {} } + } + +\cs_new:Nn \__tag_seq_new:N + { + \seq_new:N #1 + \__tag_luatex_get_table_name:Nn \l_tmpa_tl { #1 } + \directlua { ltx.__tag.tables.\l_tmpa_tl = {} } + } + +\cs_new:Nn \__tag_prop_gput:Nnn + { + \prop_gput:Nnn #1 { #2 } { #3 } + \__tag_luatex_get_table_name:Nn \l_tmpa_tl { #1 } + \directlua { ltx.__tag.tables.\l_tmpa_tl["#2"] = "#3" } + } + +\cs_new:Nn \__tag_seq_gput_right:Nn + { + \seq_gput_right:Nn #1 { #2 } + \__tag_luatex_get_table_name:Nn \l_tmpa_tl { #1 } + \directlua { table.insert(ltx.__tag.tables.\l_tmpa_tl, "#2") } + } + + +\cs_new:Npn \__tag_seq_item:cn #1 #2 + { + \directlua { tex.print(ltx.__tag.tables.#1[#2]) } + } + +\cs_new:Npn \__tag_prop_item:cn #1 #2 + { + \directlua { tex.print(ltx.__tag.tables.#1["#2"]) } + } + +\cs_new:Nn \__tag_seq_show:N + { + \seq_show:N #1 + \__tag_luatex_get_table_name:Nn \l_tmpa_tl { #1 } + \directlua { ltx.__tag.trace.log ("lua~sequence~array~\l_tmpa_tl",1) } + \directlua { ltx.__tag.trace.show_seq (ltx.__tag.tables.\l_tmpa_tl) } + } + +\cs_new:Nn \__tag_prop_show:N + { + \prop_show:N #1 + \__tag_luatex_get_table_name:Nn \l_tmpa_tl { #1 } + \directlua {ltx.__tag.trace.log ("lua~property~table~\l_tmpa_tl",1) } + \directlua {ltx.__tag.trace.show_prop (ltx.__tag.tables.\l_tmpa_tl) } + } +%% +%% +%% End of file `tagpdf-luatex.def'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-generic.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-generic.sty index 3f6ce228834..984df8a986a 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-generic.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-generic.sty @@ -1,285 +1,287 @@ -\ProvidesExplPackage {tagpdf-mc-code-generic} {2019/07/02} {0.61} +%% +%% This is file `tagpdf-mc-code-generic.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf-mc.dtx (with options: `generic') +%% +%% Copyright (C) 2019 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-mc.dtx +\ProvidesExplPackage {tagpdf-mc-code-generic} {2021/02/23} {0.80} {part of tagpdf - code related to marking chunks - generic mode} -% for the label system -% tagmcid is the id which should be also in the pdf -% it will be (hopefully) reset by page -\int_new:N \g__uftag_MCID_tmp_bypage_int -\zref@newprop {tagmcid} [0] { \int_use:N \g__uftag_MCID_tmp_bypage_int } -\zref@addprop {uftagzrl} {tagmcid} +\__tag_prop_new:N \g__tag_MCID_byabspage_prop -% will hold the current maximum on a page -% it will contain key-value of type "abspagenum=max mcid on this page" -\__uftag_prop_new:N \g__uftag_MCID_byabspage_prop +\bool_new:N \g__tag_in_mc_bool -%to test nesting mc: -\bool_new:N \g__uftag_in_mc_bool +\prg_new_conditional:Nnn \__tag_mc_if_in: {p,T,F,TF} + { + \bool_if:NTF \g__tag_in_mc_bool + { \prg_return_true: } + { \prg_return_false: } + } -\prg_new_conditional:Nnn \__uftag_mc_if_in: {p,T,F,TF} - { - \bool_if:NTF \g__uftag_in_mc_bool - { \prg_return_true: } - { \prg_return_false: } - } +\prg_new_eq_conditional:NNn \tag_mc_if_in: \__tag_mc_if_in: {p,T,F,TF} -\prg_new_eq_conditional:NNn \uftag_mc_if_in: \__uftag_mc_if_in: {p,T,F,TF} +\prg_new_eq_conditional:NNn \uftag_mc_if_in: \__tag_mc_if_in: {p,T,F,TF} +\cs_new_protected:Nn \__tag_mc_bmc:n + { + \pdf_bmc:n {#1} + } -% this are the low level mc command. -% they insert literals and so a are specific to generic mode -% checking if the type is defined will done somewhere else -% #1 is the type/tag -% change 04.08.2018: I don't try to escape the name, but assume that it is valid. -% Checks/conversions should perhaps be done on a higher level -\cs_new:Nn \__uftag_mc_bmc:n - { - \__uftag_pdfliteral_page:n - { - /#1\c_space_tl BMC - } - } +\cs_new_protected:Nn \__tag_mc_emc: + { + \pdf_emc: + %\__tag_pdfliteral_page:n + } -\cs_new:Nn \__uftag_mc_emc: - { - \__uftag_pdfliteral_page:n - { - EMC - } - } +\cs_new_protected:Nn \__tag_mc_bdc:nn + { + \pdf_bdc:nn { #1 } { #2 } + } + +\cs_generate_variant:Nn \__tag_mc_bdc:nn {nx} + +\tl_new:N \l__tag_mc_ref_abspage_tl %will store the abspage value of label +\tl_new:N \l__tag_mc_tmp_tl -% #1 tag, #2 properties -% change 04.08.2018: I don't escape the name. Also the dictionary content -% must imho be done at a higher level -\cs_new:Nn \__uftag_mc_bdc:nn - { - \__uftag_pdfliteral_page:n - { - /#1\c_space_tl<<#2>>~BDC - } +\cs_new:Nn \__tag_mc_bdc_mcid:nn + { + \int_gincr:N \c@g__tag_MCID_abs_int + \tl_set:Nx \l__tag_mc_ref_abspage_tl + { + \__tag_ref_value:enn %3 args + { + mcid-\int_use:N \c@g__tag_MCID_abs_int + } + { tagabspage } + {-1} + } + \prop_get:NoNTF + \g__tag_MCID_byabspage_prop + { + \l__tag_mc_ref_abspage_tl + } + \l__tag_mc_tmp_tl + { + %key already present, use value for MCID and add 1 for the next + \int_gset:Nn \g__tag_MCID_tmp_bypage_int { \l__tag_mc_tmp_tl } + \__tag_prop_gput:Nxx + \g__tag_MCID_byabspage_prop + { \l__tag_mc_ref_abspage_tl } + { \int_eval:n {\l__tag_mc_tmp_tl +1} } + } + { + %key not present, set MCID to 0 and insert 1 + \int_gzero:N \g__tag_MCID_tmp_bypage_int + \__tag_prop_gput:Nxx + \g__tag_MCID_byabspage_prop + { \l__tag_mc_ref_abspage_tl } + {1} + } + \__tag_ref_label:en + { + mcid-\int_use:N \c@g__tag_MCID_abs_int + } + { mc } + %\exp_args:Nnx + \__tag_mc_bdc:nx + {#1} + { /MCID~\int_eval:n { \g__tag_MCID_tmp_bypage_int }~ \exp_not:n { #2 } } } +\cs_new:Nn \__tag_mc_bdc_mcid:n + { + \__tag_mc_bdc_mcid:nn {#1} {} + } -% bdc with /MCID + more properties -% we need a ref-label system to ensure that the cnt restarts at 0 on a new page +\cs_new:Nn \__tag_mc_bmc_artifact: + { + \__tag_mc_bmc:n {Artifact} + } -\tl_new:N \l__uftag_mc_ref_abspage_tl %will store the abspage value of label -\tl_new:N \l__uftag_mc_tmp_tl +\cs_new:Nn \__tag_mc_bmc_artifact:n + { + \__tag_mc_bdc:nn {Artifact}{/Type/#1} + } -\cs_new:Nn \__uftag_mc_bdc_mcid:nn - { - \int_gincr:N \c@g__uftag_MCID_abs_int - \tl_set:Nx \l__uftag_mc_ref_abspage_tl - { - \zref@extractdefault %3 args - { - mcid-\int_use:N \c@g__uftag_MCID_abs_int - } - {tagabspage} - {-1} - } - \prop_get:NoNTF - \g__uftag_MCID_byabspage_prop - { - \l__uftag_mc_ref_abspage_tl - } - \l__uftag_mc_tmp_tl - { - %key already present, use value for MCID and add 1 for the next - \int_gset:Nn \g__uftag_MCID_tmp_bypage_int { \l__uftag_mc_tmp_tl } - \__uftag_prop_gput:Nxx - \g__uftag_MCID_byabspage_prop - { \l__uftag_mc_ref_abspage_tl } - { \int_eval:n {\l__uftag_mc_tmp_tl +1} } - } - { - %key not present, set MCID to 0 and insert 1 - \int_gzero:N \g__uftag_MCID_tmp_bypage_int - \__uftag_prop_gput:Nxx - \g__uftag_MCID_byabspage_prop - { \l__uftag_mc_ref_abspage_tl } - {1} - } - \zref@labelbylist - { - mcid-\int_use:N \c@g__uftag_MCID_abs_int - } - {uftagzrl} - \__uftag_mc_bdc:nn - {#1} - { /MCID~\int_eval:n { \g__uftag_MCID_tmp_bypage_int }~#2 } - } -% only /MCID -\cs_new:Nn \__uftag_mc_bdc_mcid:n - { - \__uftag_mc_bdc_mcid:nn {#1} {} - } -%artifact without type -\cs_new:Nn \__uftag_mc_bmc_artifact: - { - \__uftag_mc_bmc:n {Artifact} - } +\tl_new:N \l__tag_mc_key_tag_tl +\tl_new:N \g__tag_mc_key_tag_tl %for "outside" queries +\tl_new:N \l__tag_mc_key_properties_tl -%artifact with a type: -\cs_new:Nn \__uftag_mc_bmc_artifact:n - { - \__uftag_mc_bdc:nn {Artifact}{/Type\c_space_tl/#1} - } +\keys_define:nn { __tag / mc } + { + tag .code:n = % the name (H,P,Spa) etc + { + %%????????? \pdfescapename?? + \tl_set:Nx \l__tag_mc_key_tag_tl { #1 } + \tl_gset:Nx \g__tag_mc_key_tag_tl { #1 } + }, + raw .code:n = + { + \tl_put_right:Nx \l__tag_mc_key_properties_tl { #1 } + }, + alttext .code:n = % Alt property + { + \str_set_convert:Nnon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \tl_put_right:Nn \l__tag_mc_key_properties_tl { /Alt~< } + \tl_put_right:No \l__tag_mc_key_properties_tl { \l__tag_tmpa_str>~ } + }, + alttext-o .code:n = % Alt property + { + \str_set_convert:Noon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \tl_put_right:Nn \l__tag_mc_key_properties_tl { /Alt~< } + \tl_put_right:No \l__tag_mc_key_properties_tl { \l__tag_tmpa_str>~ } + }, + actualtext .code:n = % ActualText property + { + \str_set_convert:Nnon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \tl_put_right:Nn \l__tag_mc_key_properties_tl { /ActualText~< } + \tl_put_right:No \l__tag_mc_key_properties_tl { \l__tag_tmpa_str>~ } + }, + actualtext-o .code:n = % ActualText property + { + \str_set_convert:Noon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \tl_put_right:Nn \l__tag_mc_key_properties_tl { /ActualText~< } + \tl_put_right:No \l__tag_mc_key_properties_tl { \l__tag_tmpa_str>~ } + }, + label .tl_set:N = \l__tag_mc_key_label_tl, + artifact .code:n = + { + \exp_args:Nnx + \keys_set:nn + { __tag / mc } + { artifact-bool, artifact-type=#1 } + }, + artifact .default:n = {notype} + } -% perhaps later: more properties for artifacts +\cs_new:Nn \__tag_mc_handle_artifact:N %#1 contains the artifact type + { + \tl_if_empty:NTF #1 + { \__tag_mc_bmc_artifact: } + { \exp_args:No\__tag_mc_bmc_artifact:n {#1} } + } +\cs_new:Nn \__tag_mc_handle_mcid:nn %#1 tag, #2 properties + { + \__tag_mc_bdc_mcid:nn {#1} {#2} + } -% keyval definitions for the user commands: +\cs_generate_variant:Nn \__tag_mc_handle_mcid:nn {VV} -\tl_new:N \l__uftag_mc_key_tag_tl -\tl_new:N \g__uftag_mc_key_tag_tl %for "outside" queries -\tl_new:N \l__uftag_mc_key_properties_tl -%Attention! definitions are different in luamode. -% tag and raw are expanded as \directlua in lua does it too. -\keys_define:nn { uftag / mc } - { - tag .code:n = % the name (H,P,Span etc - { - %%????????? \pdfescapename?? - \tl_set:Nx \l__uftag_mc_key_tag_tl { #1 } - \tl_gset:Nx \g__uftag_mc_key_tag_tl { #1 } - }, - raw .code:n = - { - \tl_put_right:Nx \l__uftag_mc_key_properties_tl { #1 } - } - , - alttext .code:n = % Alt property - { - \str_set_convert:Nnon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \tl_put_right:Nn \l__uftag_mc_key_properties_tl { /Alt~< } - \tl_put_right:No \l__uftag_mc_key_properties_tl { \l__uftag_tmpa_str>~ } - }, - alttext-o .code:n = % Alt property - { - \str_set_convert:Noon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \tl_put_right:Nn \l__uftag_mc_key_properties_tl { /Alt~< } - \tl_put_right:No \l__uftag_mc_key_properties_tl { \l__uftag_tmpa_str>~ } - }, - actualtext .code:n = % ActualText property - { - \str_set_convert:Nnon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \tl_put_right:Nn \l__uftag_mc_key_properties_tl { /ActualText~< } - \tl_put_right:No \l__uftag_mc_key_properties_tl { \l__uftag_tmpa_str>~ } - }, - actualtext-o .code:n = % ActualText property - { - \str_set_convert:Noon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \tl_put_right:Nn \l__uftag_mc_key_properties_tl { /ActualText~< } - \tl_put_right:No \l__uftag_mc_key_properties_tl { \l__uftag_tmpa_str>~ } - }, - label .tl_set:N = \l__uftag_mc_key_label_tl, - artifact .code:n = { \exp_args:Nnx \keys_set:nn { uftag / mc } { artifact-bool, artifact-type=#1 } }, - artifact .default:n = {notype} - } +\cs_new:Nn \__tag_mc_handle_stash:n %1 mcidnum + { + \__tag_check_mc_used:n {#1} + \__tag_struct_kid_mc_gput_right:nn + { \g__tag_struct_stack_current_tl } + {#1} + \prop_gput:Nxx \g__tag_mc_parenttree_prop + {#1} + { \g__tag_struct_stack_current_tl } + } -\cs_new:Nn \__uftag_mc_handle_artifact:N %#1 contains the artifact type - { - \tl_if_empty:NTF #1 - { \__uftag_mc_bmc_artifact: } - { \exp_args:No\__uftag_mc_bmc_artifact:n {#1} } - } +\cs_new_protected:Nn \tag_mc_begin:n + { + \group_begin: %hm + \__tag_check_mc_if_nested: + \bool_gset_true:N \g__tag_in_mc_bool + \keys_set:nn { __tag / mc } {#1} + \bool_if:NTF \l__tag_mc_artifact_bool + { %handle artifact + \__tag_mc_handle_artifact:N \l__tag_mc_artifact_type_tl + } + { %handle mcid type + \__tag_check_mc_tag:N \l__tag_mc_key_tag_tl + \__tag_mc_handle_mcid:VV + \l__tag_mc_key_tag_tl + \l__tag_mc_key_properties_tl + \tl_if_empty:NF {\l__tag_mc_key_label_tl} + { + \__tag_mc_handle_mc_label:n { \l__tag_mc_key_label_tl } + } + \bool_if:NF \l__tag_mc_key_stash_bool + { + \__tag_mc_handle_stash:n { \int_use:N \c@g__tag_MCID_abs_int } + } + } + \group_end: + } -\cs_new:Nn \__uftag_mc_handle_mcid:nn %#1 tag, #2 properties - { - \__uftag_mc_bdc_mcid:nn {#1} {#2} - } +\cs_set_eq:NN \uftag_mc_begin:n \tag_mc_begin:n +\cs_new_protected:Nn \tag_mc_end: + { + \__tag_check_mc_if_open: + \bool_gset_false:N \g__tag_in_mc_bool + \tl_gset:Nn \g__tag_mc_key_tag_tl { } + \__tag_mc_emc: + } -% puts the absolute number of an mcid in the current structure -\cs_new:Nn \__uftag_mc_handle_stash:n %1 mcidnum - { - \__uftag_check_mc_used:n {#1} - \__uftag_struct_kid_mc_gput_right:nn - { \g__uftag_struct_stack_current_tl } - {#1} - \prop_gput:Nxx \g__uftag_mc_parenttree_prop - {#1} - { \g__uftag_struct_stack_current_tl } - } +\cs_set_eq:NN \uftag_mc_end: \tag_mc_end: -\cs_new_protected:Nn \uftag_mc_begin:n - { - \group_begin: - \__uftag_check_mc_if_nested: - \bool_gset_true:N \g__uftag_in_mc_bool - \keys_set:nn { uftag / mc } {#1} - \bool_if:NTF \l__uftag_mc_artifact_bool - { %handle artifact - \__uftag_mc_handle_artifact:N \l__uftag_mc_artifact_type_tl - } - { %handle mcid type - \__uftag_check_mc_tag:N \l__uftag_mc_key_tag_tl - \__uftag_mc_handle_mcid:nn { \l__uftag_mc_key_tag_tl }{\l__uftag_mc_key_properties_tl} - \tl_if_empty:NF {\l__uftag_mc_key_label_tl} +\cs_new_protected:Nn \tag_mc_use:n %#1: label name + { + \tl_set:Nx \l_tmpa_tl { \__tag_ref_value:enn{tagpdf-#1}{tagmcabs}{} } + \tl_if_empty:NTF\l_tmpa_tl { - \__uftag_mc_handle_mc_label:n { \l__uftag_mc_key_label_tl } + \msg_warning:nnn {tag} {mc-label-unknown} {#1} } - \bool_if:NF \l__uftag_mc_key_stash_bool - { - \__uftag_mc_handle_stash:n { \int_use:N \c@g__uftag_MCID_abs_int } - } - } - \group_end: - } - -\cs_new_protected:Nn \uftag_mc_end: - { - \__uftag_check_mc_if_open: - \bool_gset_false:N \g__uftag_in_mc_bool - \tl_gset:Nn \g__uftag_mc_key_tag_tl { } - \__uftag_mc_emc: - } + { + \prop_gput:Nxx + \g__tag_mc_parenttree_prop + { + \__tag_ref_value:enn {tagpdf-#1} {tagmcabs} {} + } + { + \g__tag_struct_stack_current_tl + } + \__tag_struct_kid_mc_gput_right:nn + { + \g__tag_struct_stack_current_tl + } + { + \__tag_ref_value:enn {tagpdf-#1} {tagmcabs} {} + } + } + } -\cs_new_protected:Nn \uftag_mc_use:n %#1: label name - { - \tl_set:Nx \l_tmpa_tl { \zref@extractdefault{tagpdf-#1}{tagmcabs}{} } - \tl_if_empty:NTF\l_tmpa_tl - { - \msg_warning:nnn {uftag} {mc-label-unknown} {#1} - } - { - \prop_gput:Nxx - \g__uftag_mc_parenttree_prop - { - \zref@extractdefault {tagpdf-#1} {tagmcabs} {} - } - { - \g__uftag_struct_stack_current_tl - } - \__uftag_struct_kid_mc_gput_right:nn - { - \g__uftag_struct_stack_current_tl - } - { - \zref@extractdefault {tagpdf-#1} {tagmcabs} {} - } - } - } +\cs_set_eq:NN \uftag_mc_use:n \tag_mc_use:n -\cs_new:Nn \__uftag_get_data_mc_tag: { \g__uftag_mc_key_tag_tl } +\cs_new:Nn \__tag_get_data_mc_tag: { \g__tag_mc_key_tag_tl } -\endinput +%% +%% +%% End of file `tagpdf-mc-code-generic.sty'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-lua.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-lua.sty index 4387d3b8085..d55366eed6b 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-lua.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-lua.sty @@ -1,280 +1,327 @@ -\ProvidesExplPackage {tagpdf-mc-code-lua} {2019/07/02} {0.61} +%% +%% This is file `tagpdf-mc-code-lua.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf-mc.dtx (with options: `luamode') +%% +%% Copyright (C) 2019 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-mc.dtx +\ProvidesExplPackage {tagpdf-mc-code-lua} {2021/02/23} {0.80} {tagpdf - mc code only for the luamode } -% the two attibutes are defined in the driver file. -% it also load the lua (as it can also contain functions needed by generic mode. -% (new) attributes for mc are local: -% \newattribute \l__uftag_mc_type_attr %the value represent the type -% \newattribute \l__uftag_mc_cnt_attr %will hold the \c@g__uftag_MCID_abs_int value -% An attribute for the current structure probably doesn't make sense as mc chunks can be used later. -% \newattribute \g__uftag_struct_type_attr %represent the current structure type. Not sure if needed -% \newattribute \g__uftag_struct_cnt_attr %will hold \c@g__uftag_struct_abs_int a cnt -% handling attribute needs a different system to number the page wise mcid's: -% a tagmcbegin ... tagmcend pair no longer surrounds exactly one mc chunk: it can be split -% at page breaks. We know the included mcid(s) only after the ship out. So for the struct-> mcid mapping we -% need to record struct -> mc-cnt (in \g__uftag_mc_parenttree_prop and/or a lua table -% and at shipout mc-cnt-> {mcid, mcid, ...} (in a table?) -% and when building the trees connect both -% key definitions are overwritten for luatex to store that data in tables -% the data for the mc are in uftag.mc[absnum] -% the fields of the table are -% tag : the type (a string) -% raw : more properties (string) -% label: a string. Do we need a way to retrieve the num from the label from lua?? -% artifact: the presence indicates an artifact, the value (string) is the type. -% kids: a array of tables {1={kid=num2,page=pagenum1}, 2={kid=num2,page=pagenum2},...}, -% this describes the chunks the mc has been split to by the traversing code -% parent: the number of the structure it is in. Needed to build the parent tree. - -% The main function which wanders through the shipout box to inject the literals. -\AtBeginDocument - { - \bool_if:NT\g_uftag_active_mc_bool - { - \AtBeginShipout - { - \directlua{uftag.func.mark_shipout ()} - } - } - } - -\prg_new_conditional:Nnn \__uftag_mc_if_in: {p,T,F,TF} - { - \int_compare:nNnTF {-2147483647}={\l__uftag_mc_type_attr} - { \prg_return_true: } - { \prg_return_false: } - } - -\prg_new_eq_conditional:NNn \uftag_mc_if_in: \__uftag_mc_if_in: {p,T,F,TF} - -% the keys -\tl_new:N \l__uftag_mc_key_tag_tl -\tl_new:N \l__uftag_mc_key_label_tl -\tl_new:N \l__uftag_mc_key_properties_tl - -\keys_define:nn { uftag / mc } - { - tag .code:n = % - {%%????????? \pdfescapename?? - \tl_set:Nx \l__uftag_mc_key_tag_tl { #1 } - \directlua - { - uftag.func.store_mc_data(\__uftag_get_mc_abs_cnt:,"tag","#1") - } - }, - raw .code:n = - { - \tl_put_right:Nx \l__uftag_mc_key_properties_tl { #1 } - \directlua - { - uftag.func.store_mc_data(\__uftag_get_mc_abs_cnt:,"raw","#1") - } - }, - alttext .code:n = % Alt property - { - \str_set_convert:Nnon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \tl_put_right:Nn \l__uftag_mc_key_properties_tl { /Alt~< } - \tl_put_right:No \l__uftag_mc_key_properties_tl { \l__uftag_tmpa_str>~ } - \directlua - { - uftag.func.store_mc_data(\__uftag_get_mc_abs_cnt:,"alt","/Alt~<\str_use:N \l__uftag_tmpa_str>") - } - }, - alttext-o .code:n = % Alt property - { - \str_set_convert:Noon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \tl_put_right:Nn \l__uftag_mc_key_properties_tl { /Alt~< } - \tl_put_right:No \l__uftag_mc_key_properties_tl { \l__uftag_tmpa_str>~ } - \directlua - { - uftag.func.store_mc_data(\__uftag_get_mc_abs_cnt:,"alt","/Alt~<\str_use:N \l__uftag_tmpa_str>") - } - }, - actualtext .code:n = % Alt property - { - \str_set_convert:Nnon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \tl_put_right:Nn \l__uftag_mc_key_properties_tl { /Alt~< } - \tl_put_right:No \l__uftag_mc_key_properties_tl { \l__uftag_tmpa_str>~ } - \directlua - { - uftag.func.store_mc_data(\__uftag_get_mc_abs_cnt:,"actualtext","/ActualText~<\str_use:N \l__uftag_tmpa_str>") - } - }, - actualtext-o .code:n = % Alt property - { - \str_set_convert:Noon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \tl_put_right:Nn \l__uftag_mc_key_properties_tl { /Alt~< } - \tl_put_right:No \l__uftag_mc_key_properties_tl { \l__uftag_tmpa_str>~ } +\hook_gput_code:nnn{begindocument}{tagpdf/mc} + { + \bool_if:NT\g__tag_active_mc_bool + { + \directlua + { + if~luatexbase.callbacktypes.pre_shipout_filter~then~ + luatexbase.add_to_callback("pre_shipout_filter", function(TAGBOX)~ + ltx.__tag.func.mark_shipout(TAGBOX)~return~true~ + end, "tagpdf")~ + end + } + \directlua + { + if~luatexbase.callbacktypes.pre_shipout_filter~then~ + token.get_next()~ + end + }\@secondoftwo\@gobble + { + \hook_gput_code:nnn{shipout/before}{tagpdf/lua} + { + \directlua + { ltx.__tag.func.mark_shipout (tex.box["ShipoutBox"]) } + } + } + } + } + +\prg_new_conditional:Nnn \__tag_mc_if_in: {p,T,F,TF} + { + \int_compare:nNnTF { -2147483647 }={ \l__tag_mc_type_attr } + { \prg_return_false: } + { \prg_return_true: } + } + +\prg_new_eq_conditional:NNn \tag_mc_if_in: \__tag_mc_if_in: {p,T,F,TF} + +\prg_new_eq_conditional:NNn \uftag_mc_if_in: \__tag_mc_if_in: {p,T,F,TF} + +\tl_new:N \l__tag_mc_key_tag_tl +\tl_new:N \l__tag_mc_key_label_tl +\tl_new:N \l__tag_mc_key_properties_tl + +\keys_define:nn { __tag / mc } + { + tag .code:n = % + {%%????????? \pdfescapename?? + \tl_set:Nx \l__tag_mc_key_tag_tl { #1 } + \directlua + { + ltx.__tag.func.store_mc_data(\__tag_get_mc_abs_cnt:,"tag","#1") + } + }, + raw .code:n = + { + \tl_put_right:Nx \l__tag_mc_key_properties_tl { #1 } + \directlua + { + ltx.__tag.func.store_mc_data(\__tag_get_mc_abs_cnt:,"raw","#1") + } + }, + alttext .code:n = % Alt property + { + \str_set_convert:Nnon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \tl_put_right:Nn \l__tag_mc_key_properties_tl { /Alt~< } + \tl_put_right:No \l__tag_mc_key_properties_tl { \l__tag_tmpa_str>~ } + \directlua + { + ltx.__tag.func.store_mc_data + ( + \__tag_get_mc_abs_cnt:,"alt","/Alt~<\str_use:N \l__tag_tmpa_str>" + ) + } + }, + alttext-o .code:n = % Alt property + { + \str_set_convert:Noon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \tl_put_right:Nn \l__tag_mc_key_properties_tl { /Alt~< } + \tl_put_right:No \l__tag_mc_key_properties_tl { \l__tag_tmpa_str>~ } + \directlua + { + ltx.__tag.func.store_mc_data + ( + \__tag_get_mc_abs_cnt:,"alt","/Alt~<\str_use:N \l__tag_tmpa_str>" + ) + } + }, + actualtext .code:n = % Alt property + { + \str_set_convert:Nnon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \tl_put_right:Nn \l__tag_mc_key_properties_tl { /Alt~< } + \tl_put_right:No \l__tag_mc_key_properties_tl { \l__tag_tmpa_str>~ } + \directlua + { + ltx.__tag.func.store_mc_data + ( + \__tag_get_mc_abs_cnt:,"actualtext","/ActualText~<\str_use:N \l__tag_tmpa_str>" + ) + } + }, + actualtext-o .code:n = % Alt property + { + \str_set_convert:Noon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \tl_put_right:Nn \l__tag_mc_key_properties_tl { /Alt~< } + \tl_put_right:No \l__tag_mc_key_properties_tl { \l__tag_tmpa_str>~ } + \directlua + { + ltx.__tag.func.store_mc_data + ( + \__tag_get_mc_abs_cnt:, + "actualtext", + "/ActualText~<\str_use:N \l__tag_tmpa_str>" + ) + } + }, + label .code:n = + { + \tl_set:Nn\l__tag_mc_key_label_tl { #1 } + \directlua + { + ltx.__tag.func.store_mc_data + ( + \__tag_get_mc_abs_cnt:,"label","#1" + ) + } + }, + __artifact-store .code:n = + { + \directlua + { + ltx.__tag.func.store_mc_data + ( + \__tag_get_mc_abs_cnt:,"artifact","#1" + ) + } + }, + artifact .code:n = + { + \exp_args:Nnx + \keys_set:nn + { __tag / mc} + { artifact-bool, artifact-type=#1, tag=Artifact } + \exp_args:Nnx + \keys_set:nn + { __tag / mc } + { __artifact-store=\l__tag_mc_artifact_type_tl } + }, + artifact .default:n = { notype } + } + + +\cs_set_protected:Npn \__tag_attribute_gset:Nn #1 #2 + { + \tex_global:D \setattribute #1 #2 + } + +\cs_set_protected:Npn \__tag_attribute_set:Nn #1 #2 + { + \setattribute #1 #2 + } + +\cs_set_protected:Npn \__tag_attribute_gunset:N #1 + { + \tex_global:D \unsetattribute #1 + } + +\cs_set_protected:Npn \__tag_attribute_unset:N #1 + { + \unsetattribute #1 + } + +\cs_new:Nn \__tag_mc_lua_set_mc_type_attr:n % #1 is a tag name + { + \__tag_attribute_set:Nn \l__tag_mc_type_attr + { + \directlua { ltx.__tag.func.output_num_from ("#1") } + } + \__tag_attribute_set:Nn \l__tag_mc_cnt_attr { \__tag_get_mc_abs_cnt: } + } + +\cs_generate_variant:Nn\__tag_mc_lua_set_mc_type_attr:n { o } + +\cs_new:Nn \__tag_mc_lua_unset_mc_type_attr: + { + \__tag_attribute_unset:N \l__tag_mc_type_attr + \__tag_attribute_unset:N \l__tag_mc_cnt_attr + } + +\cs_new:Nn \__tag_mc_insert_mcid_kids:n + { + \directlua { ltx.__tag.func.mc_insert_kids (#1,0) } + } + +\cs_new:Nn \__tag_mc_insert_mcid_single_kids:n + { + \directlua {ltx.__tag.func.mc_insert_kids (#1,1) } + } + + +\cs_new:Nn \__tag_mc_handle_stash:n %1 mcidnum + { + \__tag_check_mc_used:n { #1 } + \seq_gput_right:cn % Don't fill a lua table due to the command in the item, + % so use the kernel command + { g__tag_struct_kids_\g__tag_struct_stack_current_tl _seq } + { + \__tag_mc_insert_mcid_kids:n {#1}% + } \directlua - { - uftag.func.store_mc_data(\__uftag_get_mc_abs_cnt:,"actualtext","/ActualText~<\str_use:N \l__uftag_tmpa_str>") - } - }, - label .code:n = - { - \tl_set:Nn\l__uftag_mc_key_label_tl { #1 } - \directlua {uftag.func.store_mc_data(\__uftag_get_mc_abs_cnt:,"label","#1")} - }, - __artifact-store .code:n = - { - \directlua {uftag.func.store_mc_data(\__uftag_get_mc_abs_cnt:,"artifact","#1")} - }, - artifact .code:n = - { - \exp_args:Nnx \keys_set:nn {uftag / mc} { artifact-bool, artifact-type=#1, tag=Artifact } - \exp_args:Nnx \keys_set:nn {uftag / mc }{ __artifact-store=\l__uftag_mc_artifact_type_tl } - }, - artifact .default:n = { notype } - } - - -% attributes -% set the mc from a tag name - -\cs_set_protected:Npn \__uftag_attribute_gset:Nn #1 #2 - { - \tex_global:D \setattribute #1 #2 - } - -\cs_set_protected:Npn \__uftag_attribute_set:Nn #1 #2 - { - \setattribute #1 #2 - } - -\cs_set_protected:Npn \__uftag_attribute_gunset:N #1 - { - \tex_global:D \unsetattribute #1 - } - -\cs_set_protected:Npn \__uftag_attribute_unset:N #1 - { - \unsetattribute #1 - } - - -\cs_new:Nn \__uftag_mc_lua_set_mc_type_attr:n % #1 is a tag name - { - \__uftag_attribute_set:Nn \l__uftag_mc_type_attr { \directlua {uftag.func.output_num_from ("#1") } } - \__uftag_attribute_set:Nn \l__uftag_mc_cnt_attr { \__uftag_get_mc_abs_cnt: } - } - -\cs_generate_variant:Nn\__uftag_mc_lua_set_mc_type_attr:n { o } - -\cs_new:Nn \__uftag_mc_lua_unset_mc_type_attr: - { - \__uftag_attribute_unset:N \l__uftag_mc_type_attr - \__uftag_attribute_unset:N \l__uftag_mc_cnt_attr - } - - - -%This command will in the finish code replace the dummy for a mc by the real mcid kids -%we need a variant for the case that it is the only kid, to get the array right -\cs_new:Nn \__uftag_mc_insert_mcid_kids:n - { - \directlua {uftag.func.mc_insert_kids (#1,0) } - } - -\cs_new:Nn \__uftag_mc_insert_mcid_single_kids:n - { - \directlua {uftag.func.mc_insert_kids (#1,1) } - } - - -% we need to pass the info if the kids are alone or already in an array -% so we add a second argument, which should == 1 if the kids are single - - -% puts an mcid absolute number in the current structure -\cs_new:Nn \__uftag_mc_handle_stash:n %1 mcidnum - { - \__uftag_check_mc_used:n { #1 } - \seq_gput_right:cn % Don't fill a lua table due to the command in the item, so the kernel command - { g__uftag_struct_kids_\g__uftag_struct_stack_current_tl _seq } - { - \__uftag_mc_insert_mcid_kids:n {#1}% - } - \directlua - { - uftag.func.store_struct_mcabs(\g__uftag_struct_stack_current_tl,#1) - } - \prop_gput:Nxx - \g__uftag_mc_parenttree_prop - { #1 } - { \g__uftag_struct_stack_current_tl } - } - -\cs_generate_variant:Nn \__uftag_mc_handle_stash:n { o } - -\cs_new_protected:Nn \uftag_mc_begin:n - { - %\group_begin: - %\__uftag_check_mc_if_nested: - %\bool_gset_true:N \g__uftag_in_mc_bool - \int_gincr:N \c@g__uftag_MCID_abs_int - \tl_clear:N\l__uftag_mc_key_properties_tl - \keys_set:nn { uftag / mc }{ label={}, #1 } - %check that a tag or artifact has been used - \__uftag_check_mc_tag:N \l__uftag_mc_key_tag_tl - %set the attributes: - \__uftag_mc_lua_set_mc_type_attr:o { \l__uftag_mc_key_tag_tl } - \bool_if:NF \l__uftag_mc_artifact_bool - { % store the absolute num name in a label: - \tl_if_empty:NF {\l__uftag_mc_key_label_tl} - { - \__uftag_mc_handle_mc_label:n { \l__uftag_mc_key_label_tl } - } - % if not stashed record the absolute number - \bool_if:NF \l__uftag_mc_key_stash_bool { - \exp_args:Nx \__uftag_mc_handle_stash:n { \__uftag_get_mc_abs_cnt: } + ltx.__tag.func.store_struct_mcabs + ( + \g__tag_struct_stack_current_tl,#1 + ) } - } - \bool_set_false:N\l__uftag_mc_artifact_bool - %\group_end: - } - -\cs_new_protected:Nn \uftag_mc_end: - { - %\__uftag_check_mc_if_open: - %\bool_gset_false:N \g__uftag_in_mc_bool - \__uftag_mc_lua_unset_mc_type_attr: - \tl_set:Nn \l__uftag_mc_key_tag_tl { } - } - -\cs_new_protected:Nn \uftag_mc_use:n %#1: label name - { - \tl_set:Nx \l_tmpa_tl { \zref@extractdefault{tagpdf-#1}{tagmcabs}{} } - \tl_if_empty:NTF\l_tmpa_tl - { - \msg_warning:nnn {uftag} {mc-label-unknown} { #1 } - } - { - \__uftag_mc_handle_stash:o { \l_tmpa_tl } - } - } - -\cs_new:Nn \__uftag_get_data_mc_tag: { \l__uftag_mc_key_tag_tl } + \prop_gput:Nxx + \g__tag_mc_parenttree_prop + { #1 } + { \g__tag_struct_stack_current_tl } + } + +\cs_generate_variant:Nn \__tag_mc_handle_stash:n { o } + +\cs_new_protected:Nn \tag_mc_begin:n + { + %\group_begin: + %\__tag_check_mc_if_nested: + %\bool_gset_true:N \g__tag_in_mc_bool + \bool_set_false:N\l__tag_mc_artifact_bool + \int_gincr:N \c@g__tag_MCID_abs_int + \tl_clear:N \l__tag_mc_key_properties_tl + \keys_set:nn { __tag / mc }{ label={}, #1 } + %check that a tag or artifact has been used + \__tag_check_mc_tag:N \l__tag_mc_key_tag_tl + %set the attributes: + \__tag_mc_lua_set_mc_type_attr:o { \l__tag_mc_key_tag_tl } + \bool_if:NF \l__tag_mc_artifact_bool + { % store the absolute num name in a label: + \tl_if_empty:NF {\l__tag_mc_key_label_tl} + { + \__tag_mc_handle_mc_label:n { \l__tag_mc_key_label_tl } + } + % if not stashed record the absolute number + \bool_if:NF \l__tag_mc_key_stash_bool + { + \exp_args:Nx \__tag_mc_handle_stash:n { \__tag_get_mc_abs_cnt: } + } + } + %\bool_set_false:N\l__tag_mc_artifact_bool + %\group_end: + } + +\cs_set_eq:NN \uftag_mc_begin:n \tag_mc_begin:n + +\cs_new_protected:Nn \tag_mc_end: + { + %\__tag_check_mc_if_open: + %\bool_gset_false:N \g__tag_in_mc_bool + \bool_set_false:N\l__tag_mc_artifact_bool + \__tag_mc_lua_unset_mc_type_attr: + \tl_set:Nn \l__tag_mc_key_tag_tl { } + } + +\cs_set_eq:NN \uftag_mc_end: \tag_mc_end: + +\cs_new_protected:Nn \tag_mc_use:n %#1: label name + { + \tl_set:Nx \l_tmpa_tl { \__tag_ref_value:enn{tagpdf-#1}{tagmcabs}{} } + \tl_if_empty:NTF\l_tmpa_tl + { + \msg_warning:nnn {tag} {mc-label-unknown} { #1 } + } + { + \__tag_mc_handle_stash:o { \l_tmpa_tl } + } + } +\cs_set_eq:NN \uftag_mc_use:n \tag_mc_use:n -\endinput +\cs_new:Nn \__tag_get_data_mc_tag: { \l__tag_mc_key_tag_tl } +%% +%% +%% End of file `tagpdf-mc-code-lua.sty'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-shared.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-shared.sty index b9bbe29eb36..49cfbaf69df 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-shared.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-mc-code-shared.sty @@ -1,47 +1,86 @@ -\ProvidesExplPackage {tagpdf-mc-code-shared} {2019/07/02} {0.61} - {part of tagpdf - code related to marking chunks - code shared by generic and luamode } - -% I use a latex counter for the absolute count, so that it is added to -% \cl@@ckpt and restored e.g. in tabulars and align -% \int_new:N \c@g__uftag_MCID_int and -% \tl_put_right:Nn\cl@@ckpt{\@elt{g_uf_test_int}} -% would work too, but as the name is not expl3 then too, why bother? -% the absolute counter can be used to label and to check if the page -% counter needs a reset. - -\newcounter { g__uftag_MCID_abs_int } -\cs_new:Nn \__uftag_get_mc_abs_cnt: { \int_use:N \c@g__uftag_MCID_abs_int } - -% tagmcabs is the label name of the absolute count which is used to identify the chunk -\zref@newprop {tagmcabs} [0] { \int_use:N \c@g__uftag_MCID_abs_int } -\zref@addprop {uftagzrl} {tagmcabs} -\zref@addprop {LastPage} {tagmcabs} - -%stores labels of mcid. -\cs_new:Nn \__uftag_mc_handle_mc_label:n - { - \zref@labelbylist{tagpdf-#1}{uftagzrl} - } +%% +%% This is file `tagpdf-mc-code-shared.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf-mc.dtx (with options: `shared') +%% +%% Copyright (C) 2019 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-mc.dtx +\ProvidesExplPackage {tagpdf-mc-code-shared} {2021/02/23} {0.80} + {part of tagpdf - code related to marking chunks - + code shared by generic and luamode } + +\newcounter { g__tag_MCID_abs_int } +\cs_new:Nn \__tag_get_mc_abs_cnt: { \int_use:N \c@g__tag_MCID_abs_int } + + +\cs_new:Nn \__tag_mc_handle_mc_label:n + { + \__tag_ref_label:en{tagpdf-#1}{mc} + } -% will hold the structure numbers for the parenttree -% key: absolute number of the mc (tagmcabs) -% value: the structure number the mc is in -\__uftag_prop_new:N \g__uftag_mc_parenttree_prop +\__tag_prop_new:N \g__tag_mc_parenttree_prop -%shared keys -%the rest are in the splitted code -\tl_new:N \l__uftag_mc_artifact_type_tl +\tl_new:N \l__tag_mc_artifact_type_tl -\keys_define:nn { uftag / mc } +\keys_define:nn { __tag / mc } + { + stash .bool_set:N = \l__tag_mc_key_stash_bool, + artifact-bool .bool_set:N = \l__tag_mc_artifact_bool, + artifact-type .choice:, + artifact-type / pagination .code:n = + { + \tl_set:Nn \l__tag_mc_artifact_type_tl { Pagination } + }, + artifact-type / layout .code:n = + { + \tl_set:Nn \l__tag_mc_artifact_type_tl { Layout } + }, + artifact-type / page .code:n = + { + \tl_set:Nn \l__tag_mc_artifact_type_tl { Page } + }, + artifact-type / background .code:n = + { + \tl_set:Nn \l__tag_mc_artifact_type_tl { Background } + }, + artifact-type / notype .code:n = + { + \tl_set:Nn \l__tag_mc_artifact_type_tl {} + }, + artifact-type / .code:n = + { + \tl_set:Nn \l__tag_mc_artifact_type_tl {} + }, + } + +\cs_new_protected:Npn \tag_mc_artifact_group_begin:n #1 { - stash .bool_set:N = \l__uftag_mc_key_stash_bool, - artifact-bool .bool_set:N = \l__uftag_mc_artifact_bool, - artifact-type .choice:, - artifact-type / pagination .code:n = {\tl_set:Nn \l__uftag_mc_artifact_type_tl { Pagination }}, - artifact-type / layout .code:n = {\tl_set:Nn \l__uftag_mc_artifact_type_tl { Layout }}, - artifact-type / page .code:n = {\tl_set:Nn \l__uftag_mc_artifact_type_tl { Page }}, - artifact-type / background .code:n = {\tl_set:Nn \l__uftag_mc_artifact_type_tl { Background }}, - artifact-type / notype .code:n = {\tl_set:Nn \l__uftag_mc_artifact_type_tl {}}, + \tag_mc_begin:n {artifact=#1} + \tag_stop_group_begin: } -\endinput +\cs_new_protected:Npn \tag_mc_artifact_group_end: + { + \tag_stop_group_end: + \tag_mc_end: + } + +\int_new:N \g__tag_MCID_tmp_bypage_int + +%% +%% +%% End of file `tagpdf-mc-code-shared.sty'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-pdftex.def b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-pdftex.def index 55e9e0c3b8a..ab40b3de3a0 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-pdftex.def +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-pdftex.def @@ -1,128 +1,47 @@ -\ProvidesExplFile {tagpdf-pdftex.def} {2019/07/02} {0.61} +%% +%% This is file `tagpdf-pdftex.def', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf-backend.dtx (with options: `pdftex') +%% +%% Copyright (C) 2019 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-backend.dtx +\ProvidesExplFile {tagpdf-pdftex.def} {2021/02/23} {0.80} {tagpdf~driver~for~pdftex} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% driver (pdflatex) commands %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% these should be in expl3!!! -\cs_new:Nn \__uftag_pdf_startlink:{ \pdfstartlink } -\cs_new:Nn \__uftag_pdf_endlink: { \pdfendlink } -\cs_new:Nn \__uftag_pdf_lastlink: { \pdflastlink } -\cs_new:Nn \__uftag_pdf_catalog: { \pdfcatalog } +\cs_set_eq:NN \__tag_prop_new:N \prop_new:N +\cs_set_eq:NN \__tag_seq_new:N \seq_new:N -% needed for \str_set_convert:Nnon -\tl_new:N \g__uftag_inputencoding_tl -\tl_gset:Nn \g__uftag_inputencoding_tl {utf8} +\cs_set_eq:NN \__tag_prop_gput:Nnn \prop_gput:Nnn +\cs_set_eq:NN \__tag_seq_gput_right:Nn \seq_gput_right:Nn -%literal -\cs_new:Nn \__uftag_pdfliteral_page:n { \__uftag_tex_pdfliteral:D page { #1} } -\cs_new:Nn \__uftag_pdfcatalog:n { \__uftag_tex_pdfcatalog:D { #1 } } +\cs_set_eq:NN \__tag_seq_item:cn \seq_item:cn -% reserve an object num and store the number -\cs_new:Nn \__uftag_pdfreserveobjnum:N % #1 = macro name to be populated with object number - { - \__uftag_tex_pdfobj:D reserveobjnum - \tl_set:Nx #1 { \int_use:N \__uftag_tex_pdflastobj:D }% - } +\cs_set_eq:NN \__tag_prop_item:cn \prop_item:cn -% add content to an object num stored in a macro -\cs_new:Nn \__uftag_pdfuseobjnum:Nn - { - % #1 = macro containing the object number - % #2 = object contents, as valid PDF - % should #2 be filtered through \pdfstringdef ??? - \__uftag_tex_immediate:D \__uftag_tex_pdfobj:D useobjnum~#1~{#2}% - } +\cs_set_eq:NN \__tag_seq_show:N \seq_show:N -\cs_new:Nn \__uftag_pdfuseobjnum:nn - { - % #1 = a number the object number - % #2 = object contents, as valid PDF - % should #2 be filtered through \pdfstringdef ??? - \__uftag_check_record_pdfobj_num:n {#1} - \__uftag_tex_immediate:D \__uftag_tex_pdfobj:D useobjnum~#1~{#2}% - } +\cs_set_eq:NN \__tag_prop_show:N \prop_show:N -% obj num of the dictionary for a page: -% the page count starts by 1 -% pages can referenced before they are actually created -% no error if the page later doesn't exist -\cs_new:Nn \__uftag_store_pdfpageref:Nn - { - % #1 = macro name to be populated with current page object number - % #2 = number or counter identifying the required page - \tl_set:Nx #1 { \__uftag_tex_pdfpageref:D #2}% - } - -% a global version of the command -\cs_new:Nn \__uftag_gstore_pdfpageref:Nn - { - \tl_gset:Nx #1 { \__uftag_tex_pdfpageref:D #2}% - } - -\cs_new:Nn \__uftag_pdfobj:Nn - { - % #1 = macro name to refer to this object - % #2 = object contents, as valid PDF - % should #2 be filtered through \pdfstringdef ??? - \__uftag_tex_immediate:D \__uftag_tex_pdfobj:D { #2 } - \tl_set:Nx #1 {\int_use:N \__uftag_tex_pdflastobj:D }% - } - -% pdfpage**s**attr: for all pages -%% is global needed? Yes. Without it the setting is lost if issued in a group -% -\cs_new:Nn \__uftag_gset_pdfpagesattr:n - { - \__uftag_tex_global:D \__uftag_tex_pdfpagesattr:D { #1 } - } - -\cs_new:Nn \__uftag_gadd_pdfpagesattr:n - { - \exp_args:No \__uftag_gset_pdfpagesattr:n { \__uftag_tex_the:D \__uftag_tex_pdfpagesattr:D #1 } - } - -% pdfpageattr for one page -% I must avoid to overwrite other entries, -% And I must avoid to add more and more /StructParens -% do we need an immediate version?? -\cs_new:Nn \__uftag_gset_pdfpageattr:n - { - \__uftag_tex_global:D \__uftag_tex_pdfpageattr:D { #1 } - } - -\cs_new:Nn \__uftag_gadd_pdfpageattr:n - { - \exp_args:No \__uftag_gset_pdfpageattr:n { \__uftag_tex_the:D \__uftag_tex_pdfpageattr:D #1} - } - -\cs_new:Nn \__uftag_get_pdfpageattr:N - { - \tl_set:No #1 { \__uftag_tex_the:D \__uftag_tex_pdfpageattr:D } - } - - -% These commands are only aliases for pdflatex but are defined differently with luatex -% to get also lua tables. -\cs_set_eq:NN \__uftag_prop_new:N \prop_new:N - -\cs_set_eq:NN \__uftag_seq_new:N \seq_new:N - -\cs_set_eq:NN \__uftag_prop_gput:Nnn \prop_gput:Nnn - -\cs_set_eq:NN \__uftag_seq_gput_right:Nn \seq_gput_right:Nn - -\cs_set_eq:NN \__uftag_seq_item:cn \seq_item:cn - -\cs_set_eq:NN \__uftag_prop_item:cn \prop_item:cn - -\cs_set_eq:NN \__uftag_seq_show:N \seq_show:N - -\cs_set_eq:NN \__uftag_prop_show:N \prop_show:N - - - -\endinput +%% +%% +%% End of file `tagpdf-pdftex.def'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-roles-code.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-roles-code.sty index 212b216c79d..a205e057e36 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-roles-code.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-roles-code.sty @@ -1,126 +1,142 @@ -\ProvidesExplPackage {tagpdf-roles-code} {2019/07/02} {0.61} +%% +%% This is file `tagpdf-roles-code.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf-roles.dtx (with options: `roles') +%% +%% Copyright (C) 2019 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-roles.dtx +\ProvidesExplPackage {tagpdf-roles-code} {2021/02/23} {0.80} {part of tagpdf - code related to roles and structure names} -\__uftag_seq_new:N \g__uftag_role_tags_seq %to get names from numbers -\__uftag_prop_new:N \g__uftag_role_tags_prop %to get numbers from names +\__tag_seq_new:N \g__tag_role_tags_seq %to get names from numbers +\__tag_prop_new:N \g__tag_role_tags_prop %to get numbers from names -%The list of standard adobe tags. -\clist_const:Nn \c__uftag_role_sttags_clist - {%possible root elements - Document, %A complete document. This is the root element of any structure tree containing - %multiple parts or multiple articles. - Part, %A large-scale division of a document. - Art, %A relatively self-contained body of text constituting a single narrative or exposition - %subelements - Sect, %A container for grouping related content elements. - Div, %A generic block-level element or group of elements - BlockQuote, %A portion of text consisting of one or more paragraphs attributed to someone other - %than the author of the surrounding text. - Caption, %A brief portion of text describing a table or figure. - TOC, %A list made up of table of contents item entries (structure tag TOCI; see below) - %and/or other nested table of contents entries - TOCI, %An individual member of a table of contents. This entry's children can be any of - %the following structure tags: - %Lbl,Reference,NonStruct,P,TOC - Index, - NonStruct, %probably not needed - H, - H1, - H2, - H3, - H4, - H5, - H6, - P, - L, %list - LI, %list item (around label and list item body) - Lbl, %list label - LBody, %list item body - Table, - TR, %table row - TH, %table header cell - TD, %table data cell - THead, %table header (n rows) - TBody, %table rows - TFoot, %table footer - Span, %generic inline marker - Quote, %inline quote - Note, % footnote, endnote. Lbl can be child - Reference, % A citation to content elsewhere in the document. - BibEntry, %bibentry - Code, % - Link, % - Annot, - Figure, - Formula, - Form, - Artifact - } +\clist_const:Nn \c__tag_role_sttags_clist + {%possible root elements + Document, %A complete document. This is the root element of any structure tree containing + %multiple parts or multiple articles. + Part, %A large-scale division of a document. + Art, %A relatively self-contained body of text constituting a single narrative or exposition + %subelements + Sect, %A container for grouping related content elements. + Div, %A generic block-level element or group of elements + BlockQuote, %A portion of text consisting of one or more paragraphs attributed to someone other + %than the author of the surrounding text. + Caption, %A brief portion of text describing a table or figure. + TOC, %A list made up of table of contents item entries (structure tag TOCI; see below) + %and/or other nested table of contents entries + TOCI, %An individual member of a table of contents. This entry's children can be any of + %the following structure tags: + %Lbl,Reference,NonStruct,P,TOC + Index, + NonStruct, %probably not needed + H, + H1, + H2, + H3, + H4, + H5, + H6, + P, + L, %list + LI, %list item (around label and list item body) + Lbl, %list label + LBody, %list item body + Table, + TR, %table row + TH, %table header cell + TD, %table data cell + THead, %table header (n rows) + TBody, %table rows + TFoot, %table footer + Span, %generic inline marker + Quote, %inline quote + Note, % footnote, endnote. Lbl can be child + Reference, % A citation to content elsewhere in the document. + BibEntry, %bibentry + Code, % + Link, % + Annot, + Figure, + Formula, + Form, + Artifact + } -% get tag name from number: \seq_item:Nn \g__uftag_role_tags_seq { n } -%\seq_gset_from_clist:NN \g__uftag_role_tags_seq \c__uftag_role_tags_clist -\clist_map_inline:Nn \c__uftag_role_sttags_clist - { - \__uftag_seq_gput_right:Nn \g__uftag_role_tags_seq { #1 } - } +\clist_map_inline:Nn \c__tag_role_sttags_clist + { + \__tag_seq_gput_right:Nn \g__tag_role_tags_seq { #1 } + } +\int_step_inline:nnnn { 1 }{ 1 }{ \seq_count:N \g__tag_role_tags_seq } + { + \__tag_prop_gput:Nxn \g__tag_role_tags_prop + { + \seq_item:Nn \g__tag_role_tags_seq { #1 } + } + { #1 } + } -% get tag number from name: \prop_item:Nn \g__uftag_role_tags_prop { name } -\int_step_inline:nnnn { 1 }{ 1 }{ \seq_count:N \g__uftag_role_tags_seq } - { - \__uftag_prop_gput:Nxn \g__uftag_role_tags_prop - { - \seq_item:Nn \g__uftag_role_tags_seq { #1 } - } - { #1 } - } +\cs_new:Nn \__tag_role_get_tag_from_index:nn + { + \__tag_seq_item:cn { #1_seq } { #2 } + } -\cs_new:Nn \__uftag_role_get_tag_from_index:nn - { - \__uftag_seq_item:cn { #1_seq } { #2 } - } +\cs_new:Nn \__tag_role_get_index_from_tag:nn + { + \__tag_prop_item:cn { #1_prop } { #2 } + } -\cs_new:Nn \__uftag_role_get_index_from_tag:nn - { - \__uftag_prop_item:cn { #1_prop } { #2 } - } -% new tags and the rolemap +\__tag_prop_new:N \g__tag_role_rolemap_prop -\__uftag_prop_new:N \g__uftag_role_rolemap_prop +\cs_new_protected:Nn \__tag_role_add_tag:nn %new name, reference to old + { + \__tag_seq_gput_right:Nn \g__tag_role_tags_seq { #1 } + \__tag_prop_gput:Nnx \g__tag_role_tags_prop { #1 } + { + \seq_count:N \g__tag_role_tags_seq + } + \__tag_check_add_tag_role:nn {#1}{#2} + \tl_if_empty:nF { #2 } + { + \__tag_prop_gput:Nnn \g__tag_role_rolemap_prop + { #1 } { #2 } + } + } -\cs_new:Nn \__uftag_role_add_tag:nn %new name, reference to old - { - \__uftag_seq_gput_right:Nn \g__uftag_role_tags_seq { #1 } - \__uftag_prop_gput:Nnx \g__uftag_role_tags_prop { #1 } - { - \seq_count:N \g__uftag_role_tags_seq - } - \__uftag_check_add_tag_role:nn {#1}{#2} - \tl_if_empty:nF { #2 } - { - \__uftag_prop_gput:Nnn \g__uftag_role_rolemap_prop - { #1 } { #2 } - } - } +\cs_generate_variant:Nn \__tag_role_add_tag:nn {xx} -\cs_generate_variant:Nn \__uftag_role_add_tag:nn {xx} - -\keys_define:nn { uftag / setup } - { - add-new-tag .code:n = - { - \seq_set_split:Nnn \l_tmpa_seq { / } {#1/} - \__uftag_role_add_tag:xx - { - \seq_item:Nn \l_tmpa_seq {1} - } +\keys_define:nn { __tag / setup } + { + add-new-tag .code:n = { - \seq_item:Nn \l_tmpa_seq {2} + \seq_set_split:Nnn \l_tmpa_seq { / } {#1/} + \__tag_role_add_tag:xx + { + \seq_item:Nn \l_tmpa_seq {1} + } + { + \seq_item:Nn \l_tmpa_seq {2} + } } - } - } - + } -\endinput +%% +%% +%% End of file `tagpdf-roles-code.sty'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-space-code.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-space-code.sty index c47da0e73d4..bbfee64e8a3 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-space-code.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-space-code.sty @@ -1,45 +1,79 @@ -\ProvidesExplPackage {tagpdf-space-code} {2019/07/02} {0.61} +%% +%% This is file `tagpdf-space-code.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf-space.dtx (with options: `space') +%% +%% Copyright (C) 2019 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-space.dtx +\ProvidesExplPackage {tagpdf-space-code} {2021/02/23} {0.80} {part of tagpdf - code related to real space chars} -% luatex uses an attribute (declared in the driver file) and some luacode in tagpdf.lua -% perhaps I will split the code by engine in the future \sys_if_engine_pdftex:T -{ - \pdfglyphtounicode{space}{0020} - \keys_define:nn { uftag / setup } { - interwordspace .choices:nn = { true, on } { \pdfinterwordspaceon }, - interwordspace .choices:nn = { false, off }{ \pdfinterwordspaceon }, - show-spaces .bool_set:N = \l__uftag_showspaces_bool + \pdfglyphtounicode{space}{0020} + \keys_define:nn { __tag / setup } + { + interwordspace .choices:nn = { true, on } { \pdfinterwordspaceon }, + interwordspace .choices:nn = { false, off }{ \pdfinterwordspaceon }, + show-spaces .bool_set:N = \l__tag_showspaces_bool + } } -} - - \sys_if_engine_luatex:T -{ - \keys_define:nn { uftag / setup } { - interwordspace .choices:nn = { true, on } - { \directlua{uftag.func.markspaceon()} }, + \keys_define:nn { __tag / setup } + { + interwordspace .choices:nn = + { true, on } + { \directlua{ltx.__tag.func.markspaceon()} }, + interwordspace .choices:nn = + { false, off } + {\directlua{ltx.__tag.func.markspaceoff()} }, + show-spaces .choice:, + show-spaces / true .code:n = + {\directlua{ltx.__tag.trace.showspaces=true}}, + show-spaces / false .code:n = + {\directlua{ltx.__tag.trace.showspaces=nil}}, + show-spaces .default:n = true + } - interwordspace .choices:nn = { false, off } - {\directlua{uftag.func.markspaceoff()} }, - show-spaces .choice:, - show-spaces / true .code:n = {\directlua{uftag.trace.showspaces=true}}, - show-spaces / false .code:n = {\directlua{uftag.trace.showspaces=nil}}, - show-spaces .default:n = true + \cs_new_protected:Nn \__tag_fakespace: + { + \group_begin: + \setattribute\g__tag_interwordspace_attr{1} + \setattribute\g__tag_interwordfont_attr + { + \directlua{tex.print(\the\catcodetable@latex, font.current())} + } + \skip_horizontal:n{\c_zero_skip} + \group_end: + } } - \cs_new_protected:Nn \__uftag_fakespace: + +\sys_if_engine_xetex:T { - \group_begin: - \setattribute\g__uftag_interwordspace_attr{1} - \setattribute\g__uftag_interwordfont_attr{\directlua{tex.print(\the\catcodetable@latex, font.current())}} - \skip_horizontal:n{\c_zero_skip} - \group_end: + \keys_define:nn { __tag / setup } + { + interwordspace .choices:nn = { true, on } { \msg_warning:nnn {tag}{sys-no-interwordspace}{xetex} }, + interwordspace .choices:nn = { false, off }{ \msg_warning:nnn {tag}{sys-no-interwordspace}{xetex} }, + show-spaces .bool_set:N = \l__tag_showspaces_bool + } } -} - - -\endinput +%% +%% +%% End of file `tagpdf-space-code.sty'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-struct-code.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-struct-code.sty index 2096a937fc9..8fedc841e17 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-struct-code.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-struct-code.sty @@ -1,523 +1,623 @@ -\ProvidesExplPackage {tagpdf-struct-code} {2019/07/02} {0.61} +%% +%% This is file `tagpdf-struct-code.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf-struct.dtx (with options: `struct') +%% +%% Copyright (C) 2019 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-struct.dtx +\ProvidesExplPackage {tagpdf-struct-code} {2021/02/23} {0.80} {part of tagpdf - code related to storing structure} -% I will use a latex counter for the structure count -% to have a chance to avoid double structures in align etc -\newcounter { g__uftag_struct_abs_int } -\int_gzero:N \c@g__uftag_struct_abs_int +\newcounter { g__tag_struct_abs_int } +\int_gzero:N \c@g__tag_struct_abs_int -\zref@newprop {tagstruct} [0] { \int_use:N \c@g__uftag_struct_abs_int } -\zref@newlist {uftagzrlstruct} -\zref@addprop {uftagzrlstruct}{tagstruct} -% a sequence stores structnum -> the obj numbers -% to allow easy mapping over the structures +\__tag_seq_new:N \g__tag_struct_objR_seq -\__uftag_seq_new:N \g__uftag_struct_objR_seq +\seq_new:N \g__tag_struct_stack_seq +\seq_gpush:Nn \g__tag_struct_stack_seq {0} -% a sequence for the structure stack. When a sequence is opened it's number is put on the stack. -\seq_new:N \g__uftag_struct_stack_seq -\seq_gpush:Nn \g__uftag_struct_stack_seq {0} +\tl_new:N \l__tag_struct_stack_parent_tmp_tl +\tl_new:N \g__tag_struct_stack_current_tl -%this variables will hold the top entry and the parent on the stack -\tl_new:N \l__uftag_struct_stack_parent_tmp_tl -\tl_new:N \g__uftag_struct_stack_current_tl -% I need at least one structure: the StructTreeRoot -% normally it should have only one kid, e.g. the document element. -% The data of the StructTreeRoot and the StructElem are in properties: -% \g__uftag_struct_0_prop for the root -% \g__uftag_struct_N_prop, N >=1 -% they have all the keys -% objnum - number, -% Type - StructTreeRoot or StructElem -% num - number (identical to the num in the name, or 0 for the root) -% and the keys from the two following lists -% (the root has a special set of properties). -% the values of the prop should be already escaped properly -% when the entries are created (title,lange,alt,E,actualtext) +\seq_const_from_clist:Nn \c__tag_struct_StructTreeRoot_entries_seq + {%p. 857/858 + Type, % always /StructTreeRoot + K, % kid, dictionary or array of dictionaries + IDTree, % currently unused + ParentTree, % required,obj ref to the parent tree + ParentTreeNextKey, %optional + RoleMap, + ClassMap + } +\seq_const_from_clist:Nn \c__tag_struct_StructElem_entries_seq + {%p 858 f + Type, %always /StructElem + S, %tag/type + P, %parent + ID, %optional + Ref, %optional, pdf 2.0 Use? + Pg, %obj num of starting page, optional + K, %kids + A, %attributes, probably unused + C, %class "" + %R, + T, %title, value in () or <> + Lang, %language + Alt, % value in () or <> + E, %abreviation + ActualText, + AF, %pdf 2.0, array of dict, associated files + NS, %pdf 2.0, dict, namespace + PhoneticAlphabet, %pdf 2.0 + Phoneme %pdf 2.0 + } -\seq_const_from_clist:Nn \c__uftag_struct_StructTreeRoot_entries_seq - {%p. 857/858 - Type, % always /StructTreeRoot - K, % kid, dictionary or array of dictionaries - IDTree, % currently unused - ParentTree, % required,obj ref to the parent tree - ParentTreeNextKey, %optional - RoleMap, - ClassMap - } -\seq_const_from_clist:Nn \c__uftag_struct_StructElem_entries_seq - {%p 858 f - Type, %always /StructElem - S, %tag/type - P, %parent - ID, %optional - Pg, %obj num of starting page, optional - K, %kids - A, %attributes, probably unused - C, %class "" - %R, - T, %title, value in () or <> - Lang, %language - Alt, % value in () or <> - E, %abreviation - ActualText +\cs_new:Nn \__tag_struct_output_prop_aux:nn %#1 num, #2 key + { + \prop_if_in:cnT + { g__tag_struct_#1_prop } + { #2 } + { + \c_space_tl/#2~ \prop_item:cn{ g__tag_struct_#1_prop } { #2 } + } } -% I need an output handler for each prop, to get expandable output -% see https://tex.stackexchange.com/questions/424208/expandable-version-of-a-expl3-command/424213#424213 - -\cs_new:Nn \__uftag_struct_output_prop_aux:nn %#1 num, #2 key - { - \prop_if_in:cnT - { g__uftag_struct_#1_prop } - { #2 } - { - \c_space_tl/#2~ \prop_item:cn{ g__uftag_struct_#1_prop } { #2 } - } - } +\cs_new:Nn \__tag_new_output_prop_handler:n + { + \cs_new:cn { __tag_struct_output_prop_#1:n } + { + \__tag_struct_output_prop_aux:nn {#1}{##1} + } + } -\cs_new:Nn \__uftag_new_output_prop_handler:n - { - \cs_new:cn { __uftag_struct_output_prop_#1:n } - { - \__uftag_struct_output_prop_aux:nn {#1}{##1} - } - } +\__tag_prop_new:c { g__tag_struct_0_prop } +\__tag_new_output_prop_handler:n {0} +\tl_gset:Nn \g__tag_struct_stack_current_tl {0} +\__tag_seq_new:c { g__tag_struct_kids_0_seq } -% the first one, the StructTreeRoot is special, so -% created manually: -\__uftag_prop_new:c { g__uftag_struct_0_prop } -\__uftag_new_output_prop_handler:n {0} -\tl_gset:Nn \g__uftag_struct_stack_current_tl {0} -\__uftag_seq_new:c { g__uftag_struct_kids_0_seq} +\__tag_prop_gput:cno + { g__tag_struct_0_prop } + { objref} + { \pdf_object_ref:n { c__tag_struct_0_obj } } -\__uftag_prop_gput:cno - { g__uftag_struct_0_prop } - { objnum} - { \c_uftag_tree_obj_structtreeroot_tl } +\__tag_prop_gput:cno + { g__tag_struct_0_prop } + { Type } + { /StructTreeRoot } -\__uftag_prop_gput:cno - { g__uftag_struct_0_prop } - { Type } - { /StructTreeRoot } +\__tag_prop_gput:cnx + { g__tag_struct_0_prop } + { ParentTree } + { \pdf_object_ref:n { c__tag_tree_parenttree_obj } } -% the constants are defined in the tree code. -\__uftag_prop_gput:cnx - { g__uftag_struct_0_prop } - { ParentTree } - { \c__uftag_tree_obj_parenttree_tl\c_space_tl 0\c_space_tl R } +\__tag_prop_gput:cnx + { g__tag_struct_0_prop } + { RoleMap } + { \pdf_object_ref:n { c__tag_tree_rolemap_obj } } -\__uftag_prop_gput:cnx - { g__uftag_struct_0_prop } - { RoleMap } - { \c__uftag_tree_obj_rolemap_tl\c_space_tl 0\c_space_tl R } +\__tag_prop_gput:cno + { g__tag_struct_0_prop } + { entries } + { StructTreeRoot } -\__uftag_prop_gput:cno - { g__uftag_struct_0_prop } - { entries } - { StructTreeRoot } +\__tag_prop_gput:cno + { g__tag_struct_0_prop } + { num } + { 0 } -\__uftag_prop_gput:cno - { g__uftag_struct_0_prop } - { num } - { 0 } -% commands to store the kids -% I don't compare the page objects number yet, but always add the /Pg key, perhaps later +\cs_new:Nn \__tag_struct_kid_mc_gput_right:nn %#1 structure num, #2 MCID absnum% + { + %\__tag_store_pdfpageref:Nn \l_tmpa_tl { \__tag_ref_value:enn{mcid-#2}{tagabspage}{1} } + \__tag_seq_gput_right:cx + { g__tag_struct_kids_#1_seq } + { + << + /Type \c_space_tl /MCR \c_space_tl + /Pg %\c_space_tl \l_tmpa_tl \c_space_tl 0 \c_space_tl R \c_space_tl + \c_space_tl + \pdf_pageobject_ref:n { \__tag_ref_value:enn{mcid-#2}{tagabspage}{1} } + /MCID \c_space_tl \__tag_ref_value:enn{mcid-#2}{tagmcid}{1} + >> + } + } -\cs_new:Nn \__uftag_struct_kid_mc_gput_right:nn %#1 structure num, #2 MCID absnum% - { - \__uftag_store_pdfpageref:Nn \l_tmpa_tl { \zref@extractdefault{mcid-#2}{tagabspage}{1} } - \__uftag_seq_gput_right:cx - { g__uftag_struct_kids_#1_seq } - { << - /Type\c_space_tl/MCR\c_space_tl - /Pg\c_space_tl\l_tmpa_tl\c_space_tl0\c_space_tl R\c_space_tl - /MCID\c_space_tl\zref@extractdefault{mcid-#2}{tagmcid}{1} - >> - } +\cs_new:Nn\__tag_struct_kid_struct_gput_right:nn %#1 num of parent struct, #2 kid struct + { + \__tag_seq_gput_right:cx + { g__tag_struct_kids_#1_seq } + { + \prop_item:cn + { g__tag_struct_#2_prop } + { objref } + } } -\cs_new:Nn\__uftag_struct_kid_struct_gput_right:nn %#1 num of parent struct, #2 kid struct - { - \__uftag_seq_gput_right:cx - { g__uftag_struct_kids_#1_seq } +\cs_new:Nn\__tag_struct_kid_link_gput_right:nn %#1 num of parent struct, #2 obj reference { - \prop_item:cn - { g__uftag_struct_#2_prop } - { objnum } - \c_space_tl 0 \c_space_tl R + \pdf_object_unnamed_write:nx + { dict } + { + /Type \c_space_tl /OBJR \c_space_tl + /Obj~#2 + } + \__tag_seq_gput_right:cx + { g__tag_struct_kids_#1_seq } + { + \pdf_object_ref_last: + } } - } -\cs_new:Nn\__uftag_struct_kid_link_gput_right:nn %#1 num of parent struct, #2 obj number of link - { - \__uftag_pdfobj:Nn \l__uftag_tmpa_tl +\cs_generate_variant:Nn\__tag_struct_kid_link_gput_right:nn { nx } + +\cs_new:Nn\__tag_struct_exchange_kid_command:N %N= seq { - << - /Type \c_space_tl /OBJR \c_space_tl - /Obj \c_space_tl #2 \c_space_tl 0 \c_space_tl R - >> + \seq_gpop_left:NN #1 \l_tmpa_tl + \regex_replace_once:nnN + { \c{\__tag_mc_insert_mcid_kids:n} } + { \c{\__tag_mc_insert_mcid_single_kids:n} } + \l_tmpa_tl + \seq_gput_left:NV #1 \l_tmpa_tl } - \__uftag_seq_gput_right:cx - { g__uftag_struct_kids_#1_seq } - { - \l__uftag_tmpa_tl \c_space_tl 0 \c_space_tl R - } - } - -\cs_generate_variant:Nn\__uftag_struct_kid_link_gput_right:nn { nx} -\cs_new:Nn\__uftag_struct_exchange_kid_command:N %N= seq - { - \seq_gpop_left:NN #1 \l_tmpa_tl - \regex_replace_once:nnN - {\c{\__uftag_mc_insert_mcid_kids:n}} - {\c{\__uftag_mc_insert_mcid_single_kids:n}} - \l_tmpa_tl - \seq_gput_left:NV #1 \l_tmpa_tl - } -\cs_generate_variant:Nn\__uftag_struct_exchange_kid_command:N { c } +\cs_generate_variant:Nn\__tag_struct_exchange_kid_command:N { c } -\cs_new:Nn \__uftag_struct_fill_kid_key:n %#1 is the struct num - { - \int_case:nnF +\cs_new:Nn \__tag_struct_fill_kid_key:n %#1 is the struct num { - \seq_count:c - { - g__uftag_struct_kids_\prop_item:cn{ g__uftag_struct_#1_prop }{num}_seq - } + \int_case:nnF + { + \seq_count:c + { + g__tag_struct_kids_\prop_item:cn{ g__tag_struct_#1_prop }{num}_seq + } + } + { + { 0 } + { } %no kids, do nothing + { 1 } % 1 kid, insert + { + % in this case we need a special command in + %luamode to get the array right. See issue #13 + \bool_if:NT\g__tag_mode_lua_bool + { + \__tag_struct_exchange_kid_command:c + {g__tag_struct_kids_\prop_item:cn{ g__tag_struct_#1_prop }{num}_seq} + } + \__tag_prop_gput:cnx { g__tag_struct_#1_prop } {K} + { + \seq_item:cn + { + g__tag_struct_kids_\prop_item:cn{ g__tag_struct_#1_prop }{num}_seq + } + {1} + } + } % + } + { %many kids, use an array + \__tag_prop_gput:cnx { g__tag_struct_#1_prop } {K} + { + [ + \seq_use:cn + { + g__tag_struct_kids_\prop_item:cn{ g__tag_struct_#1_prop }{num}_seq + } + { + \c_space_tl + } + ] + } + } } + + +\tl_new:N \l__tag_struct_dict_content_tl + +\cs_new:Nn \__tag_struct_get_dict_content:n { - { 0 } - { } %no kids, do nothing - { 1 } % 1 kid, insert - { - % in this case we in luamode need a special command in luamode to get the array right. See issue #13 - \bool_if:NT\g__uftag_mode_lua_bool + %\tl_set:Nn \l__tag_struct_dict_content_tl {<<} + \tl_clear:N \l__tag_struct_dict_content_tl + \seq_map_inline:cn { - \__uftag_struct_exchange_kid_command:c - {g__uftag_struct_kids_\prop_item:cn{ g__uftag_struct_#1_prop }{num}_seq} + c__tag_struct_\prop_item:cn{ g__tag_struct_#1_prop }{entries}_entries_seq } - \__uftag_prop_gput:cnx { g__uftag_struct_#1_prop } {K} { - \seq_item:cn - { - g__uftag_struct_kids_\prop_item:cn{ g__uftag_struct_#1_prop }{num}_seq - }{1} + \tl_put_right:Nx + \l__tag_struct_dict_content_tl + { + \prop_if_in:cnT + { g__tag_struct_#1_prop } + { ##1 } + { + \c_space_tl/##1~\prop_item:cn{ g__tag_struct_#1_prop } { ##1 } + } + } } - } % - } - { %many kids, use an array - \__uftag_prop_gput:cnx { g__uftag_struct_#1_prop } {K} - { - [ - \seq_use:cn - { - g__uftag_struct_kids_\prop_item:cn{ g__uftag_struct_#1_prop }{num}_seq - } - { - \c_space_tl - } - ] - } + %\tl_put_right:Nn \l__tag_struct_dict_content_tl { >> } } - } -% this command can be used for roots and structure elements -% #1 is a num +\cs_new:Nn \__tag_struct_write_obj:n + { + \prop_if_in:cnTF + { g__tag_struct_#1_prop } + { objref } + { + \__tag_struct_fill_kid_key:n { #1 } + %\prop_show:c { g__tag_struct_#1_prop } + \__tag_struct_get_dict_content:n { #1 } + \exp_args:Nx + \pdf_object_write:nx + { c__tag_struct_#1_obj } + { + \l__tag_struct_dict_content_tl + } + } + { + \msg_error:nnn { tag } { struct-no-objnum } { #1} + } + } -\tl_new:N \l_uftag_struct_dict_content_tl +\keys_define:nn { __tag / struct } + { + label .tl_set:N = \l__tag_struct_key_label_tl, + stash .bool_set:N = \l__tag_struct_elem_stash_bool, + tag .code:n = % S property + {%%????????? \pdfescapename?? + \tl_set:Nx \l__tag_tmpa_tl { #1 } + \bool_if:NT \g__tag_check_tags_bool + { + \__tag_check_structure_tag:N \l__tag_tmpa_tl + } + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { S } + { /\exp_not:V\l__tag_tmpa_tl } + }, + title .code:n = % T property + { + \str_set_convert:Nnon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { T } + { <\l__tag_tmpa_str> } + }, + title-o .code:n = % T property + { + \str_set_convert:Nnon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { T } + { <\l__tag_tmpa_str> } + }, + alttext .code:n = % Alt property + { + \str_set_convert:Nnon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { Alt } + { <\l__tag_tmpa_str> } + }, + alttext-o .code:n = % Alt property + { + \str_set_convert:Noon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { Alt } + { <\l__tag_tmpa_str> } + }, + actualtext .code:n = % ActualText property + { + \str_set_convert:Nnon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { ActualText } + { <\l__tag_tmpa_str>} + }, + actualtext-o .code:n = % ActualText property + { + \str_set_convert:Noon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { ActualText } + { <\l__tag_tmpa_str>} + }, + lang .code:n = % Lang property + { + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { Lang } + { (#1) } + }, + ref .code:n = % Lang property + { + \tl_clear:N\l__tag_tmpa_tl + \clist_map_inline:nn {#1} + { + \tl_put_right:Nx \l__tag_tmpa_tl + {~\ref_value:nn{tagpdfstruct-##1}{tagstructobj} } + } + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { Ref } + { [\l__tag_tmpa_tl] } + }, + E .code:n = % E property + { + \str_set_convert:Nnon + \l__tag_tmpa_str + { #1 } + { default } + { utf16/hex } + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { E } + { <\l__tag_tmpa_str> } + }, + } -\cs_new:Nn \__uftag_struct_get_dict_content:n +\keys_define:nn { __tag / struct } { - \tl_set:Nn \l_uftag_struct_dict_content_tl {<<} - \seq_map_inline:cn - { - c__uftag_struct_\prop_item:cn{ g__uftag_struct_#1_prop }{entries}_entries_seq - } - { - \tl_put_right:Nx - \l_uftag_struct_dict_content_tl - { - \prop_if_in:cnT - { g__uftag_struct_#1_prop } - { ##1 } + AF .code:n = % T property + { + \pdf_object_if_exist:nTF {#1} + { + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { AF } + { \pdf_object_ref:n {#1} } + } + { + + } + }, + ,AFinline .code:n = { - \c_space_tl/##1~\prop_item:cn{ g__uftag_struct_#1_prop } { ##1 } + \group_begin: + \exp_args:Ne + \pdf_object_if_exist:nF {__tag/fileobj\int_use:N\c@g__tag_struct_abs_int} + { + \pdffile_embed_stream:nxx + {#1} + {tag-AFfile\int_use:N\c@g__tag_struct_abs_int.txt} + {__tag/fileobj\int_use:N\c@g__tag_struct_abs_int} + } + \__tag_prop_gput:cnx + { g__tag_struct_\int_use:N\c@g__tag_struct_abs_int _prop } + { AF } + { \pdf_object_ref:e {__tag/fileobj\int_use:N\c@g__tag_struct_abs_int } } + \group_end: } - } - } - \tl_put_right:Nn \l_uftag_struct_dict_content_tl { >> } - } - - -% #1 is the struct num -\cs_new:Nn \__uftag_struct_write_obj:n - { - \prop_if_in:cnTF - { g__uftag_struct_#1_prop } - { objnum } - { - \__uftag_struct_fill_kid_key:n { #1 } - %\prop_show:c { g__uftag_struct_#1_prop } - \__uftag_struct_get_dict_content:n { #1 } - \__uftag_pdfuseobjnum:xx - { \prop_item:cn { g__uftag_struct_#1_prop } {objnum} } + ,AFinline-o .code:n = { - \l_uftag_struct_dict_content_tl + \group_begin: + \exp_args:Ne + \pdf_object_if_exist:nF {__tag/fileobj\int_use:N\c@g__tag_struct_abs_int} + { + \pdffile_embed_stream:oxx + {#1} + {tag-AFfile\int_use:N\c@g__tag_struct_abs_int.txt} + {__tag/fileobj\int_use:N\c@g__tag_struct_abs_int} + } + \__tag_prop_gput:cnx + { g__tag_struct_\int_use:N\c@g__tag_struct_abs_int _prop } + { AF } + { \pdf_object_ref:e {__tag/fileobj\int_use:N\c@g__tag_struct_abs_int } } + \group_end: } - } - { - \msg_error:nnn {uftag} { struct-no-objnum } { #1} - } } -% keys for the user commands -% should I pass the values (e.g. the tag) through an escape command? -\keys_define:nn { uftag / struct } - { - label .tl_set:N = \l__uftag_struct_key_label_tl, - stash .bool_set:N = \l__uftag_struct_elem_stash_bool, - tag .code:n = % S property - {%%????????? \pdfescapename?? - \tl_set:Nx \l__uftag_tmpa_tl { #1 } - \bool_if:NT \g__uftag_check_tags_bool - { - \__uftag_check_structure_tag:N \l__uftag_tmpa_tl - } - \__uftag_prop_gput:cnx - { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop } - { S } - { /\exp_not:V\l__uftag_tmpa_tl } - }, - title .code:n = % T property - { - \str_set_convert:Nnon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \__uftag_prop_gput:cnx - { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop } - { T } - { <\l__uftag_tmpa_str> } - }, - title-o .code:n = % T property - { - \str_set_convert:Nnon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \__uftag_prop_gput:cnx - { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop } - { T } - { <\l__uftag_tmpa_str> } - }, - alttext .code:n = % Alt property - { - \str_set_convert:Nnon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \__uftag_prop_gput:cnx - { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop } - { Alt } - { <\l__uftag_tmpa_str> } - }, - alttext-o .code:n = % Alt property - { - \str_set_convert:Noon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \__uftag_prop_gput:cnx - { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop } - { Alt } - { <\l__uftag_tmpa_str> } - }, - actualtext .code:n = % ActualText property - { - \str_set_convert:Nnon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \__uftag_prop_gput:cnx - { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop } - { ActualText } - { <\l__uftag_tmpa_str>} - }, - actualtext-o .code:n = % ActualText property - { - \str_set_convert:Noon - \l__uftag_tmpa_str - { #1 } - { \g__uftag_inputencoding_tl } - { utf16/hex } - \__uftag_prop_gput:cnx - { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop } - { ActualText } - { <\l__uftag_tmpa_str>} - }, -} - - -\cs_new_protected:Nn \uftag_struct_begin:n - { - \group_begin: - \int_gincr:N \c@g__uftag_struct_abs_int - \__uftag_prop_new:c { g__uftag_struct_\int_eval:n { \c@g__uftag_struct_abs_int }_prop } - \__uftag_new_output_prop_handler:n {\int_eval:n { \c@g__uftag_struct_abs_int }} - \__uftag_seq_new:c { g__uftag_struct_kids_\int_eval:n { \c@g__uftag_struct_abs_int }_seq} - \__uftag_pdfreserveobjnum:N \l_tmpa_tl - \__uftag_prop_gput:cno - { g__uftag_struct_\int_eval:n { \c@g__uftag_struct_abs_int }_prop } - { objnum} - { \l_tmpa_tl } - \__uftag_prop_gput:cnx - { g__uftag_struct_\int_eval:n { \c@g__uftag_struct_abs_int }_prop } - { num} - { \int_eval:n { \c@g__uftag_struct_abs_int } } - \__uftag_prop_gput:cno - { g__uftag_struct_\int_eval:n { \c@g__uftag_struct_abs_int }_prop } - { Type } - { /StructElem } - \__uftag_prop_gput:cno - { g__uftag_struct_\int_eval:n { \c@g__uftag_struct_abs_int }_prop } - { entries } - { StructElem } - \keys_set:nn {uftag / struct} { #1 } - \__uftag_check_structure_has_tag:n { \int_eval:n {\c@g__uftag_struct_abs_int} } - \tl_if_empty:NF - {\l__uftag_struct_key_label_tl} - { - \zref@labelbylist{tagpdfstruct-\l__uftag_struct_key_label_tl}{uftagzrlstruct} - } - %get the potential parent from the stack: - \seq_get:NNF - \g__uftag_struct_stack_seq - \l__uftag_struct_stack_parent_tmp_tl - { - \msg_error:nn { uftag } { struct-faulty-nesting } - } - \seq_gpush:NV \g__uftag_struct_stack_seq \c@g__uftag_struct_abs_int - \tl_gset:NV \g__uftag_struct_stack_current_tl \c@g__uftag_struct_abs_int - %\seq_show:N \g__uftag_struct_stack_seq - \bool_if:NF - \l__uftag_struct_elem_stash_bool - {%set the parent - \__uftag_prop_gput:cnx - { g__uftag_struct_\int_eval:n {\c@g__uftag_struct_abs_int}_prop } - { P } +\cs_new_protected:Nn \tag_struct_begin:n + { + \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 } + \__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} + %\__tag_pdfreserveobjnum:N \l_tmpa_tl + \exp_args:Ne + \pdf_object_new:nn + { c__tag_struct_\int_eval:n { \c@g__tag_struct_abs_int }_obj } + { dict } + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n { \c@g__tag_struct_abs_int }_prop } + { objref} { - \prop_item:cn { g__uftag_struct_\l__uftag_struct_stack_parent_tmp_tl _prop} { objnum }~0~R + \exp_args:Ne + \pdf_object_ref:n + {c__tag_struct_\int_eval:n { \c@g__tag_struct_abs_int }_obj} } - %record this structure as kid: - %\tl_show:N \g__uftag_struct_stack_current_tl - %\tl_show:N \l__uftag_struct_stack_parent_tmp_tl - \__uftag_struct_kid_struct_gput_right:nn - { \l__uftag_struct_stack_parent_tmp_tl } - { \g__uftag_struct_stack_current_tl } - %\prop_show:c { g__uftag_struct_\g__uftag_struct_stack_current_tl _prop } - %\seq_show:c {g__uftag_struct_kids_\l__uftag_struct_stack_parent_tmp_tl _seq} - } - %\prop_show:c { g__uftag_struct_\g__uftag_struct_stack_current_tl _prop } - %\seq_show:c {g__uftag_struct_kids_\l__uftag_struct_stack_parent_tmp_tl _seq} - \group_end: - } + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n { \c@g__tag_struct_abs_int }_prop } + { num} + { \int_eval:n { \c@g__tag_struct_abs_int } } + \__tag_prop_gput:cno + { g__tag_struct_\int_eval:n { \c@g__tag_struct_abs_int }_prop } + { Type } + { /StructElem } + \__tag_prop_gput:cno + { g__tag_struct_\int_eval:n { \c@g__tag_struct_abs_int }_prop } + { entries } + { StructElem } + \keys_set:nn { __tag / struct} { #1 } + \__tag_check_structure_has_tag:n { \int_eval:n {\c@g__tag_struct_abs_int} } + \tl_if_empty:NF + \l__tag_struct_key_label_tl + { + \__tag_ref_label:en{tagpdfstruct-\l__tag_struct_key_label_tl}{struct} + } + %get the potential parent from the stack: + \seq_get:NNF + \g__tag_struct_stack_seq + \l__tag_struct_stack_parent_tmp_tl + { + \msg_error:nn { tag } { struct-faulty-nesting } + } + \seq_gpush:NV \g__tag_struct_stack_seq \c@g__tag_struct_abs_int + \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 + {%set the parent + \__tag_prop_gput:cnx + { g__tag_struct_\int_eval:n {\c@g__tag_struct_abs_int}_prop } + { P } + { + \prop_item:cn + { g__tag_struct_\l__tag_struct_stack_parent_tmp_tl _prop} + { objref } + } + %record this structure as kid: + %\tl_show:N \g__tag_struct_stack_current_tl + %\tl_show:N \l__tag_struct_stack_parent_tmp_tl + \__tag_struct_kid_struct_gput_right:nn + { \l__tag_struct_stack_parent_tmp_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_tmp_tl _seq} + } + %\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_tmp_tl _seq} + \group_end: + } -\cs_new_protected:Nn \uftag_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__uftag_struct_stack_seq - \seq_gpop:NNTF \g__uftag_struct_stack_seq \l_tmpa_tl - { - \int_compare:nNnT {\l__uftag_loglevel_int} > { 0 } - { - \__uftag_check_info_closing_struct:o { \g__uftag_struct_stack_current_tl } - } - } - { \__uftag_check_no_open_struck: } - % get the previous one, shouldn't be empty as the root should be there - \seq_get:NNTF \g__uftag_struct_stack_seq \l_tmpa_tl - { - \tl_gset:NV \g__uftag_struct_stack_current_tl \l_tmpa_tl - } - { - \__uftag_check_no_open_struck: - } - } +\cs_set_eq:NN \uftag_struct_begin:n \tag_struct_begin:n -\cs_new_protected:Nn \uftag_struct_use:n %#1 is the label - { - \prop_if_exist:cTF - { g__uftag_struct_\zref@extractdefault{tagpdfstruct-#1}{tagstruct}{unknown}_prop } %?????????? - { - \__uftag_check_struct_used:n {#1} - %add the label structure as kid to the current structure (can be the root) - \__uftag_struct_kid_struct_gput_right:nn - { \g__uftag_struct_stack_current_tl } - { \zref@extractdefault{tagpdfstruct-#1}{tagstruct}{0} } - %add the current structure to the labeled one as parents - \__uftag_prop_gput:cnx - { g__uftag_struct_\zref@extractdefault{tagpdfstruct-#1}{tagstruct}{0}_prop } - { P } - { - \prop_item:cn { g__uftag_struct_\g__uftag_struct_stack_current_tl _prop} { objnum }~0~R - } - } - {\msg_warning:nnn{uftag}{struct-label-unknown}{#1}} - } +\cs_new_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 + \seq_gpop:NNTF \g__tag_struct_stack_seq \l_tmpa_tl + { + \int_compare:nNnT {\l__tag_loglevel_int} > { 0 } + { + \__tag_check_info_closing_struct:o { \g__tag_struct_stack_current_tl } + } + } + { \__tag_check_no_open_struck: } + % get the previous one, shouldn't be empty as the root should be there + \seq_get:NNTF \g__tag_struct_stack_seq \l_tmpa_tl + { + \tl_gset:NV \g__tag_struct_stack_current_tl \l_tmpa_tl + } + { + \__tag_check_no_open_struck: + } + } +\cs_set_eq:NN \uftag_struct_end: \tag_struct_end: + +\cs_new_protected:Nn \tag_struct_use:n %#1 is the label + { + \prop_if_exist:cTF + { g__tag_struct_\__tag_ref_value: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:nn + { \g__tag_struct_stack_current_tl } + { \__tag_ref_value:enn{tagpdfstruct-#1}{tagstruct}{0} } + %add the current structure to the labeled one as parents + \__tag_prop_gput:cnx + { g__tag_struct_\__tag_ref_value:enn{tagpdfstruct-#1}{tagstruct}{0}_prop } + { P } + { + \prop_item:cn + { g__tag_struct_\g__tag_struct_stack_current_tl _prop} + { objref } + } + } + { + \msg_warning:nnn{ tag }{struct-label-unknown}{#1} + } + } + +\cs_set_eq:NN \uftag_struct_use:n \tag_struct_use:n %%%% Code to tag links %%%% this works for url, see exp-link.pdf. %%%% it must be checked for other links -\cs_new_protected:Nn \__uftag_struct_finish_link: -{ - \bool_if:NT \g_uftag_active_struct_bool - { - %get the number of the parent link structure: - \seq_get:NNF - \g__uftag_struct_stack_seq - \l__uftag_struct_stack_parent_tmp_tl - { - \msg_error:nn { uftag } { struct-faulty-nesting } - } - %put the obj number of link annot in the kid entry: - \__uftag_struct_kid_link_gput_right:nx - { - \l__uftag_struct_stack_parent_tmp_tl - } - { - \int_use:N\__uftag_pdf_lastlink: - } - % add the parent obj number to the parent tree: - \__uftag_parenttree_add_objr:nn - { - \int_use:N\c@g__uftag_parenttree_obj_int - } +\cs_new_protected:Nn \__tag_struct_finish_link: { - \prop_item:cn{ g__uftag_struct_\l__uftag_struct_stack_parent_tmp_tl _prop } - { objnum } + \bool_if:NT \g__tag_active_struct_bool + { + %get the number of the parent link structure: + \seq_get:NNF + \g__tag_struct_stack_seq + \l__tag_struct_stack_parent_tmp_tl + { + \msg_error:nn { tag } { struct-faulty-nesting } + } + %put the obj number of link annot in the kid entry: + \__tag_struct_kid_link_gput_right:nx + { + \l__tag_struct_stack_parent_tmp_tl + } + { + \pdfannot_link_ref_last: + } + % add the parent obj number to the parent tree: + \__tag_parenttree_add_objr:nn + { + \int_use:N\c@g__tag_parenttree_obj_int + } + { + \prop_item:cn + { g__tag_struct_\l__tag_struct_stack_parent_tmp_tl _prop } + { objref } + } + % increase the int: + \stepcounter{ g__tag_parenttree_obj_int } + } } - % increase the int: - \stepcounter{ g__uftag_parenttree_obj_int } - } -} -\endinput + +%% +%% +%% End of file `tagpdf-struct-code.sty'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-tree-code.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-tree-code.sty index af8ec11aa9c..390965ae506 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-tree-code.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-tree-code.sty @@ -1,210 +1,252 @@ -\ProvidesExplPackage {tagpdf-tree-code} {2019/07/02} {0.61} +%% +%% This is file `tagpdf-tree-code.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf-tree.dtx (with options: `tree') +%% +%% Copyright (C) 2019 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-tree.dtx +\ProvidesExplPackage {tagpdf-tree-code} {2021/02/23} {0.80} {part of tagpdf - code related to writing trees and dictionaries to the pdf} -%this does the actual finishing: -\AtBeginDocument - { - \bool_if:NT \g_uftag_active_tree_bool - { - \AfterEndDocument { \uftag_finish_structure: } - } - } - - -% the StructTreeRoot -% we better get the object number in any case: -\__uftag_pdfreserveobjnum:N \l_tmpa_tl -\tl_const:Nx \c_uftag_tree_obj_structtreeroot_tl { \l_tmpa_tl } - - -\cs_new:Nn \__uftag_tree_write_structtreeroot: - { - \__uftag_pdfcatalog:n { /StructTreeRoot~\c_uftag_tree_obj_structtreeroot_tl\c_space_tl0~R } - \__uftag_struct_write_obj:n { 0 } - } - -\cs_new:Nn \__uftag_tree_write_structelements: - { - \int_step_inline:nnnn {1}{1}{\c@g__uftag_struct_abs_int} - { - %\prop_show:c {g__uftag_struct_##1_prop} - \__uftag_struct_write_obj:n { ##1 } %write the object - } - } - - -%the ParentTree -\__uftag_pdfreserveobjnum:N \l_tmpa_tl -\tl_const:Nx \c__uftag_tree_obj_parenttree_tl { \l_tmpa_tl } - -% we have two sets of entries in the parent tree: -% page streams and real objects. -% The numbers must be distinct and ordered -% So we rely on abspage and put the real objects at the end -% I use a counter to have a chance to get the correct number -% if code is process twice. -\newcounter { g__uftag_parenttree_obj_int } -\AtBeginDocument - { \int_gset:Nn \c@g__uftag_parenttree_obj_int - { \zref@extractdefault{LastPage}{abspage}{100} } - } - -% we need to record the obj references: - -\tl_new:N \g__uftag_parenttree_objr_tl - -\cs_new:Nn \__uftag_parenttree_add_objr:nn %#1 Structparent number, #2 obj number -{ - \tl_gput_right:Nx \g__uftag_parenttree_objr_tl +\hook_gput_code:nnn{begindocument}{tagpdf} { - #1 \c_space_tl #2\c_space_tl 0 \c_space_tl R\c_space_tl ^^J + \bool_if:NT \g__tag_active_tree_bool + { + \AfterEndDocument { \tag_finish_structure: } + } } -} - -\tl_new:N \l__uftag_parenttree_content_tl - -\cs_new:Nn \__uftag_tree_fill_parenttree: - { - \int_step_inline:nnnn{1}{1}{\zref@extractdefault{LastPage}{abspage}{-1}} %not quite clear if labels are needed. See lua code - { %page ##1\par - \prop_clear:N \l_tmpa_prop - \int_step_inline:nnnn{1}{1}{\zref@extractdefault{LastPage}{tagmcabs}{-1}} - { - %mcid####1 - \int_compare:nT%F - {\zref@extractdefault{mcid-####1}{tagabspage}{-1}=##1} %mcid is on current page - {% yes\par - \prop_put:Nxx \l_tmpa_prop - {\zref@extractdefault{mcid-####1}{tagmcid}{-1}} - {\prop_item:Nn \g__uftag_mc_parenttree_prop {####1}} - } - } - %\prop_show:N \l_tmpa_prop - \tl_put_right:Nx\l__uftag_parenttree_content_tl - {\int_eval:n {##1-1}\c_space_tl[\c_space_tl} %%brackt - \int_step_inline:nnnn {0}{1}{ \prop_map_function:NN \l_tmpa_prop\__uftag_prop_count:nn -1 } - { - \prop_get:NnNTF \l_tmpa_prop {####1} \l_tmpb_tl - {% page#1:mcid##1:\l_tmpb_tl :content - \tl_put_right:Nx \l__uftag_parenttree_content_tl - { - \prop_item:cn { g__uftag_struct_\l_tmpb_tl _prop } {objnum}~0~R~ - } - } - {\msg_warning:nn {uftag} {tree-mcid-index-wrong} } - } - \tl_put_right:Nn \l__uftag_parenttree_content_tl {]^^J} % + + +\pdf_object_new:nn { c__tag_struct_0_obj }{ dict } + + %need to think about the best place ... +\hook_gput_code:nnn{begindocument}{tagpdf} + { + \bool_if:NT \g__tag_active_struct_bool + { + \pdfmanagement_add:nnx + { Catalog } + { StructTreeRoot } + { \pdf_object_ref:n { c__tag_struct_0_obj } } + } + } +\cs_new_protected:Nn \__tag_tree_write_structtreeroot: + { + \__tag_struct_write_obj:n { 0 } + } + +\cs_new_protected:Nn \__tag_tree_write_structelements: + { + \int_step_inline:nnnn {1}{1}{\c@g__tag_struct_abs_int} + { + %\prop_show:c {g__tag_struct_##1_prop} + \__tag_struct_write_obj:n { ##1 } %write the object + } + } + + +\pdf_object_new:nn { c__tag_tree_parenttree_obj }{ dict } + +\newcounter { g__tag_parenttree_obj_int } +\hook_gput_code:nnn{begindocument}{tagpdf} + { + \int_gset:Nn + \c@g__tag_parenttree_obj_int + { \__tag_ref_value_lastpage:nn{abspage}{100} } + } + + +\tl_new:N \g__tag_parenttree_objr_tl + +\cs_new_protected:Nn \__tag_parenttree_add_objr:nn %#1 Structparent number, #2 objref + { + \tl_gput_right:Nx \g__tag_parenttree_objr_tl + { + #1 \c_space_tl #2 ^^J + } + } + +\tl_new:N \l__tag_parenttree_content_tl + +\cs_new_protected:Nn \__tag_tree_fill_parenttree: + { + \int_step_inline:nnnn{1}{1}{\__tag_ref_value_lastpage:nn{abspage}{-1}} %not quite clear if labels are needed. See lua code + { %page ##1\par + \prop_clear:N \l_tmpa_prop + \int_step_inline:nnnn{1}{1}{\__tag_ref_value_lastpage:nn{tagmcabs}{-1}} + { + %mcid####1 + \int_compare:nT%F + {\__tag_ref_value:enn{mcid-####1}{tagabspage}{-1}=##1} %mcid is on current page + {% yes\par + \prop_put:Nxx + \l_tmpa_prop + {\__tag_ref_value:enn{mcid-####1}{tagmcid}{-1}} + {\prop_item:Nn \g__tag_mc_parenttree_prop {####1}} + } + } + %\prop_show:N \l_tmpa_prop + \tl_put_right:Nx\l__tag_parenttree_content_tl + { + \int_eval:n {##1-1}\c_space_tl + [\c_space_tl %] + } + \int_step_inline:nnnn + {0} + {1} + { \prop_map_function:NN \l_tmpa_prop\__tag_prop_count:nn -1 } + { + \prop_get:NnNTF \l_tmpa_prop {####1} \l_tmpb_tl + {% page#1:mcid##1:\l_tmpb_tl :content + \tl_put_right:Nx \l__tag_parenttree_content_tl + { + \prop_item:cn { g__tag_struct_\l_tmpb_tl _prop } {objref} + \c_space_tl + } + %\tl_show:N \l__tag_parenttree_content_tl + } + { + \msg_warning:nn { tag } {tree-mcid-index-wrong} + } + } + \tl_put_right:Nn + \l__tag_parenttree_content_tl + {%[ + ]^^J + } + } + } + +\cs_new_protected:Nn \__tag_tree_lua_fill_parenttree: + { + \tl_set:Nn \l__tag_parenttree_content_tl + { + \directlua + { + ltx.__tag.func.output_parenttree + ( + \int_use:N\g_shipout_readonly_int + ) + } + } + } + +\cs_new_protected:Nn \__tag_tree_write_parenttree: + { + \bool_if:NTF \g__tag_mode_lua_bool + { + \__tag_tree_lua_fill_parenttree: + } + { + \__tag_tree_fill_parenttree: + } + \tl_put_right:NV \l__tag_parenttree_content_tl\g__tag_parenttree_objr_tl + \pdf_object_write:nx { c__tag_tree_parenttree_obj } + { + /Nums\c_space_tl [\l__tag_parenttree_content_tl] + } + } + + +\pdf_object_new:nn { c__tag_tree_rolemap_obj }{ dict } + +\tl_new:N \l__tag_rolemap_content_tl + +\cs_new_protected:Nn \__tag_tree_fill_rolemap: + { + \prop_map_inline:Nn \g__tag_role_rolemap_prop + { + \tl_put_right:Nx \l__tag_rolemap_content_tl + { + /##1\c_space_tl/##2^^J + } + } + } + +\cs_new_protected:Nn \__tag_tree_write_rolemap: + { + \__tag_tree_fill_rolemap: + \pdf_object_write:nx { c__tag_tree_rolemap_obj } + { + \l__tag_rolemap_content_tl + } + } + + +\cs_new_protected:Nn \__tag_tree_write_classmap: + { + \tl_gclear:N \g__tag_attr_class_content_tl + \seq_gremove_duplicates:N \g__tag_attr_class_used_seq + \seq_set_map:NNn \l_tmpa_seq \g__tag_attr_class_used_seq + { + /##1\c_space_tl + << + \prop_item:Nn + \g__tag_attr_entries_prop + {##1} + >> + } + \tl_gset:Nx \g__tag_attr_class_content_tl + { + \seq_use:Nn + \l_tmpa_seq + { \iow_newline: } + } + \tl_if_empty:NF + \g__tag_attr_class_content_tl + { + \pdf_object_new:nn { c__tag_tree_classmap_obj }{ dict } + % \__tag_pdfreserveobjnum:N \l_tmpa_tl + % \tl_const:Nx \c__tag_tree_obj_classmap_tl { \l_tmpa_tl } + \pdf_object_write:nx + { c__tag_tree_classmap_obj } + { \g__tag_attr_class_content_tl } + \__tag_prop_gput:cnx + { g__tag_struct_0_prop } + { ClassMap } + { \pdf_object_ref:n { c__tag_tree_classmap_obj } } + } } - } - -%lua mode must/can do it differently -\cs_new:Nn \__uftag_tree_lua_fill_parenttree: - { - \tl_set:Nn \l__uftag_parenttree_content_tl - { - \directlua{uftag.func.output_parenttree(\int_use:N\g__uftag_abspage_int)} - } - } - - - -\cs_new:Nn \__uftag_tree_write_parenttree: - { - \bool_if:NTF \g__uftag_mode_lua_bool - { - \__uftag_tree_lua_fill_parenttree: - } - { - \__uftag_tree_fill_parenttree: - } - \tl_put_right:NV \l__uftag_parenttree_content_tl\g__uftag_parenttree_objr_tl - \__uftag_pdfuseobjnum:xx { \c__uftag_tree_obj_parenttree_tl } - { - <<\c_space_tl/Nums\c_space_tl [\l__uftag_parenttree_content_tl] \c_space_tl >> - } - } - -%the Rolemap tree -\__uftag_pdfreserveobjnum:N \l_tmpa_tl -\tl_const:Nx \c__uftag_tree_obj_rolemap_tl { \l_tmpa_tl } -\tl_new:N \l__uftag_rolemap_content_tl - -\cs_new:Nn \__uftag_tree_fill_rolemap: - { - \prop_map_inline:Nn \g__uftag_role_rolemap_prop - { - \tl_put_right:Nx \l__uftag_rolemap_content_tl - { - /##1\c_space_tl/##2^^J - } - } - } - -\cs_new:Nn \__uftag_tree_write_rolemap: - { - \__uftag_tree_fill_rolemap: - \__uftag_pdfuseobjnum:xx { \c__uftag_tree_obj_rolemap_tl } - { - <<\l__uftag_rolemap_content_tl >> - } - } - -%classmap, should only be written, if values has been used - -\cs_new_protected:Nn \__uftag_tree_class_write_map: - { - \tl_gclear:N \g__uftag_attr_class_content_tl - \seq_gremove_duplicates:N \g__uftag_attr_class_used_seq - \seq_set_map:NNn \l_tmpa_seq \g__uftag_attr_class_used_seq - { - /##1\c_space_tl - \prop_item:Nn \g__uftag_attr_entries_prop - {##1} - } - \tl_gset:Nx \g__uftag_attr_class_content_tl - { - \seq_use:Nn \l_tmpa_seq - { \iow_newline: } - } - \tl_if_empty:NF \g__uftag_attr_class_content_tl + +\cs_new_protected:Nn \tag_finish_structure: + { + \__tag_tree_write_parenttree: + \__tag_tree_write_rolemap: + \__tag_tree_write_classmap: + \__tag_tree_write_structelements: %this is rather slow!! + \__tag_tree_write_structtreeroot: + } + +\cs_set_eq:NN \uftag_finish_structure: \tag_finish_structure: + +\hook_gput_code:nnn{begindocument}{tagpdf} { - \__uftag_pdfreserveobjnum:N \l_tmpa_tl - \tl_const:Nx \c__uftag_tree_obj_classmap_tl { \l_tmpa_tl } - \__uftag_pdfuseobjnum:Nx \c__uftag_tree_obj_classmap_tl - { <<\g__uftag_attr_class_content_tl>> } - - \__uftag_prop_gput:cnx - { g__uftag_struct_0_prop } - { ClassMap } - { \c__uftag_tree_obj_classmap_tl\c_space_tl0\c_space_tl R } + \bool_if:NT\g__tag_active_tree_bool + { + \hook_gput_code:nnn{shipout/before} { tagpdf/structparents } + { + \pdfmanagement_add:nnx + { Page } + {StructParents} + {\int_eval:n { \g_shipout_readonly_int}} + } + } } - } - - -\cs_new:Nn \uftag_finish_structure: - { - \__uftag_pdfcatalog:n {^^J/MarkInfo\c_space_tl<> } - \__uftag_tree_write_parenttree: - \__uftag_tree_write_rolemap: - \__uftag_tree_class_write_map: - \__uftag_tree_write_structelements: - \__uftag_tree_write_structtreeroot: - } - - -%StructParents + tabs order. Tabs order should be probably be changeable by page. - -\cs_new:Nn \__uftag_tree_write_pageattr: - { - \__uftag_get_pdfpageattr:N \l_tmpa_tl - \regex_replace_once:nnN {/StructParents\s*\d+} {}\l_tmpa_tl - \regex_replace_once:nnN {/Tabs\s*/[SCR]} {}\l_tmpa_tl - \__uftag_gset_pdfpageattr:x - { - \l_tmpa_tl / StructParents \c_space_tl - \int_eval:n { \g__uftag_abspage_int } - \l__uftag_tree_tabs_order_tl - } - } - -\endinput + +%% +%% +%% End of file `tagpdf-tree-code.sty'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-user.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-user.sty index 5bce390e4f4..8d2569a879b 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf-user.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf-user.sty @@ -1,102 +1,171 @@ -\ProvidesExplPackage {tagpdf-user} {2019/07/02} {0.61} +%% +%% This is file `tagpdf-user.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf.dtx (with options: `user') +%% +%% Copyright (C) 2019 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-user} {2021/02/23} {0.80} {tagpdf - user commands} \NewDocumentCommand \tagpdfsetup { m } - { - \keys_set:nn { uftag / setup } { #1 } - } + { + \keys_set:nn { __tag / 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 -%%% a generic command to retrieve data +%%% stop tagging +\bool_new:N \l__tag_stop_bool -\cs_new:Npn \tagpdfget #1 { \uftag_get:n { #1} } -\cs_new:Npn \uftag_get:n #1 { \use:c {__uftag_get_data_#1: } } +\prg_new_conditional:Nnn \__tag_if_stop: {p,T,F,TF} + { + \bool_if:NTF \l__tag_stop_bool + { \prg_return_true: } + { \prg_return_false: } + } +\prg_new_eq_conditional:NNn \tag_if_stop: \__tag_if_stop: {p,T,F,TF} + +\cs_new_protected:Npn \__tag_stop: + { + \bool_set_true:N \l__tag_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 + %deprecated + \cs_set_eq:NN \uftag_mc_begin:n \tag_mc_begin:n + \cs_set_eq:NN \uftag_mc_end: \tag_mc_end: + \cs_set_eq:NN \uftag_mc_use:n \tag_mc_use:n + \cs_set_eq:NN \uftag_struct_begin:n \tag_struct_begin:n + \cs_set_eq:NN \uftag_struct_end: \tag_struct_end: + \cs_set_eq:NN \uftag_struct_use:n \tag_struct_use:n + } + +\cs_new_protected:Npn \tag_stop_group_begin: + { + \group_begin: + \__tag_stop: + } + +\cs_set_eq:NN \tag_stop_group_end: \group_end: + +%%% a generic command to retrieve data + +\cs_new:Npn \tagpdfget #1 { \use:c {__tag_get_data_#1: } } +\cs_new:Npn \tag_get:n #1 { \use:c {__tag_get_data_#1: } } +\cs_new:Npn \uftag_get:n #1 { \use:c {__tag_get_data_#1: } } %%%% mc related user commands \NewDocumentCommand \tagmcifinTF { m m } + { + \__tag_mc_if_in:TF { #1 } { #2 } + } + +\NewDocumentEnvironment{tagmcartifact}{m} { - \__uftag_mc_if_in:TF { #1 } { #2 } + \tag_mc_artifact_group_begin:n { #1}\ignorespaces } - -\NewDocumentCommand \tagmcbegin { m } { - \uftag_mc_begin:n {#1}\ignorespaces + \tag_mc_artifact_group_end: } +\NewDocumentCommand \tagmcbegin { m } + { + \tag_mc_begin:n {#1}\ignorespaces + } \NewDocumentCommand \tagmcend { } - { - \unskip % this unskip appears to mess up some spacing; can we do this in another way? - \uftag_mc_end: - } + { + \unskip % this unskip appears to mess up some spacing; can we do this in another way? + \tag_mc_end: + } \NewDocumentCommand \tagmcuse { m } - { - \uftag_mc_use:n {#1} - } - + { + \tag_mc_use:n {#1} + } %%%% structure related commands \NewDocumentCommand \tagstructbegin { m } - { - \uftag_struct_begin:n {#1} - } + { + \tag_struct_begin:n {#1} + } \NewDocumentCommand \tagstructend { } - { - \uftag_struct_end: - } + { + \tag_struct_end: + } \NewDocumentCommand \tagstructuse { m } - { - \uftag_struct_use:n {#1} - } - - + { + \tag_struct_use:n {#1} + } %%%% debug/show commands -\NewDocumentCommand\showtagpdfmcdata { O {\__uftag_get_mc_abs_cnt:} } - { - \bool_if:NT \g__uftag_mode_lua_bool - { - \sys_if_engine_luatex:T - { - \directlua{uftag.trace.show_all_mc_data(#1)} - } - } - } +\NewDocumentCommand\showtagpdfmcdata { O {\__tag_tag_get_mc_abs_cnt:} } + { + \bool_if:NT \g__tag_mode_lua_bool + { + \sys_if_engine_luatex:T + { + \directlua{ltx.__tag.trace.show_all_mc_data(#1)} + } + } + } \NewDocumentCommand\showtagpdfattributes { } - { - \bool_if:NT \g__uftag_mode_lua_bool - { - \sys_if_engine_luatex:T - { - \directlua - { - uftag.trace.log( - "showtagpdfattributes: MC=>abscnt=\__uftag_get_mc_abs_cnt:=>attr=\the\l__uftag_mc_cnt_attr=>tag=" .. - tostring(uftag.func.get_tag_from (\the\l__uftag_mc_type_attr)) .. - "=\the\l__uftag_mc_type_attr",0 - ) - } - \ignorespaces - } + { + \bool_if:NT \g__tag_mode_lua_bool + { + \sys_if_engine_luatex:T + { + \directlua + { + ltx.__tag.trace.log + ( + "showtagpdfattributes: + MC=>abscnt=\__tag_get_mc_abs_cnt: + =>attr=\the\l__tag_mc_cnt_attr=>tag=" + .. + tostring(ltx.__tag.func.get_tag_from (\the\l__tag_mc_type_attr)) + .. + "=\the\l__tag_mc_type_attr",0 + ) + } + \ignorespaces + } + } } - } \sys_if_engine_luatex:T -{ - \NewDocumentCommand\pdffakespace { } { - \__uftag_fakespace: + \NewDocumentCommand\pdffakespace { } + { + \__tag_fakespace: + } } -} - -\endinput +%% +%% +%% End of file `tagpdf-user.sty'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua b/Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua index e3b2373bc05..bc9f440b052 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf.lua @@ -1,17 +1,38 @@ +-- +-- This is file `tagpdf.lua', +-- generated with the docstrip utility. +-- +-- The original source files were: +-- +-- tagpdf-backend.dtx (with options: `lua') +-- +-- Copyright (C) 2019 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-backend.dtx -- tagpdf.lua -- Ulrike Fischer -local ProvidesLuaModule = { +local ProvidesLuaModule = { name = "tagpdf", - version = "0.61", --TAGVERSION - date = "2019-07-02", --TAGDATE + version = "0.80", --TAGVERSION + date = "2021-02-23", --TAGDATE description = "tagpdf lua code", license = "The LATEX Project Public License 1.3c" } if luatexbase and luatexbase.provides_module then luatexbase.provides_module (ProvidesLuaModule) -end +end --[[ The code has quite probably a number of problems @@ -19,60 +40,58 @@ The code has quite probably a number of problems - the naming is not always consistent due to the development of the code - the traversing of the shipout box must be tested with more complicated setups - it should probably handle more node types - - + - --]] - - --[[ -the main table is named uftag. It contains the functions and also the data +the main table is named ltx.__tag. It contains the functions and also the data collected during the compilation. -uftag.mc will contain mc connected data. -uftag.struct will contain structure related data. -uftag.page will contain page data -uftag.tables contains also data from mc and struct (from older code). This needs cleaning up. +ltx.__tag.mc will contain mc connected data. +ltx.__tag.struct will contain structure related data. +ltx.__tag.page will contain page data +ltx.__tag.tables contains also data from mc and struct (from older code). This needs cleaning up. There are certainly dublettes, but I don't dare yet ... -uftag.func will contain (public) functions. -uftag.trace will contain tracing/loging functions. +ltx.__tag.func will contain (public) functions. +ltx.__tag.trace will contain tracing/loging functions. local funktions starts with __ +functions meant for users will be in ltx.tag functions - uftag.func.get_num_from (tag): takes a tag (string) and returns the id number - uftag.func.output_num_from (tag): takes a tag (string) and prints (to tex) the id number - uftag.func.get_tag_from (num): takes a num and returns the tag - uftag.func.output_tag_from (num): takes a num and prints (to tex) the tag - uftag.func.store_mc_data (num,key,data): stores key=data in uftag.mc[num] - uftag.func.store_mc_label (label,num): stores label=num in uftag.mc.labels - uftag.func.store_mc_kid (mcnum,kid,page): stores the mc-kids of mcnum on page page - uftag.func.store_mc_in_page(mcnum,mcpagecnt,page): stores in the page table the number of mcnum on this page - uftag.func.store_struct_mcabs (structnum,mcnum): stores relations structnum<->mcnum (abs) - uftag.func.mc_insert_kids (mcnum): inserts the /K entries for mcnum by wandering throught the [kids] table - uftag.func.mark_page_elements(box,mcpagecnt,mccntprev,mcopen,name,mctypeprev) : the main function - uftag.func.mark_shipout (): a wrapper around the core function which inserts the last EMC - uftag.func.fill_parent_tree_line (page): outputs the entries of the parenttree for this page - uftag.func.output_parenttree(): outputs the content of the parenttree - uftag.func.markspaceon(), uftag.func.markspaceoff(): (de)activates the marking of positions for space chars - uftag.trace.show_mc_data (num): shows uftag.mc[num] - uftag.trace.show_all_mc_data (max): shows a maximum about mc's - uftag.trace.show_seq: shows a sequence (array) - uftag.trace.show_struct_data (num): shows data of structure num - uftag.trace.show_prop: shows a prop - uftag.trace.log - uftag.trace.showspaces : boolean + ltx.__tag.func.get_num_from (tag): takes a tag (string) and returns the id number + ltx.__tag.func.output_num_from (tag): takes a tag (string) and prints (to tex) the id number + ltx.__tag.func.get_tag_from (num): takes a num and returns the tag + ltx.__tag.func.output_tag_from (num): takes a num and prints (to tex) the tag + ltx.__tag.func.store_mc_data (num,key,data): stores key=data in ltx.__tag.mc[num] + ltx.__tag.func.store_mc_label (label,num): stores label=num in ltx.__tag.mc.labels + ltx.__tag.func.store_mc_kid (mcnum,kid,page): stores the mc-kids of mcnum on page page + ltx.__tag.func.store_mc_in_page(mcnum,mcpagecnt,page): stores in the page table the number of mcnum on this page + ltx.__tag.func.store_struct_mcabs (structnum,mcnum): stores relations structnum<->mcnum (abs) + ltx.__tag.func.mc_insert_kids (mcnum): inserts the /K entries for mcnum by wandering throught the [kids] table + ltx.__tag.func.mark_page_elements(box,mcpagecnt,mccntprev,mcopen,name,mctypeprev) : the main function + ltx.__tag.func.mark_shipout (): a wrapper around the core function which inserts the last EMC + ltx.__tag.func.fill_parent_tree_line (page): outputs the entries of the parenttree for this page + ltx.__tag.func.output_parenttree(): outputs the content of the parenttree + ltx.__tag.func.markspaceon(), ltx.__tag.func.markspaceoff(): (de)activates the marking of positions for space chars + ltx.__tag.trace.show_mc_data (num): shows ltx.__tag.mc[num] + ltx.__tag.trace.show_all_mc_data (max): shows a maximum about mc's + ltx.__tag.trace.show_seq: shows a sequence (array) + ltx.__tag.trace.show_struct_data (num): shows data of structure num + ltx.__tag.trace.show_prop: shows a prop + ltx.__tag.trace.log + ltx.__tag.trace.showspaces : boolean --]] -local mctypeattributeid = luatexbase.registernumber ("l__uftag_mc_type_attr") -local mccntattributeid = luatexbase.registernumber ("l__uftag_mc_cnt_attr") -local iwspaceattributeid = luatexbase.registernumber ("g__uftag_interwordspace_attr") -local iwfontattributeid = luatexbase.registernumber ("g__uftag_interwordfont_attr") - +local mctypeattributeid = luatexbase.registernumber ("l__tag_mc_type_attr") +local mccntattributeid = luatexbase.registernumber ("l__tag_mc_cnt_attr") +local iwspaceattributeid = luatexbase.registernumber ("g__tag_interwordspace_attr") +local iwfontattributeid = luatexbase.registernumber ("g__tag_interwordfont_attr") local catlatex = luatexbase.registernumber("catcodetable@latex") -local tagunmarkedbool= token.create("g__uftag_tagunmarked_bool") -local truebool = token.create("c_true_bool") +local tagunmarkedbool= token.create("g__tag_tagunmarked_bool") +local truebool = token.create("c_true_bool") -local tableinsert = table.insert +local tableinsert = table.insert -- not all needed, copied from lua-visual-debug. local nodeid = node.id @@ -87,7 +106,7 @@ local nodetraverseid = node.traverse_id local nodetraverse = node.traverse local nodeinsertafter = node.insert_after local nodeinsertbefore = node.insert_before -local pdfpageref = pdf.pageref +local pdfpageref = pdf.pageref local HLIST = node.id("hlist") local VLIST = node.id("vlist") @@ -100,46 +119,43 @@ local PENALTY = node.id("penalty") local LOCAL_PAR = node.id("local_par") local MATH = node.id("math") -local function __uftag_get_mathsubtype (mathnode) +local function __tag_get_mathsubtype (mathnode) if mathnode.subtype == 0 then subtype = "beginmath" - else + else subtype = "endmath" - end + end return subtype -end - - +end -uftag = uftag or { } -uftag.mc = uftag.mc or { } -- mc data -uftag.struct = uftag.struct or { } -- struct data -uftag.tables = uftag.tables or { } -- tables created with new prop and new seq. +ltx = ltx or { } +ltx.__tag = ltx.__tag or { } +ltx.__tag.mc = ltx.__tag.mc or { } -- mc data +ltx.__tag.struct = ltx.__tag.struct or { } -- struct data +ltx.__tag.tables = ltx.__tag.tables or { } -- tables created with new prop and new seq. -- wasn't a so great idea ... -uftag.page = uftag.page or { } -- page data, currently only i->{0->mcnum,1->mcnum,...} -uftag.trace = uftag.trace or { } -- show commands -uftag.func = uftag.func or { } -- functions -uftag.conf = uftag.conf or { } -- configuration variables +ltx.__tag.page = ltx.__tag.page or { } -- page data, currently only i->{0->mcnum,1->mcnum,...} +ltx.__tag.trace = ltx.__tag.trace or { } -- show commands +ltx.__tag.func = ltx.__tag.func or { } -- functions +ltx.__tag.conf = ltx.__tag.conf or { } -- configuration variables -local __uftag_log = +local __tag_log = function (message,loglevel) - if (loglevel or 3) <= tex.count["l__uftag_loglevel_int"] then + if (loglevel or 3) <= tex.count["l__tag_loglevel_int"] then texio.write_nl("tagpdf: ".. message) end - end - -uftag.trace.log = __uftag_log + end +ltx.__tag.trace.log = __tag_log -local __uftag_get_mc_cnt_type_tag = function (n) +local __tag_get_mc_cnt_type_tag = function (n) local mccnt = nodegetattribute(n,mccntattributeid) or -1 local mctype = nodegetattribute(n,mctypeattributeid) or -1 - local tag = uftag.func.get_tag_from(mctype) + local tag = ltx.__tag.func.get_tag_from(mctype) return mccnt,mctype,tag end - -local function __uftag_insert_emc_node (head,current) +local function __tag_insert_emc_node (head,current) local emcnode = nodenew("whatsit","pdf_literal") emcnode.data = "EMC" emcnode.mode=1 @@ -147,8 +163,7 @@ local function __uftag_insert_emc_node (head,current) return head end - -local function __uftag_insert_bmc_node (head,current,tag) +local function __tag_insert_bmc_node (head,current,tag) local bmcnode = nodenew("whatsit","pdf_literal") bmcnode.data = "/"..tag.." BMC" bmcnode.mode=1 @@ -156,7 +171,7 @@ local function __uftag_insert_bmc_node (head,current,tag) return head end -local function __uftag_insert_bdc_node (head,current,tag,dict) +local function __tag_insert_bdc_node (head,current,tag,dict) local bdcnode = nodenew("whatsit","pdf_literal") bdcnode.data = "/"..tag.."<<"..dict..">> BDC" bdcnode.mode=1 @@ -165,9 +180,9 @@ local function __uftag_insert_bdc_node (head,current,tag,dict) end -- this is for debugging the space chars -local function __uftag_show_spacemark (head,current,color,height) +local function __tag_show_spacemark (head,current,color,height) local markcolor = color or "1 0 0" - local markheight = height or 10 + local markheight = height or 10 local pdfstring = node.new("whatsit","pdf_literal") pdfstring.data = string.format("q "..markcolor.." RG "..markcolor.." rg 0.4 w 0 %g m 0 %g l S Q",-3,markheight) @@ -177,9 +192,9 @@ end --[[ a function to mark up places where real space chars should be inserted it only sets an attribute. ---]] +--]] -local function __uftag_mark_spaces (head) +local function __tag_mark_spaces (head) local inside_math = false for n in nodetraverse(head) do local id = n.id @@ -190,31 +205,31 @@ local function __uftag_mark_spaces (head) then nodesetattribute(glyph.next,iwspaceattributeid,1) nodesetattribute(glyph.next,iwfontattributeid,glyph.font) - -- for debugging - if uftag.trace.showspaces then - __uftag_show_spacemark (head,glyph) - end + -- for debugging + if ltx.__tag.trace.showspaces then + __tag_show_spacemark (head,glyph) + end elseif glyph.next and (glyph.next.id==KERN) and not inside_math then local kern = glyph.next - if kern.next and (kern.next.id== GLUE) and (kern.next.width >0) + if kern.next and (kern.next.id== GLUE) and (kern.next.width >0) then nodesetattribute(kern.next,iwspaceattributeid,1) nodesetattribute(kern.next,iwfontattributeid,glyph.font) - end + end end elseif id == PENALTY then local glyph = n - -- uftag.trace.log ("PENALTY ".. n.subtype.."VALUE"..n.penalty,3) + -- ltx.__tag.trace.log ("PENALTY ".. n.subtype.."VALUE"..n.penalty,3) if glyph.next and (glyph.next.id == GLUE) and not inside_math and (glyph.next.width >0) and n.subtype==0 then nodesetattribute(glyph.next,iwspaceattributeid,1) -- nodesetattribute(glyph.next,iwfontattributeid,glyph.font) - -- for debugging - if uftag.trace.showspaces then - __uftag_show_spacemark (head,glyph) - end - end + -- for debugging + if ltx.__tag.trace.showspaces then + __tag_show_spacemark (head,glyph) + end + end elseif id == MATH then inside_math = (n.subtype == 0) end @@ -222,30 +237,30 @@ local function __uftag_mark_spaces (head) return head end -local function __uftag_activate_mark_space () +local function __tag_activate_mark_space () if not luatexbase.in_callback ("pre_linebreak_filter","markspaces") then - luatexbase.add_to_callback("pre_linebreak_filter",__uftag_mark_spaces,"markspaces") - luatexbase.add_to_callback("hpack_filter",__uftag_mark_spaces,"markspaces") - end + luatexbase.add_to_callback("pre_linebreak_filter",__tag_mark_spaces,"markspaces") + luatexbase.add_to_callback("hpack_filter",__tag_mark_spaces,"markspaces") + end end -uftag.func.markspaceon=__uftag_activate_mark_space +ltx.__tag.func.markspaceon=__tag_activate_mark_space -local function __uftag_deactivate_mark_space () +local function __tag_deactivate_mark_space () if luatexbase.in_callback ("pre_linebreak_filter","markspaces") then luatexbase.remove_from_callback("pre_linebreak_filter","markspaces") luatexbase.remove_from_callback("hpack_filter","markspaces") end end -- -uftag.func.markspaceoff=__uftag_deactivate_mark_space +ltx.__tag.func.markspaceoff=__tag_deactivate_mark_space local default_space_char = node.new(GLYPH) local default_fontid = font.id("TU/lmr/m/n/10") default_space_char.char = 32 default_space_char.font = default_fontid -local function __uftag_insert_space_char (head,n,fontid) +local function __tag_insert_space_char (head,n,fontid) if luaotfload.aux.slot_of_name(fontid,"space") then local space -- head, space = node.insert_before(head, n, ) -- Set the right font @@ -258,167 +273,168 @@ end Now follows the core function It wades through the shipout box and checks the attributes ARGUMENTS - box: is a box, + box: is a box, mcpagecnt: num, the current page cnt of mc (should start at -1 in shipout box), needed for recursion mccntprev: num, the attribute cnt of the previous node/whatever - if different we have a chunk border - mcopen: num, records if some bdc/emc is open + mcopen: num, records if some bdc/emc is open These arguments are only needed for log messages, if not present are replaces by fix strings: name: string to describe the box mctypeprev: num, the type attribute of the previous node/whatever - + there are lots of logging messages currently. Should be cleaned up in due course. One should also find ways to make the function shorter. --]] -function uftag.func.mark_page_elements (box,mcpagecnt,mccntprev,mcopen,name,mctypeprev) +function ltx.__tag.func.mark_page_elements (box,mcpagecnt,mccntprev,mcopen,name,mctypeprev) local name = name or ("SOMEBOX") local mctypeprev = mctypeprev or -1 - local abspage = tex.count["g__uftag_abspage_int"] --["c@abspage"] - uftag.trace.log ("PAGE " .. abspage,3) - uftag.trace.log ("FUNC ARGS: pagecnt".. mcpagecnt.." prev "..mccntprev .. " type prev "..mctypeprev,4) - uftag.trace.log ("TRAVERSING BOX ".. tostring(name).." TYPE ".. node.type(node.getid(box)),3) - local head = box.head -- AtBeginShipoutBox is a vlist? + local abspage = status.total_pages + 1 -- the real counter is increased inside the box so one off + -- if the callback is not used. + ltx.__tag.trace.log ("PAGE " .. abspage,3) + ltx.__tag.trace.log ("FUNC ARGS: pagecnt".. mcpagecnt.." prev "..mccntprev .. " type prev "..mctypeprev,4) + ltx.__tag.trace.log ("TRAVERSING BOX ".. tostring(name).." TYPE ".. node.type(node.getid(box)),3) + local head = box.head -- ShipoutBox is a vlist? if head then - mccnthead, mctypehead,taghead = __uftag_get_mc_cnt_type_tag (head) - uftag.trace.log ("HEAD " .. node.type(node.getid(head)).. " MC"..tostring(mccnthead).." => TAG "..tostring(mctypehead).." => "..tostring(taghead),3) + mccnthead, mctypehead,taghead = __tag_get_mc_cnt_type_tag (head) + ltx.__tag.trace.log ("HEAD " .. node.type(node.getid(head)).. " MC"..tostring(mccnthead).." => TAG "..tostring(mctypehead).." => "..tostring(taghead),3) else - uftag.trace.log ("HEAD is ".. tostring(head),3) - end + ltx.__tag.trace.log ("HEAD is ".. tostring(head),3) + end for n in node.traverse(head) do - local mccnt, mctype, tag = __uftag_get_mc_cnt_type_tag (n) + local mccnt, mctype, tag = __tag_get_mc_cnt_type_tag (n) local spaceattr = nodegetattribute(n,iwspaceattributeid) or -1 - uftag.trace.log ("NODE ".. node.type(node.getid(n)).." MC"..tostring(mccnt).." => TAG "..tostring(mctype).." => " .. tostring(tag),3) + ltx.__tag.trace.log ("NODE ".. node.type(node.getid(n)).." MC"..tostring(mccnt).." => TAG "..tostring(mctype).." => " .. tostring(tag),3) if n.id == HLIST then -- enter the hlist - mcopen,mcpagecnt,mccntprev,mctypeprev= - uftag.func.mark_page_elements (n,mcpagecnt,mccntprev,mcopen,"INTERNAL HLIST",mctypeprev) - elseif n.id == VLIST then -- enter the vlist - mcopen,mcpagecnt,mccntprev,mctypeprev= - uftag.func.mark_page_elements (n,mcpagecnt,mccntprev,mcopen,"INTERNAL VLIST",mctypeprev) - elseif n.id == GLUE then -- at glue real space chars are inserted, for the rest it is ignored - -- for debugging - if uftag.trace.showspaces and spaceattr==1 then - __uftag_show_spacemark (head,n,"0 1 0") + mcopen,mcpagecnt,mccntprev,mctypeprev= + ltx.__tag.func.mark_page_elements (n,mcpagecnt,mccntprev,mcopen,"INTERNAL HLIST",mctypeprev) + elseif n.id == VLIST then -- enter the vlist + mcopen,mcpagecnt,mccntprev,mctypeprev= + ltx.__tag.func.mark_page_elements (n,mcpagecnt,mccntprev,mcopen,"INTERNAL VLIST",mctypeprev) + elseif n.id == GLUE then -- at glue real space chars are inserted, for the rest it is ignored + -- for debugging + if ltx.__tag.trace.showspaces and spaceattr==1 then + __tag_show_spacemark (head,n,"0 1 0") end - if spaceattr==1 then + if spaceattr==1 then local space local space_char = node.copy(default_space_char) - local curfont = nodegetattribute(n,iwfontattributeid) - uftag.trace.log ("FONT ".. tostring(curfont),3) + local curfont = nodegetattribute(n,iwfontattributeid) + ltx.__tag.trace.log ("FONT ".. tostring(curfont),3) if curfont and luaotfload.aux.slot_of_name(curfont,"space") then space_char.font=curfont end - head, space = node.insert_before(head, n, space_char) -- + head, space = node.insert_before(head, n, space_char) -- n.width = n.width - space.width space.attr = n.attr end - elseif n.id == LOCAL_PAR then -- local_par is ignored + elseif n.id == LOCAL_PAR then -- local_par is ignored elseif n.id == PENALTY then -- penalty is ignored - elseif n.id == KERN then -- kern is ignored - uftag.trace.log ("SUBTYPE KERN ".. n.subtype,3) + elseif n.id == KERN then -- kern is ignored + ltx.__tag.trace.log ("SUBTYPE KERN ".. n.subtype,3) else - -- math is currently only logged. + -- math is currently only logged. -- we could mark the whole as math -- for inner processing the mlist_to_hlist callback is probably needed. - if n.id == MATH then - uftag.trace.log("NODE "..node.type(node.getid(n)).." "..__uftag_get_mathsubtype(n),3) + if n.id == MATH then + ltx.__tag.trace.log("NODE "..node.type(node.getid(n)).." "..__tag_get_mathsubtype(n),3) end -- endmath - uftag.trace.log("CURRENT "..mccnt.." PREV "..mccntprev,3) + ltx.__tag.trace.log("CURRENT "..mccnt.." PREV "..mccntprev,3) if mccnt~=mccntprev then -- a new mc chunk - uftag.trace.log ("NODE ".. node.type(node.getid(n)).." MC"..tostring(mccnt).." <=> PREVIOUS "..tostring(mccntprev),3) + ltx.__tag.trace.log ("NODE ".. node.type(node.getid(n)).." MC"..tostring(mccnt).." <=> PREVIOUS "..tostring(mccntprev),3) if mcopen~=0 then -- there is a chunk open, close it (hope there is only one ... - box.list=__uftag_insert_emc_node (box.list,n) + box.list=__tag_insert_emc_node (box.list,n) mcopen = mcopen - 1 - uftag.trace.log ("INSERT EMC " .. mcpagecnt .. " MCOPEN = " .. mcopen,2) + ltx.__tag.trace.log ("INSERT EMC " .. mcpagecnt .. " MCOPEN = " .. mcopen,2) if mcopen ~=0 then - uftag.trace.log ("!WARNING! open mc" .. " MCOPEN = " .. mcopen,1) - end - end - if uftag.mc[mccnt] then - if uftag.mc[mccnt]["artifact"] then - uftag.trace.log("THIS IS AN ARTIFACT of type "..tostring(uftag.mc[mccnt]["artifact"]),3) - if uftag.mc[mccnt]["artifact"] == "" then - box.list = __uftag_insert_bmc_node (box.list,n,"Artifact") + ltx.__tag.trace.log ("!WARNING! open mc" .. " MCOPEN = " .. mcopen,1) + end + end + if ltx.__tag.mc[mccnt] then + if ltx.__tag.mc[mccnt]["artifact"] then + ltx.__tag.trace.log("THIS IS AN ARTIFACT of type "..tostring(ltx.__tag.mc[mccnt]["artifact"]),3) + if ltx.__tag.mc[mccnt]["artifact"] == "" then + box.list = __tag_insert_bmc_node (box.list,n,"Artifact") else - box.list = __uftag_insert_bdc_node (box.list,n,"Artifact", "/Type /"..uftag.mc[mccnt]["artifact"]) + box.list = __tag_insert_bdc_node (box.list,n,"Artifact", "/Type /"..ltx.__tag.mc[mccnt]["artifact"]) end else - uftag.trace.log("THIS IS A TAG "..tostring(tag),3) + ltx.__tag.trace.log("THIS IS A TAG "..tostring(tag),3) mcpagecnt = mcpagecnt +1 - uftag.trace.log ("INSERT BDC "..mcpagecnt,2) + ltx.__tag.trace.log ("INSERT BDC "..mcpagecnt,2) local dict= "/MCID "..mcpagecnt - if uftag.mc[mccnt]["raw"] then - uftag.trace.log("RAW CONTENT"..tostring(uftag.mc[mccnt]["raw"]),3) - dict= dict .. " " .. uftag.mc[mccnt]["raw"] - end - if uftag.mc[mccnt]["alt"] then - uftag.trace.log("RAW CONTENT"..tostring(uftag.mc[mccnt]["alt"]),3) - dict= dict .. " " .. uftag.mc[mccnt]["alt"] - end - if uftag.mc[mccnt]["actualtext"] then - uftag.trace.log("RAW CONTENT"..tostring(uftag.mc[mccnt]["actualtext"]),3) - dict= dict .. " " .. uftag.mc[mccnt]["actualtext"] - end - box.list = __uftag_insert_bdc_node (box.list,n,tag, dict) - uftag.func.store_mc_kid (mccnt,mcpagecnt,abspage) - uftag.func.store_mc_in_page(mccnt,mcpagecnt,abspage) - uftag.trace.show_mc_data (mccnt) - end + if ltx.__tag.mc[mccnt]["raw"] then + ltx.__tag.trace.log("RAW CONTENT"..tostring(ltx.__tag.mc[mccnt]["raw"]),3) + dict= dict .. " " .. ltx.__tag.mc[mccnt]["raw"] + end + if ltx.__tag.mc[mccnt]["alt"] then + ltx.__tag.trace.log("RAW CONTENT"..tostring(ltx.__tag.mc[mccnt]["alt"]),3) + dict= dict .. " " .. ltx.__tag.mc[mccnt]["alt"] + end + if ltx.__tag.mc[mccnt]["actualtext"] then + ltx.__tag.trace.log("RAW CONTENT"..tostring(ltx.__tag.mc[mccnt]["actualtext"]),3) + dict= dict .. " " .. ltx.__tag.mc[mccnt]["actualtext"] + end + box.list = __tag_insert_bdc_node (box.list,n,tag, dict) + ltx.__tag.func.store_mc_kid (mccnt,mcpagecnt,abspage) + ltx.__tag.func.store_mc_in_page(mccnt,mcpagecnt,abspage) + ltx.__tag.trace.show_mc_data (mccnt) + end mcopen = mcopen + 1 else - uftag.trace.log("THIS HAS NOT BEEN TAGGED",1) - -- perhaps code that tag a artifact can be added ... + ltx.__tag.trace.log("THIS HAS NOT BEEN TAGGED",1) + -- perhaps code that tag a artifact can be added ... if tagunmarkedbool.mode == truebool.mode then - box.list = __uftag_insert_bmc_node (box.list,n,"Artifact") - end - mcopen = mcopen + 1 + box.list = __tag_insert_bmc_node (box.list,n,"Artifact") + mcopen = mcopen + 1 + end end mccntprev = mccnt - end + end end -- end if end -- end for if head then - mccnthead, mctypehead,taghead = __uftag_get_mc_cnt_type_tag (head) - uftag.trace.log ("ENDHEAD " .. node.type(node.getid(head)).. " MC"..tostring(mccnthead).." => TAG "..tostring(mctypehead).." => "..tostring(taghead),3) + mccnthead, mctypehead,taghead = __tag_get_mc_cnt_type_tag (head) + ltx.__tag.trace.log ("ENDHEAD " .. node.type(node.getid(head)).. " MC"..tostring(mccnthead).." => TAG "..tostring(mctypehead).." => "..tostring(taghead),3) else - uftag.trace.log ("ENDHEAD is ".. tostring(head),3) - end - uftag.trace.log ("QUITTING TRAVERSING BOX ".. tostring(name).." TYPE ".. node.type(node.getid(box)),3) + ltx.__tag.trace.log ("ENDHEAD is ".. tostring(head),3) + end + ltx.__tag.trace.log ("QUITTING TRAVERSING BOX ".. tostring(name).." TYPE ".. node.type(node.getid(box)),3) return mcopen,mcpagecnt,mccntprev,mctypeprev -end +end -function uftag.func.mark_shipout () - mcopen = uftag.func.mark_page_elements (tex.box["AtBeginShipoutBox"],-1,-100,0,"Shipout",-1) +function ltx.__tag.func.mark_shipout (box) + mcopen = ltx.__tag.func.mark_page_elements (box,-1,-100,0,"Shipout",-1) if mcopen~=0 then -- there is a chunk open, close it (hope there is only one ... local emcnode = nodenew("whatsit","pdf_literal") - local box = tex.box["AtBeginShipoutBox"].list + local list = box.list emcnode.data = "EMC" emcnode.mode=1 - if box then - box = node.insert_after (box,node.tail(box),emcnode) + if list then + list = node.insert_after (list,node.tail(list),emcnode) mcopen = mcopen - 1 - uftag.trace.log ("INSERT LAST EMC, MCOPEN = " .. mcopen,2) + ltx.__tag.trace.log ("INSERT LAST EMC, MCOPEN = " .. mcopen,2) else - uftag.trace.log ("UPS ",1) + ltx.__tag.trace.log ("UPS ",1) end if mcopen ~=0 then - uftag.trace.log ("!WARNING! open mc" .. " MCOPEN = " .. mcopen,1) - end + ltx.__tag.trace.log ("!WARNING! open mc" .. " MCOPEN = " .. mcopen,1) + end end end -function uftag.trace.show_seq (seq) +function ltx.__tag.trace.show_seq (seq) if (type(seq) == "table") then - for i,v in ipairs(seq) do - __uftag_log ("[" .. i .. "] => " .. tostring(v),1) - end - else - __uftag_log ("sequence " .. tostring(seq) .. " not found",1) - end -end - -local __uftag_pairs_prop = + for i,v in ipairs(seq) do + __tag_log ("[" .. i .. "] => " .. tostring(v),1) + end + else + __tag_log ("sequence " .. tostring(seq) .. " not found",1) + end +end + +local __tag_pairs_prop = function (prop) local a = {} for n in pairs(prop) do tableinsert(a, n) end @@ -433,201 +449,202 @@ local __uftag_pairs_prop = return iter end - -function uftag.trace.show_prop (prop) +function ltx.__tag.trace.show_prop (prop) if (type(prop) == "table") then - for i,v in __uftag_pairs_prop (prop) do - __uftag_log ("[" .. i .. "] => " .. tostring(v),1) - end - else - __uftag_log ("prop " .. tostring(prop) .. " not found or not a table",1) - end - end - + for i,v in __tag_pairs_prop (prop) do + __tag_log ("[" .. i .. "] => " .. tostring(v),1) + end + else + __tag_log ("prop " .. tostring(prop) .. " not found or not a table",1) + end + end -local __uftag_get_num_from = +local __tag_get_num_from = function (tag) - if uftag.tables["g__uftag_role_tags_prop"][tag] then - a= uftag.tables["g__uftag_role_tags_prop"][tag] + if ltx.__tag.tables["g__tag_role_tags_prop"][tag] then + a= ltx.__tag.tables["g__tag_role_tags_prop"][tag] else - a= -1 + a= -1 end - return a - end - -uftag.func.get_num_from = __uftag_get_num_from + return a + end + +ltx.__tag.func.get_num_from = __tag_get_num_from -function uftag.func.output_num_from (tag) - local num = __uftag_get_num_from (tag) +function ltx.__tag.func.output_num_from (tag) + local num = __tag_get_num_from (tag) tex.sprint(catlatex,num) if num == -1 then - __uftag_log ("Unknown tag "..tag.." used") + __tag_log ("Unknown tag "..tag.." used") end -end - -local __uftag_get_tag_from = +end + +local __tag_get_tag_from = function (num) - if uftag.tables["g__uftag_role_tags_seq"][num] then - a = uftag.tables["g__uftag_role_tags_seq"][num] + if ltx.__tag.tables["g__tag_role_tags_seq"][num] then + a = ltx.__tag.tables["g__tag_role_tags_seq"][num] else a= "UNKNOWN" end return a end -uftag.func.get_tag_from = __uftag_get_tag_from +ltx.__tag.func.get_tag_from = __tag_get_tag_from -function uftag.func.output_tag_from (num) - tex.sprint(catlatex,__uftag_get_tag_from (num)) -end +function ltx.__tag.func.output_tag_from (num) + tex.sprint(catlatex,__tag_get_tag_from (num)) +end -function uftag.func.store_mc_data (num,key,data) - uftag.mc[num] = uftag.mc[num] or { } - uftag.mc[num][key] = data - __uftag_log ("storing mc"..num..": "..tostring(key).."=>"..tostring(data)) +function ltx.__tag.func.store_mc_data (num,key,data) + ltx.__tag.mc[num] = ltx.__tag.mc[num] or { } + ltx.__tag.mc[num][key] = data + __tag_log ("storing mc"..num..": "..tostring(key).."=>"..tostring(data)) end -function uftag.trace.show_mc_data (num) - if uftag and uftag.mc and uftag.mc[num] then - for k,v in pairs(uftag.mc[num]) do - __uftag_log ("mc"..num..": "..tostring(k).."=>"..tostring(v),3) +function ltx.__tag.trace.show_mc_data (num) + if ltx.__tag and ltx.__tag.mc and ltx.__tag.mc[num] then + for k,v in pairs(ltx.__tag.mc[num]) do + __tag_log ("mc"..num..": "..tostring(k).."=>"..tostring(v),3) end - if uftag.mc[num]["kids"] then - __uftag_log ("mc" .. num .. " has " .. #uftag.mc[num]["kids"] .. " kids",3) - for k,v in ipairs(uftag.mc[num]["kids"]) do - __uftag_log ("mc ".. num .. " kid "..k.." =>" .. v.kid.." on page " ..v.page,3) + if ltx.__tag.mc[num]["kids"] then + __tag_log ("mc" .. num .. " has " .. #ltx.__tag.mc[num]["kids"] .. " kids",3) + for k,v in ipairs(ltx.__tag.mc[num]["kids"]) do + __tag_log ("mc ".. num .. " kid "..k.." =>" .. v.kid.." on page " ..v.page,3) end end else - __uftag_log ("mc"..num.." not found",3) + __tag_log ("mc"..num.." not found",3) end end -function uftag.trace.show_all_mc_data (max) - for i = 1, max do - uftag.trace.show_mc_data (i) +function ltx.__tag.trace.show_all_mc_data (max) + for i = 1, max do + ltx.__tag.trace.show_mc_data (i) end -end - +end -function uftag.func.store_mc_label (label,num) - uftag.mc["labels"] = uftag.mc["labels"] or { } - uftag.mc.labels[label] = num +function ltx.__tag.func.store_mc_label (label,num) + ltx.__tag.mc["labels"] = ltx.__tag.mc["labels"] or { } + ltx.__tag.mc.labels[label] = num end -function uftag.func.store_mc_kid (mcnum,kid,page) - uftag.trace.log("MC"..mcnum.." STORING KID" .. kid.." on page " .. page,3) - uftag.mc[mcnum]["kids"] = uftag.mc[mcnum]["kids"] or { } +function ltx.__tag.func.store_mc_kid (mcnum,kid,page) + ltx.__tag.trace.log("MC"..mcnum.." STORING KID" .. kid.." on page " .. page,3) + ltx.__tag.mc[mcnum]["kids"] = ltx.__tag.mc[mcnum]["kids"] or { } local kidtable = {kid=kid,page=page} - tableinsert(uftag.mc[mcnum]["kids"], kidtable ) + tableinsert(ltx.__tag.mc[mcnum]["kids"], kidtable ) end - -function uftag.func.mc_num_of_kids (mcnum) +function ltx.__tag.func.mc_num_of_kids (mcnum) local num = 0 - if uftag.mc[mcnum] and uftag.mc[mcnum]["kids"] then - num = #uftag.mc[mcnum]["kids"] + if ltx.__tag.mc[mcnum] and ltx.__tag.mc[mcnum]["kids"] then + num = #ltx.__tag.mc[mcnum]["kids"] end - uftag.trace.log ("MC" .. mcnum .. "has " .. num .. "KIDS",4) + ltx.__tag.trace.log ("MC" .. mcnum .. "has " .. num .. "KIDS",4) return num end - -function uftag.func.mc_insert_kids (mcnum,single) - if uftag.mc[mcnum] then - uftag.trace.log("MC-KIDS test " .. mcnum,4) - if uftag.mc[mcnum]["kids"] then - if #uftag.mc[mcnum]["kids"] > 1 and single==1 then + +function ltx.__tag.func.mc_insert_kids (mcnum,single) + if ltx.__tag.mc[mcnum] then + ltx.__tag.trace.log("MC-KIDS test " .. mcnum,4) + if ltx.__tag.mc[mcnum]["kids"] then + if #ltx.__tag.mc[mcnum]["kids"] > 1 and single==1 then tex.sprint("[") - end - for i,kidstable in ipairs( uftag.mc[mcnum]["kids"] ) do + end + for i,kidstable in ipairs( ltx.__tag.mc[mcnum]["kids"] ) do local kidnum = kidstable["kid"] local kidpage = kidstable["page"] local kidpageobjnum = pdfpageref(kidpage) - uftag.trace.log("MC" .. mcnum .. " insert KID " ..i.. " with num " .. kidnum .. " on page " .. kidpage.."/"..kidpageobjnum,3) + ltx.__tag.trace.log("MC" .. mcnum .. " insert KID " ..i.. " with num " .. kidnum .. " on page " .. kidpage.."/"..kidpageobjnum,3) tex.sprint(catlatex,"<> " ) - end - if #uftag.mc[mcnum]["kids"] > 1 and single==1 then + end + if #ltx.__tag.mc[mcnum]["kids"] > 1 and single==1 then tex.sprint("]") - end + end else - uftag.trace.log("WARN! MC"..mcnum.." has no kids",0) + ltx.__tag.trace.log("WARN! MC"..mcnum.." has no kids",0) + if single==1 then + tex.sprint("null") + end end else - uftag.trace.log("WARN! MC"..mcnum.." doesn't exist",0) + ltx.__tag.trace.log("WARN! MC"..mcnum.." doesn't exist",0) end end - -function uftag.func.store_struct_mcabs (structnum,mcnum) - uftag.struct[structnum]=uftag.struct[structnum] or { } - uftag.struct[structnum]["mc"]=uftag.struct[structnum]["mc"] or { } +function ltx.__tag.func.store_struct_mcabs (structnum,mcnum) + ltx.__tag.struct[structnum]=ltx.__tag.struct[structnum] or { } + ltx.__tag.struct[structnum]["mc"]=ltx.__tag.struct[structnum]["mc"] or { } -- a structure can contain more than on mc chunk, the content should be ordered - tableinsert(uftag.struct[structnum]["mc"],mcnum) - uftag.trace.log("MCNUM "..mcnum.." insert in struct "..structnum,3) + tableinsert(ltx.__tag.struct[structnum]["mc"],mcnum) + ltx.__tag.trace.log("MCNUM "..mcnum.." insert in struct "..structnum,3) -- but every mc can only be in one structure - uftag.mc[mcnum]= uftag.mc[mcnum] or { } - uftag.mc[mcnum]["parent"] = structnum -end - -function uftag.trace.show_struct_data (num) - if uftag and uftag.struct and uftag.struct[num] then - for k,v in ipairs(uftag.struct[num]) do - __uftag_log ("struct "..num..": "..tostring(k).."=>"..tostring(v)) + ltx.__tag.mc[mcnum]= ltx.__tag.mc[mcnum] or { } + ltx.__tag.mc[mcnum]["parent"] = structnum +end + +function ltx.__tag.trace.show_struct_data (num) + if ltx.__tag and ltx.__tag.struct and ltx.__tag.struct[num] then + for k,v in ipairs(ltx.__tag.struct[num]) do + __tag_log ("struct "..num..": "..tostring(k).."=>"..tostring(v)) end - else - __uftag_log ("struct "..num.." not found ") - end + else + __tag_log ("struct "..num.." not found ") + end end -- pay attention: lua counts arrays from 1, tex pages from one --- mcid and arrays in pdf count from 0. -function uftag.func.store_mc_in_page (mcnum,mcpagecnt,page) - uftag.page[page] = uftag.page[page] or {} - uftag.page[page][mcpagecnt] = mcnum - uftag.trace.log("PAGE " .. page .. ": inserting MCID " .. mcpagecnt .. " => " .. mcnum,3) +-- mcid and arrays in pdf count from 0. +function ltx.__tag.func.store_mc_in_page (mcnum,mcpagecnt,page) + ltx.__tag.page[page] = ltx.__tag.page[page] or {} + ltx.__tag.page[page][mcpagecnt] = mcnum + ltx.__tag.trace.log("PAGE " .. page .. ": inserting MCID " .. mcpagecnt .. " => " .. mcnum,3) end -function uftag.func.fill_parent_tree_line (page) - -- we need to get page-> i=kid -> mcnum -> structnum +function ltx.__tag.func.fill_parent_tree_line (page) + -- we need to get page-> i=kid -> mcnum -> structnum -- pay attention: the kid numbers and the page number in the parent tree start with 0! local numsentry ="" local pdfpage = page-1 - if uftag.page[page] and uftag.page[page][0] then - mcchunks=#uftag.page[page] - uftag.trace.log("PAGETREE PAGE "..page.." has "..mcchunks.."+1 Elements ",3) + if ltx.__tag.page[page] and ltx.__tag.page[page][0] then + mcchunks=#ltx.__tag.page[page] + ltx.__tag.trace.log("PAGETREE PAGE "..page.." has "..mcchunks.."+1 Elements ",3) for i=0,mcchunks do - uftag.trace.log("PAGETREE CHUNKS "..uftag.page[page][i],3) + ltx.__tag.trace.log("PAGETREE CHUNKS "..ltx.__tag.page[page][i],3) end - if mcchunks == 0 then + if mcchunks == 0 then -- only one chunk so no need for an array - local mcnum = uftag.page[page][0] - local structnum = uftag.mc[mcnum]["parent"] - local propname = "g__uftag_struct_"..structnum.."_prop" - local objnum = uftag.tables[propname]["objnum"] or "XXXX" - texio.write_nl("=====>"..tostring(objnum)) - numsentry = pdfpage .. " ".. objnum .. " 0 R" - uftag.trace.log("PAGETREE PAGE" .. page.. " NUM ENTRY = ".. numsentry,3) + local mcnum = ltx.__tag.page[page][0] + local structnum = ltx.__tag.mc[mcnum]["parent"] + local propname = "g__tag_struct_"..structnum.."_prop" + local objref = ltx.__tag.tables[propname]["objref"] or "XXXX" + texio.write_nl("=====>"..tostring(objref)) + numsentry = pdfpage .. " [".. objref .. "]" + ltx.__tag.trace.log("PAGETREE PAGE" .. page.. " NUM ENTRY = ".. numsentry,3) else numsentry = pdfpage .. " [" for i=0,mcchunks do - local mcnum = uftag.page[page][i] - local structnum = uftag.mc[mcnum]["parent"] or 0 - local propname = "g__uftag_struct_"..structnum.."_prop" - local objnum = uftag.tables[propname]["objnum"] or "XXXX" - numsentry = numsentry .. " ".. objnum .. " 0 R" + local mcnum = ltx.__tag.page[page][i] + local structnum = ltx.__tag.mc[mcnum]["parent"] or 0 + local propname = "g__tag_struct_"..structnum.."_prop" + local objref = ltx.__tag.tables[propname]["objref"] or "XXXX" + numsentry = numsentry .. " ".. objref end numsentry = numsentry .. "] " - uftag.trace.log("PAGETREE PAGE" .. page.. " NUM ENTRY = ".. numsentry,3) - end + ltx.__tag.trace.log("PAGETREE PAGE" .. page.. " NUM ENTRY = ".. numsentry,3) + end else - uftag.trace.log ("PAGETREE: NO DATA FOR PAGE "..page,3) + ltx.__tag.trace.log ("PAGETREE: NO DATA FOR PAGE "..page,3) end - return numsentry + return numsentry end -function uftag.func.output_parenttree (abspage) +function ltx.__tag.func.output_parenttree (abspage) for i=1,abspage do - line = uftag.func.fill_parent_tree_line (i) .. "^^J" + line = ltx.__tag.func.fill_parent_tree_line (i) .. "^^J" tex.sprint(catlatex,line) end end + +-- +-- End of File `tagpdf.lua'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdf.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdf.sty index 4163494d313..71daeab6935 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdf.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdf.sty @@ -1,179 +1,247 @@ -\RequirePackage{expl3}[2019/07/01] -%\RequirePackage[enable-debug]{expl3}[2018/06/14] +%% +%% This is file `tagpdf.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tagpdf.dtx (with options: `package') +%% +%% Copyright (C) 2019 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} {2021/02/23} {0.80} + { 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{}\MessageBreak + before~\string\documentclass + } + } -\ProvidesExplPackage {tagpdf} {2019/07/02} {0.61} - {A package to experiment with pdf tagging} -%\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 { uftag }{ tagpdf } - } + { + \prop_gput:Nnn \g_msg_module_name_prop { tag }{ tagpdf } + } -% storing internal names to my name space: -\cs_set_eq:NN \__uftag_tex_pdffeedback:D \tex_pdffeedback:D -\cs_set_eq:NN \__uftag_tex_pdfextension:D \tex_pdfextension:D -\cs_set_eq:NN \__uftag_tex_immediate:D \tex_immediate:D -\cs_set_eq:NN \__uftag_tex_pdfvariable:D \tex_pdfvariable:D -\cs_set_eq:NN \__uftag_tex_global:D \tex_global:D -\cs_set_eq:NN \__uftag_tex_the:D \tex_the:D -\cs_set_eq:NN \__uftag_tex_pdfliteral:D \tex_pdfliteral:D -\cs_set_eq:NN \__uftag_tex_pdfcatalog:D \tex_pdfcatalog:D -\cs_set_eq:NN \__uftag_tex_pdflastobj:D \tex_pdflastobj:D -\cs_set_eq:NN \__uftag_tex_pdfobj:D \tex_pdfobj:D -\cs_set_eq:NN \__uftag_tex_pdfpageattr:D \tex_pdfpageattr:D -\cs_set_eq:NN \__uftag_tex_pdfpagesattr:D \tex_pdfpagesattr:D -\cs_set_eq:NN \__uftag_tex_pdfpageref:D \tex_pdfpageref:D -\cs_set_eq:NN \__uftag_tex_pdfcompresslevel:D \tex_pdfcompresslevel:D -\cs_set_eq:NN \__uftag_tex_pdfobjcompresslevel:D \tex_pdfobjcompresslevel:D +\cs_set_eq:NN \__tag_tex_global:D \tex_global:D %%% package options -\bool_new:N\g__uftag_mode_lua_bool +\bool_new:N\g__tag_mode_lua_bool -\DeclareOption{luamode} { \sys_if_engine_luatex:T { \bool_gset_true:N \g__uftag_mode_lua_bool } } -\DeclareOption{genericmode}{ \bool_gset_false:N\g__uftag_mode_lua_bool } +\DeclareOption {luamode} { \sys_if_engine_luatex:T { \bool_gset_true:N \g__tag_mode_lua_bool } } +\DeclareOption {genericmode}{ \bool_gset_false:N\g__tag_mode_lua_bool } \ExecuteOptions{luamode} \ProcessOptions %%% some packages -\RequirePackage{xparse} -\RequirePackage{atbegshi} -\RequirePackage{zref-base,zref-lastpage} -\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 } - +\RequirePackage{l3ref-tmp} + %================ + % temporary code + % =============== + % faking the LastPage label: + \cs_new_protected:Npn \__tag_lastpagelabel: + { + \legacy_if:nT { @filesw } + { + \exp_args:NNnx \exp_args:NNx\iow_now:Nn \@auxout + { + \token_to_str:N \newlabeldata + {__tag_LastPage} + { + {abspage} { \int_use:N \g_shipout_readonly_int} + {tagmcabs}{ \int_use:N \c@g__tag_MCID_abs_int } + } + } + } + } -%%% absolute page numbers -\int_new:N \g__uftag_abspage_int -\int_gset:Nn \g__uftag_abspage_int { 0 } -\zref@newlist {uftagzrl} %zrl=zreflist -\zref@newprop*{tagabspage} [0] { \int_use:N \g__uftag_abspage_int } -\zref@addprop {uftagzrl} {tagabspage} + \AddToHook{enddocument/afterlastpage} + {\__tag_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 + } + } + } -%%% tagpdfsetup, -%%% TODO: checks need to be improved -\int_new:N \l__uftag_loglevel_int -\tl_new:N \l__uftag_tree_tabs_order_tl - -\keys_define:nn { uftag / setup } -{ - activate-mc .bool_gset:N = \g_uftag_active_mc_bool, - activate-tree .bool_gset:N = \g_uftag_active_tree_bool, - activate-struct .bool_gset:N = \g_uftag_active_struct_bool, - activate-all .meta:n ={activate-mc,activate-tree,activate-struct}, - check-tags .bool_gset:N = \g__uftag_check_tags_bool, - check-tags .initial:n = true, - log .choice:, - log / none .code:n = {\int_set:Nn \l__uftag_loglevel_int { 0 }}, - log / v .code:n = {\int_set:Nn \l__uftag_loglevel_int { 1 }}, - log / vv .code:n = {\int_set:Nn \l__uftag_loglevel_int { 2 }}, - log / vvv .code:n = {\int_set:Nn \l__uftag_loglevel_int { 3 }}, - log / all .code:n = {\int_set:Nn \l__uftag_loglevel_int { 10 }}, - tagunmarked .bool_gset:N = \g__uftag_tagunmarked_bool, - tagunmarked .initial:n = true, - tabsorder .choice:, - tabsorder / row .code:n = {\tl_set:Nn \l__uftag_tree_tabs_order_tl {/Tabs/R}}, - tabsorder / column .code:n = {\tl_set:Nn \l__uftag_tree_tabs_order_tl {/Tabs/C}}, - tabsorder / structure .code:n = {\tl_set:Nn \l__uftag_tree_tabs_order_tl {/Tabs/S}}, - tabsorder / none .code:n = {\tl_set:Nn \l__uftag_tree_tabs_order_tl {}}, - tabsorder .initial:n = structure, - uncompress .code:n = {\pdf_uncompress: }, - inputencoding .code:n = + %============= + % attributes + %============= +\ref_attribute_gset:nnnn {tagstruct} {0}{now} { \int_use:N \c@g__tag_struct_abs_int } +\ref_attribute_gset:nnnn {tagstructobj} {}{now} + { + \exp_args:Ne + \pdf_object_if_exist:nT {c__tag_struct_ \int_use:N \c@g__tag_struct_abs_int _obj} + { + \pdf_object_ref:e{c__tag_struct_ \int_use:N \c@g__tag_struct_abs_int _obj} + } + } + % 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__tag_MCID_abs_int } +\ref_attribute_gset:nnnn {tagmcid } {0}{now} { \int_use:N \g__tag_MCID_tmp_bypage_int } +\clist_const:Nn \c__tag_refmc_clist {tagabspage,tagmcabs,tagmcid} %mc is new!! +\clist_const:Nn \c__tag_refstruct_clist {tagstruct,tagstructobj} +\cs_generate_variant:Nn \ref_label:nn { nv } +\cs_new_protected:Npn \__tag_ref_label:nn #1 #2 %#1 label, #2 name of list mc or struct + { + \@bsphack + \ref_label:nv {#1}{c__tag_ref#2_clist} + \@esphack + } +\cs_new:Npn \__tag_ref_value:nnn #1 #2 #3 %#1 label, #2 attribute, #3 default + { + \ref_value:nnn {#1}{#2}{#3} + } +\cs_new:Npn \__tag_ref_value_lastpage:nn #1 #2 { - \sys_if_engine_pdftex:T - { \tl_gset:Nn \g__uftag_inputencoding_tl { #1 } } - }, -} + \ref_value:nnn {__tag_LastPage}{#1}{#2} + } -% 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 \__uftag_pdf_escape_string:Nn \EdefEscapeString -%\cs_set_eq:NN \__uftag_pdf_escape_name:Nn \EdefEscapeName -%\cs_set_eq:NN \__uftag_pdf_escape_hex:Nn \EdefEscapeHex +\cs_generate_variant:Nn \__tag_ref_label:nn {en} +\cs_generate_variant:Nn \__tag_ref_value:nnn {enn} -%\cs_set_eq:NN \__uftag_pdf_escape_string:n \EdefEscapeString -%\cs_set_eq:NN \__uftag_pdf_escape_name:Nn \EdefEscapeName +\RequirePackage{etoolbox} -%escape command. They are backend specific as \pdf@escapehex would ignore most chars -%outside the "pdflatex" range +\cs_generate_variant:Nn \str_set_convert:Nnnn {Nonn, Noon, Nnon } +%%% tagpdfsetup, +%%% TODO: checks need to be improved +\int_new:N \l__tag_loglevel_int +\tl_new:N \l__tag_tree_tabs_order_tl +\keys_define:nn { __tag / setup } + { + activate-mc .bool_gset:N = \g__tag_active_mc_bool, + activate-tree .bool_gset:N = \g__tag_active_tree_bool, + activate-struct .bool_gset:N = \g__tag_active_struct_bool, + activate-all .meta:n ={activate-mc,activate-tree,activate-struct}, + check-tags .bool_gset:N = \g__tag_check_tags_bool, + check-tags .initial:n = true, + log .choice:, + log / none .code:n = {\int_set:Nn \l__tag_loglevel_int { 0 }}, + log / v .code:n = {\int_set:Nn \l__tag_loglevel_int { 1 }}, + log / vv .code:n = {\int_set:Nn \l__tag_loglevel_int { 2 }}, + log / vvv .code:n = {\int_set:Nn \l__tag_loglevel_int { 3 }}, + log / all .code:n = {\int_set:Nn \l__tag_loglevel_int { 10 }}, + tagunmarked .bool_gset:N = \g__tag_tagunmarked_bool, + tagunmarked .initial:n = true, + tabsorder .choice:, + tabsorder / row .code:n = %{\tl_set:Nn \l__tag_tree_tabs_order_tl {/Tabs/R}}, + \pdfmanagement_add:nnn { Page } {Tabs}{/R}, + tabsorder / column .code:n = %{\tl_set:Nn \l__tag_tree_tabs_order_tl {/Tabs/C}}, + \pdfmanagement_add:nnn { Page } {Tabs}{/C}, + tabsorder / structure .code:n = %{\tl_set:Nn \l__tag_tree_tabs_order_tl {/Tabs/S}}, + \pdfmanagement_add:nnn { Page } {Tabs}{/S}, + tabsorder / none .code:n = %{\tl_set:Nn \l__tag_tree_tabs_order_tl {}}, + \pdfmanagement_remove:nn {Page} {Tabs}, + tabsorder .initial:n = structure, + uncompress .code:n = {\pdf_uncompress: }, + } +\hook_gput_code:nnn{begindocument}{tagpdf} + { + \bool_if:NT \g__tag_active_struct_bool + { + \pdfmanagement_add:nnn { Catalog / MarkInfo } { Marked } { true } + } + } -% a hook for later code and an absolute page counter -% should be executed before counters are resetted. -% is it used? -\cs_new:Nn \__uftag_finish_page_hook: { } +\cs_new:Nn \__tag_finish_page_hook: { } -\AtBeginShipout - { - \__uftag_finish_page_hook: - \bool_if:NT\g_uftag_active_tree_bool - { - \__uftag_tree_write_pageattr: - } - \int_gincr:N \g__uftag_abspage_int - } +\hook_gput_code:nnn + { shipout/before } + { tagpdf/cnt } + { + \__tag_finish_page_hook: + %\int_gincr:N \g__tag_abspage_int + } -%testing the engines and loading the backend files \sys_if_engine_xetex:T - { - \PackageError { tagpdf } { xelatex~is~not~supported~-~aborting } {} - \tex_endinput:D - } + { %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} - } + { + \file_input:n {tagpdf-luatex.def} + } \sys_if_engine_pdftex:T - { - \file_input:n {tagpdf-pdftex.def} - } + { + \file_input:n {tagpdf-pdftex.def} + } \sys_if_output_dvi:T - { - \PackageError { tagpdf } { dvi~output~is~not~supported~-~aborting }{} - \tex_endinput:D - } + { + %\PackageError { tagpdf } { dvi~output~is~not~supported~-~aborting }{} + %\tex_endinput:D + } -\cs_generate_variant:Nn \__uftag_prop_gput:Nnn { Nxn , Nxx, Nnx , cnn, cxn, cnx, cno} -\cs_generate_variant:Nn \__uftag_seq_gput_right:Nn { Nx , No, cn, cx } -\cs_generate_variant:Nn \__uftag_prop_new:N { c } -\cs_generate_variant:Nn \__uftag_seq_new:N { c } -\cs_generate_variant:Nn \__uftag_seq_show:N { c } -\cs_generate_variant:Nn \__uftag_prop_show:N { c } +\cs_generate_variant:Nn \__tag_prop_gput:Nnn { Nxn , Nxx, Nnx , cnn, cxn, cnx, cno} +\cs_generate_variant:Nn \__tag_seq_gput_right:Nn { Nx , No, cn, cx } +\cs_generate_variant:Nn \__tag_prop_new:N { c } +\cs_generate_variant:Nn \__tag_seq_new:N { c } +\cs_generate_variant:Nn \__tag_seq_show:N { c } +\cs_generate_variant:Nn \__tag_prop_show:N { c } \cs_generate_variant:Nn \prop_gput:Nnn {Nxx} \cs_generate_variant:Nn \prop_put:Nnn {Nxx} -\cs_generate_variant:Nn \__uftag_pdfuseobjnum:Nn {Nx,No} -\cs_generate_variant:Nn \__uftag_pdfuseobjnum:nn {nx,xx} -\cs_generate_variant:Nn \__uftag_gset_pdfpageattr:n {x} - -% few temp tl -\tl_new:N \g__uftag_tmpa_tl -\tl_new:N \l__uftag_tmpa_tl -\tl_new:N \l__uftag_tmpb_tl -\tl_new:N \l__uftag_tmpc_tl -\tl_new:N \l__uftag_tmpd_tl -\tl_new:N \l__uftag_tmpe_tl -\str_new:N \l__uftag_tmpa_str - -% helper function to get the propcount. -% use as \prop_map_function:NN PROP { \__uftag_prop_count:nn -1 } -\cs_new:Nn\__uftag_prop_count:nn { + 1 } + +\cs_generate_variant:Nn \pdffile_embed_stream:nnn {nxx,oxx} +\cs_generate_variant:Nn \pdf_object_ref:n {e} + +\tl_new:N \g__tag_tmpa_tl +\tl_new:N \l__tag_tmpa_tl +\tl_new:N \l__tag_tmpb_tl +\tl_new:N \l__tag_tmpc_tl +\tl_new:N \l__tag_tmpd_tl +\tl_new:N \l__tag_tmpe_tl +\str_new:N \l__tag_tmpa_str + +\cs_new:Nn\__tag_prop_count:nn { + 1 } %% Loading the tagpdf sub packages \RequirePackage { tagpdf-checks-code } @@ -181,16 +249,17 @@ \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__uftag_mode_lua_bool - { - \RequirePackage {tagpdf-mc-code-lua} - } - { - \RequirePackage { tagpdf-mc-code-generic } % - } +\bool_if:NTF \g__tag_mode_lua_bool + { + \RequirePackage {tagpdf-mc-code-lua} + } + { + \RequirePackage { tagpdf-mc-code-generic } % + } \RequirePackage { tagpdf-struct-code } \RequirePackage { tagpdf-space-code } -\endinput +%% +%% +%% End of file `tagpdf.sty'. diff --git a/Master/texmf-dist/tex/latex/tagpdf/tagpdfdocu-patches.sty b/Master/texmf-dist/tex/latex/tagpdf/tagpdfdocu-patches.sty index d810bef9f1b..2032895ec2a 100644 --- a/Master/texmf-dist/tex/latex/tagpdf/tagpdfdocu-patches.sty +++ b/Master/texmf-dist/tex/latex/tagpdf/tagpdfdocu-patches.sty @@ -1,7 +1,7 @@ \RequirePackage{expl3}[2018/06/14] %\RequirePackage[enable-debug]{expl3}[2018/06/14] \RequirePackage{xpatch} -\ProvidesExplPackage {tagpdfdocu-patches} {2019/07/02} {0.61} +\ProvidesExplPackage {tagpdfdocu-patches} {2019/10/15} {0.70} {patches/commands for the tagpdf documentation} % to do : marginnote, perhaps the description macros ... @@ -30,20 +30,20 @@ \NewDocumentCommand\TagP{t{^}} { - \uftag_mc_if_in:T { \uftag_mc_end: } + \tag_mc_if_in:T { \tag_mc_end: } \IfBooleanF{#1} { - \uftag_struct_end: + \tag_struct_end: } - \uftag_struct_begin:n{tag=P} - \uftag_mc_begin:n{tag=P} + \tag_struct_begin:n{tag=P} + \tag_mc_begin:n{tag=P} } % close a mc and one structure \NewDocumentCommand\TagPend{} { - \uftag_mc_if_in:T { \uftag_mc_end: } - \uftag_struct_end: + \tag_mc_if_in:T { \tag_mc_end: } + \tag_struct_end: } @@ -58,15 +58,15 @@ %Marking the toc entries %around the whole entry so only structure: -\newcommand\tagscrtocentry[1]{\uftag_struct_begin:n{tag=TOCI}#1\uftag_struct_end:} +\newcommand\tagscrtocentry[1]{\tag_struct_begin:n{tag=TOCI}#1\tag_struct_end:} %leaf so structure and mc: \newcommand\tagscrtocpagenumber[1]{% - \uftag_struct_begin:n{tag=Reference}% - \uftag_mc_begin:n{tag=Reference}% + \tag_struct_begin:n{tag=Reference}% + \tag_mc_begin:n{tag=Reference}% #1% - \uftag_mc_end: - \uftag_struct_end:} + \tag_mc_end: + \tag_struct_end:} \DeclareTOCStyleEntry[ @@ -85,9 +85,9 @@ \renewcommand{\addtocentrydefault}[3]{% - \ifstr{#3}{}{} + \Ifstr{#3}{}{} {%\ - \ifstr{#2}{} + \Ifstr{#2}{} {% \addcontentsline{toc}{#1} {% @@ -118,7 +118,7 @@ \renewcommand*{\TOCLineLeaderFill}[1][.]{ \leaders\hbox{$\m@th - \mkern \@dotsep mu\hbox{\uftag_mc_begin:n{artifact}#1\uftag_mc_end:}\mkern \@dotsep + \mkern \@dotsep mu\hbox{\tag_mc_begin:n{artifact}#1\tag_mc_end:}\mkern \@dotsep mu$}\hfill } @@ -142,34 +142,34 @@ \tagstructbegin{tag=\prop_item:Nn\g_tag_section_level_prop{#1}} \tl_if_empty:nF{#3} { - \uftag_mc_begin:n {tag=\prop_item:Nn\g_tag_section_level_prop{#1}} + \tag_mc_begin:n {tag=\prop_item:Nn\g_tag_section_level_prop{#1}} #3 - \uftag_mc_end: + \tag_mc_end: } } - {\uftag_mc_begin:n {tag=\prop_item:Nn\g_tag_section_level_prop{#1}} + {\tag_mc_begin:n {tag=\prop_item:Nn\g_tag_section_level_prop{#1}} #4 - \uftag_mc_end:\tagstructend}% + \tag_mc_end:\tagstructend}% } %minisec is simply P, H6 doesn't work .... -\cs_new:Nn \__uftag_docu_tag_minisec:n +\cs_new:Nn \__tag_docu_tag_minisec:n { - \uftag_struct_begin:n {tag=P} - \uftag_mc_begin:n{tag=P} + \tag_struct_begin:n {tag=P} + \tag_mc_begin:n{tag=P} #1 - \uftag_mc_end: - \uftag_struct_end: + \tag_mc_end: + \tag_struct_end: } -\addtokomafont{minisec}{\__uftag_docu_tag_minisec:n} +\addtokomafont{minisec}{\__tag_docu_tag_minisec:n} -\AfterTOCHead{\uftag_struct_begin:n{tag=TOC}} -\AfterStartingTOC{\uftag_struct_end:} %end TOC +\AfterTOCHead{\tag_struct_begin:n{tag=TOC}} +\AfterStartingTOC{\tag_struct_end:} %end TOC %% list -\newcommand\uftag@enit@format@preset[1]{% +\newcommand\tag@enit@format@preset[1]{% \tagstructbegin{tag=LI}% \tagstructbegin{tag=Lbl}% \tagmcbegin{tag=Lbl}% @@ -190,7 +190,7 @@ } \ExplSyntaxOff -\xpatchcmd\enit@preset{\@firstofone}{\uftag@enit@format@preset}{}{\fail} +\xpatchcmd\enit@preset{\@firstofone}{\tag@enit@format@preset}{}{\fail} \ExplSyntaxOn \setlist{ before*=\tagstructbegin{tag=L}, @@ -209,62 +209,95 @@ %%% attention, to get the order right, it is necessary currently to start a new %%% mc after a link! I'm not sure if this can/group be included in the hooks %%% grouping is a bit tricky ... -\cs_if_exist:NT\hook_put_left:nnn -{ - \hook_put_left:nnn - { pdf } - { link_begin_url } - { - \uftag_struct_begin:n{tag=Link} - \uftag_mc_begin:n{tag=Link} - } -\hook_put:nnnn - { pdf } - { link_begin_url_attr } - { /StructParent } - { \int_use:N\c@g__uftag_parenttree_obj_int } - -\hook_put_right:nnn - { pdf } - { link_end_url } - { - \__uftag_struct_finish_link: - \uftag_mc_end: - \uftag_struct_end: - } +%\cs_if_exist:NT\hook_put_left:nnn +%{ +% \hook_put_left:nnn +% { pdf } +% { annot/Link/URI_begin } +% { +% \tag_struct_begin:n{tag=Link} +% \tag_mc_begin:n{tag=Link} +% } + +\cs_generate_variant:Nn \pdfannot_dict_put:nnn {nnx} +\hook_gput_code:nnn + {pdfannot/link/URI/before} + {tagpdf} + { + \tag_struct_begin:n{tag=Link} + \tag_mc_begin:n{tag=Link} + \pdfannot_dict_put:nnx + {link/URI} + { StructParent } + { \int_use:N\c@g__tag_parenttree_obj_int } + } + +%\hook_put_right:nnn +% { pdf } +% { annot/Link/URI_end } +% { +% \__tag_struct_finish_link: +% \tag_mc_end: +% \tag_struct_end: +% } +\hook_gput_code:nnn + {pdfannot/link/URI/after} + {tagpdf} + { + \__tag_struct_finish_link: + \tag_mc_end: + \tag_struct_end: + } + +%\hook_put_left:nnn +% { pdf } +% { annot/Link/GoTo_begin } +% { +% \tag_struct_begin:n{tag=Link} +% \tag_mc_begin:n{tag=Link} +% } + +\hook_gput_code:nnn + {pdfannot/link/GoTo/before} + {tagpdf} + { + \tag_struct_begin:n{tag=Link} + \tag_mc_begin:n{tag=Link} + \pdfannot_dict_put:nnx + {link/GoTo} + { StructParent } + { \int_use:N\c@g__tag_parenttree_obj_int } + } + -\hook_put_left:nnn - { pdf } - { link_begin_link } - { - \uftag_struct_begin:n{tag=Link} - \uftag_mc_begin:n{tag=Link} - } -\hook_put:nnnn - { pdf } - { link_begin_link_attr } - { /StructParent } - { \int_use:N\c@g__uftag_parenttree_obj_int } -\hook_put_right:nnn - { pdf } - { link_end_link } - { - \__uftag_struct_finish_link: - \uftag_mc_end: - \uftag_struct_end: - } + +%\hook_put_right:nnn +% { pdf } +% { annot/link/GoTo_end } +% { +% \__tag_struct_finish_link: +% \tag_mc_end: +% \tag_struct_end: +% } + +\hook_gput_code:nnn + {pdfannot/link/GoTo/after} + {tagpdf} + { + \__tag_struct_finish_link: + \tag_mc_end: + \tag_struct_end: + } % "alternative descriptions " for PAX3. How to get better text here?? -\hook_put:nnnn - { pdf } - { link_begin_url_attr } - { /Contents } +\pdfannot_dict_put:nnx + {link/URI} + { Contents } { (url) } -\hook_put:nnnn - { pdf } - { link_begin_link_attr } - { /Contents } +\pdfannot_dict_put:nnx + {link/GoTo} + { Contents } { (ref) } - } + \endinput -- cgit v1.2.3