summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tagpdf/tagpdf-struct.dtx
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2022-12-24 03:01:20 +0000
committerNorbert Preining <norbert@preining.info>2022-12-24 03:01:20 +0000
commitda0bd16b0ba9d42d044af47137003788f0b7f773 (patch)
treec7681ad6dfc80d15e6439d6e981c48046acee3f8 /macros/latex/contrib/tagpdf/tagpdf-struct.dtx
parentb2b552bfe4933283e7d61d721bea40b0dd2bb9fb (diff)
CTAN sync 202212240301
Diffstat (limited to 'macros/latex/contrib/tagpdf/tagpdf-struct.dtx')
-rw-r--r--macros/latex/contrib/tagpdf/tagpdf-struct.dtx207
1 files changed, 181 insertions, 26 deletions
diff --git a/macros/latex/contrib/tagpdf/tagpdf-struct.dtx b/macros/latex/contrib/tagpdf/tagpdf-struct.dtx
index dd85e47277..6f6d60ba4b 100644
--- a/macros/latex/contrib/tagpdf/tagpdf-struct.dtx
+++ b/macros/latex/contrib/tagpdf/tagpdf-struct.dtx
@@ -46,7 +46,7 @@
% }^^A
% }
%
-% \date{Version 0.97, released 2022-08-24}
+% \date{Version 0.98, released 2022-12-22}
% \maketitle
% \begin{documentation}
% \section{Public Commands}
@@ -242,7 +242,7 @@
% \begin{macrocode}
%<@@=tag>
%<*header>
-\ProvidesExplPackage {tagpdf-struct-code} {2022-08-24} {0.97}
+\ProvidesExplPackage {tagpdf-struct-code} {2022-12-22} {0.98}
{part of tagpdf - code related to storing structure}
%</header>
% \end{macrocode}
@@ -298,6 +298,14 @@
% \end{macrocode}
% \end{variable}
%
+% \begin{variable}{\g_@@_struct_tag_NS_prop}
+% For the parent-child check, we need the tag and NS of every structure
+% \begin{macrocode}
+\prop_new:N\g_@@_struct_tag_NS_prop
+% \end{macrocode}
+% \end{variable}
+%
+%
% \begin{variable}{\g_@@_struct_stack_current_tl,\l_@@_struct_stack_parent_tmpa_tl}
% The global variable will hold the current structure number. It is already
% defined in \texttt{tagpdf-base}.
@@ -399,6 +407,28 @@
\bool_new:N \l_@@_struct_elem_stash_bool
% \end{macrocode}
% \end{variable}
+%
+% \subsection{Variables used by tagging code of basic elements}
+%
+% \begin{variable}{\g_@@_struct_dest_num_prop}
+% This variable records for (some or all, not clear yet)
+% destination names the related structure number to allow
+% to reference them in a Ref. The key is the destination.
+% It is currently used by the toc-tagging and sec-tagging code.
+% \begin{macrocode}
+\prop_new:N \g_@@_struct_dest_num_prop
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\g_@@_struct_ref_by_dest_prop}
+% This variable contains structures whose Ref key should be updated
+% at the end to point to structured related with this destination.
+% As this is probably need in other places too, it is not only a toc-variable.
+% \begin{macrocode}
+\prop_new:N \g_@@_struct_ref_by_dest_prop
+% \end{macrocode}
+% \end{variable}
+%
% \section{Commands}
%
% The properties must be in some places handled expandably.
@@ -442,7 +472,11 @@
% \begin{macrocode}
\tl_gset:Nn \g_@@_struct_stack_current_tl {0}
% \end{macrocode}
-
+% \begin{macro}{\@@_pdf_name_e:n}
+% \begin{macrocode}
+\cs_new:Npn \@@_pdf_name_e:n #1{\pdf_name_from_unicode_e:n{#1}}
+% \end{macrocode}
+% \end{macro}
%
% \begin{variable}{g_@@_struct_0_prop,g_@@_struct_kids_0_seq}
% \begin{macrocode}
@@ -450,13 +484,17 @@
\@@_new_output_prop_handler:n {0}
\@@_seq_new:c { g_@@_struct_kids_0_seq }
-\@@_prop_gput:cnn
+\@@_prop_gput:cnx
{ g_@@_struct_0_prop }
{ Type }
- { /StructTreeRoot }
-
+ { \pdf_name_from_unicode_e:n {StructTreeRoot} }
+\@@_prop_gput:cnx
+ { g_@@_struct_0_prop }
+ { S }
+ { \pdf_name_from_unicode_e:n {StructTreeRoot} }
+\prop_gput:Nnn \g_@@_struct_tag_NS_prop {0}{{StructTreeRoot}{pdf}}
% \end{macrocode}
% Namespaces are pdf 2.0 but it doesn't harm
% to have an empty entry. We could add a test, but if the code moves into
@@ -468,6 +506,65 @@
{ \pdf_object_ref:n { @@/tree/namespaces } }
% \end{macrocode}
% \end{variable}
+%
+% \subsection{Filling in the tag info}
+
+% \begin{macro}{\@@_struct_set_tag_info:nnn }
+% This adds or updates the tag info to a structure given by a number.
+% We need also the original data, so we store both.
+% \begin{macrocode}
+\pdf_version_compare:NnTF < {2.0}
+ {
+ \cs_new_protected:Npn \@@_struct_set_tag_info:nnn #1 #2 #3
+ %#1 structure number, #2 tag, #3 NS
+ {
+ \@@_prop_gput:cnx
+ { g_@@_struct_#1_prop }
+ { S }
+ { \pdf_name_from_unicode_e:n {#2} } %
+ \prop_gput:Nnn \g_@@_struct_tag_NS_prop {#1}{{#2}{#3}}
+ }
+ }
+ {
+ \cs_new_protected:Npn \@@_struct_set_tag_info:nnn #1 #2 #3
+ {
+ \@@_prop_gput:cnx
+ { g_@@_struct_#1_prop }
+ { S }
+ { \pdf_name_from_unicode_e:n {#2} } %
+ \prop_get:NnNT \g_@@_role_NS_prop {#3} \l_@@_get_tmpc_tl
+ {
+ \@@_prop_gput:cnx
+ { g_@@_struct_#1_prop }
+ { NS }
+ { \l_@@_get_tmpc_tl } %
+ }
+ \prop_gput:Nnn \g_@@_struct_tag_NS_prop {#1}{{#2}{#3}}
+ }
+ }
+\cs_generate_variant:Nn \@@_struct_set_tag_info:nnn {eVV}
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\cc}
+% We also need a way to get the tag info back from parent structures.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_struct_get_tag_info:nNN #1 #2 #3
+ %#1 struct num, #2 tlvar for tag , #3 tlvar for NS
+ {
+ \prop_get:NnNTF \g_@@_struct_tag_NS_prop {#1}\l_@@_get_tmpc_tl
+ {
+ \tl_set:Nx #2{\exp_last_unbraced:NV\use_i:nn \l_@@_get_tmpc_tl}
+ \tl_set:Nx #3{\exp_last_unbraced:NV\use_ii:nn \l_@@_get_tmpc_tl}
+ }
+ {
+ \tl_clear:N#2
+ \tl_clear:N#3
+ }
+ }
+\cs_generate_variant:Nn\@@_struct_get_tag_info:nNN {eNN}
+% \end{macrocode}
+% \end{macro}
% \subsection{Handlings kids}
% Commands to store the kids. Kids in a structure can be a reference to a mc-chunk,
% an object reference to another structure element, or a object reference to an
@@ -857,21 +954,10 @@
parent .default:n = {-1},
tag .code:n = % S property
{
- \seq_set_split:Nne \l_@@_tmpa_seq { / } {#1/\prop_item:No\g__tag_role_tags_NS_prop{#1}}
- \tl_gset:Nx \g_@@_struct_tag_tl { \seq_item:Nn\l_@@_tmpa_seq {1} }
- \tl_gset:Nx \g_@@_struct_tag_NS_tl { \seq_item:Nn\l_@@_tmpa_seq {2} }
+ \seq_set_split:Nne \l_@@_tmpa_seq { / } {#1/\prop_item:Ne\g__tag_role_tags_NS_prop{#1}}
+ \tl_gset:Nx \g_@@_struct_tag_tl { \seq_item:Nn\l_@@_tmpa_seq {1} }
+ \tl_gset:Nx \g_@@_struct_tag_NS_tl{ \seq_item:Nn\l_@@_tmpa_seq {2} }
\@@_check_structure_tag:N \g_@@_struct_tag_tl
- \@@_prop_gput:cnx
- { g_@@_struct_\int_eval:n {\c@g_@@_struct_abs_int}_prop }
- { S }
- { \pdf_name_from_unicode_e:n{ \g_@@_struct_tag_tl} } %
- \prop_get:NVNT \g_@@_role_NS_prop\g_@@_struct_tag_NS_tl\l_@@_tmpa_tl
- {
- \@@_prop_gput:cnx
- { g_@@_struct_\int_eval:n {\c@g_@@_struct_abs_int}_prop }
- { NS }
- { \l_@@_tmpa_tl } %
- }
},
title .code:n = % T property
{
@@ -1114,7 +1200,13 @@
{ /StructElem }
\tl_set:Nn \l_@@_struct_stack_parent_tmpa_tl {-1}
\keys_set:nn { @@ / struct} { #1 }
- \@@_check_structure_has_tag:n { \int_eval:n {\c@g_@@_struct_abs_int} }
+% \end{macrocode}
+% \begin{macrocode}
+ \@@_struct_set_tag_info:eVV
+ { \int_eval:n {\c@g_@@_struct_abs_int} }
+ \g_@@_struct_tag_tl
+ \g_@@_struct_tag_NS_tl
+ \@@_check_structure_has_tag:n { \int_eval:n {\c@g_@@_struct_abs_int} }
\tl_if_empty:NF
\l_@@_struct_key_label_tl
{
@@ -1139,7 +1231,43 @@
%\seq_show:N \g_@@_struct_stack_seq
\bool_if:NF
\l_@@_struct_elem_stash_bool
- {%set the parent
+ {
+% \end{macrocode}
+% check if the tag can be used inside the parent. It only makes sense,
+% if the structure is actually used here, so it is guarded by the stash boolean.
+% For now we ignore the namespace!
+% \begin{macrocode}
+ \@@_struct_get_tag_info:eNN
+ {\l_@@_struct_stack_parent_tmpa_tl}
+ \l_@@_get_parent_tmpa_tl
+ \l_@@_get_parent_tmpb_tl
+ \@@_check_parent_child:VVVVN
+ \l_@@_get_parent_tmpa_tl
+ \l_@@_get_parent_tmpb_tl
+ \g_@@_struct_tag_tl
+ \g_@@_struct_tag_NS_tl
+ \l_@@_parent_child_check_tl
+ \int_compare:nNnT {\l_@@_parent_child_check_tl}<0
+ {
+ \msg_warning:nnxxx
+ { tag }
+ {role-parent-child}
+ { \l_@@_get_parent_tmpa_tl/\l_@@_get_parent_tmpb_tl }
+ { \g_@@_struct_tag_tl/\g_@@_struct_tag_NS_tl }
+ { not~allowed~(struct~\g_@@_struct_stack_current_tl) }
+ \cs_set_eq:NN \l_@@_role_remap_tag_tl \g_@@_struct_tag_tl
+ \cs_set_eq:NN \l_@@_role_remap_NS_tl \g_@@_struct_tag_NS_tl
+ \@@_role_remap:
+ \cs_gset_eq:NN \g_@@_struct_tag_tl \l_@@_role_remap_tag_tl
+ \cs_gset_eq:NN \g_@@_struct_tag_NS_tl \l_@@_role_remap_NS_tl
+ \@@_struct_set_tag_info:eVV
+ { \int_eval:n {\c@g_@@_struct_abs_int} }
+ \g_@@_struct_tag_tl
+ \g_@@_struct_tag_NS_tl
+ }
+% \end{macrocode}
+% Set the Parent.
+% \begin{macrocode}
\@@_prop_gput:cnx
{ g_@@_struct_\int_eval:n {\c@g_@@_struct_abs_int}_prop }
{ P }
@@ -1202,7 +1330,7 @@
%<base>\cs_new_protected:Npn \tag_struct_use:n #1 {}
%<*package>
\cs_set_protected:Npn \tag_struct_use:n #1 %#1 is the label
- {
+ {
\@@_check_if_active_struct:T
{
\prop_if_exist:cTF
@@ -1220,6 +1348,33 @@
{
\pdf_object_ref:e { @@/struct/\g_@@_struct_stack_current_tl }
}
+% \end{macrocode}
+% check if the tag is allowed as child. Here we have to retrieve the
+% tag info for the child, while the data for the parent is in
+% the global tl-vars:
+% \begin{macrocode}
+ \@@_struct_get_tag_info:eNN
+ {\__tag_ref_value:enn{tagpdfstruct-#1}{tagstruct}{0}}
+ \l_@@_tmpa_tl
+ \l_@@_tmpb_tl
+ \@@_check_parent_child:VVVVN
+ \g_@@_struct_tag_tl
+ \g_@@_struct_tag_NS_tl
+ \l_@@_tmpa_tl
+ \l_@@_tmpb_tl
+ \l_@@_parent_child_check_tl
+ \int_compare:nNnT {\l_@@_parent_child_check_tl}<0
+ {
+ \cs_set_eq:NN \l_@@_role_remap_tag_tl \g_@@_struct_tag_tl
+ \cs_set_eq:NN \l_@@_role_remap_NS_tl \g_@@_struct_tag_NS_tl
+ \@@_role_remap:
+ \cs_gset_eq:NN \g_@@_struct_tag_tl \l_@@_role_remap_tag_tl
+ \cs_gset_eq:NN \g_@@_struct_tag_NS_tl \l_@@_role_remap_NS_tl
+ \@@_struct_set_tag_info:eVV
+ { \int_eval:n {\c@g_@@_struct_abs_int} }
+ \g_@@_struct_tag_tl
+ \g_@@_struct_tag_NS_tl
+ }
}
{
\msg_warning:nnn{ tag }{struct-label-unknown}{#1}
@@ -1271,11 +1426,11 @@
\prop_get:cnN
{ g_@@_struct_#1_prop }
{Ref}
- \l_@@_tmpb_tl
+ \l_@@_get_tmpc_tl
\@@_prop_gput:cnx
{ g_@@_struct_#1_prop }
{ Ref }
- { \quark_if_no_value:NF\l_@@_tmpb_tl { \l_@@_tmpb_tl\c_space_tl }#2 }
+ { \quark_if_no_value:NF\l_@@_get_tmpc_tl { \l_@@_get_tmpc_tl\c_space_tl }#2 }
}
\cs_generate_variant:Nn \@@_struct_gput_data_ref:nn {ee}
% \end{macrocode}
@@ -1319,7 +1474,7 @@
% \section{Attributes and attribute classes}
% \begin{macrocode}
%<*header>
-\ProvidesExplPackage {tagpdf-attr-code} {2022-08-24} {0.97}
+\ProvidesExplPackage {tagpdf-attr-code} {2022-12-22} {0.98}
{part of tagpdf - code related to attributes and attribute classes}
%</header>
% \end{macrocode}