[latex3-commits] [latex3/tagpdf] para-hooks-to-sockets: start moving para-hook into sockets, WIP (e6e6be6)

github at latex-project.org github at latex-project.org
Fri Feb 2 01:11:51 CET 2024


Repository : https://github.com/latex3/tagpdf
On branch  : para-hooks-to-sockets
Link       : https://github.com/latex3/tagpdf/commit/e6e6be64a07dd2a493c471a8419992e1b3c89847

>---------------------------------------------------------------

commit e6e6be64a07dd2a493c471a8419992e1b3c89847
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Fri Feb 2 01:11:51 2024 +0100

    start moving para-hook into sockets, WIP


>---------------------------------------------------------------

e6e6be64a07dd2a493c471a8419992e1b3c89847
 tagpdf-user.dtx | 193 +++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 134 insertions(+), 59 deletions(-)

diff --git a/tagpdf-user.dtx b/tagpdf-user.dtx
index ebdc8ce..6f0788b 100644
--- a/tagpdf-user.dtx
+++ b/tagpdf-user.dtx
@@ -736,6 +736,7 @@
 %   \g_@@_para_end_int,
 %   \g_@@_para_main_begin_int,
 %   \g_@@_para_main_end_int,
+%   \g_@@_para_main_struct_tl,
 %   \l_@@_para_tag_default_tl,
 %   \l_@@_para_tag_tl,
 %   \l_@@_para_main_tag_tl,
@@ -752,6 +753,10 @@
 \int_new:N  \g_@@_para_end_int
 \int_new:N  \g_@@_para_main_begin_int
 \int_new:N  \g_@@_para_main_end_int
+%    \end{macrocode}
+% this will hold the structure number of the current text-unit.
+%    \begin{macrocode}
+\tl_new:N   \g_@@_para_main_struct_tl
 \tl_new:N   \l_@@_para_tag_default_tl
 \tl_set:Nn  \l_@@_para_tag_default_tl { text }
 \tl_new:N   \l_@@_para_tag_tl
@@ -795,7 +800,6 @@
  }
 %    \end{macrocode}
 % \end{macro}
-
 % \begin{macro}{\@@_start_para_ints:,\@@_stop_para_ints:}
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_start_para_ints:
@@ -827,6 +831,16 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% We want to be able to inspect the current para main structure, so 
+% we need a command to store its structure number
+% \begin{macro}{\@@_para_main_store_struct:}
+%    \begin{macrocode}
+\cs_new:Npn \@@_para_main_store_struct: 
+  {
+    \tl_gset:Ne \g_@@_para_main_struct_tl {\int_use:N \c at g_@@_struct_abs_int } 
+  }
+%    \end{macrocode}
+% \end{macro}
 % TEMPORARLY FIX (2023-11-17). Until latex-lab is updated we must adapt a sec command:
 %    \begin{macrocode}
 \AddToHook{package/latex-lab-testphase-sec/after}
@@ -852,7 +866,7 @@
    }
  } 
 %    \end{macrocode}
-% and two adaptions from the block module:
+% and one adaptions from the block module:
 %    \begin{macrocode}
 \AddToHook{package/latex-lab-testphase-block/after}
  {
@@ -860,49 +874,6 @@
     {
       \tl_set:Nn \l_@@_para_attr_class_tl { \l_tag_para_attr_class_tl }
     }
-   \cs_set_protected:Npn \__block_start_para_structure:n #1 {
-     \__block_debug_typeout:n
-        { @endpe = \legacy_if:nTF { @endpe }{true}{false}
-          \on at line }
-     \legacy_if:nF { @endpe }
-       {
-         \bool_if:NF \l__tag_para_flattened_bool
-            {
-              \@@_gincr_para_main_begin_int:
-              \tag_struct_begin:n
-               {
-                tag=\l_@@_para_main_tag_tl,
-                attribute-class=\l_@@_para_main_attr_class_tl,
-               }
-            }
-        }
-     \@@_gincr_para_begin_int:
-     \__block_debug_typeout:n{increment~ P \on at line }
-     \tag_struct_begin:n
-         {
-            tag=\l__tag_para_tag_tl
-           ,attribute-class=\l_@@_para_attr_class_tl
-         }
-     \__tag_check_para_begin_show:nn {green}{#1}    
-     \tag_mc_begin:n {}
-  }
-  \RemoveFromHook{para/end}[latex-lab-testphase-block]
-  \AddToHook{para/end}[latex-lab-testphase-block]
-   {
-    \bool_if:NT \l__tag_para_bool
-      {
-        \__tag_gincr_para_end_int:
-        \__block_debug_typeout:n{increment~ /P \on at line }
-        \tag_mc_end:
-        \__tag_check_para_end_show:nn {red}{}
-        \tag_struct_end:
-        \bool_if:NF \l__tag_para_flattened_bool
-         {
-           \__tag_gincr_para_main_end_int:
-           \tag_struct_end:
-         }
-      }
-   }
 } 
   
 %    \end{macrocode}
@@ -934,7 +905,7 @@
   }
 %    \end{macrocode}
 % \end{macro}
-% This fills the para hooks with the needed code.
+% Helper command for debugging: 
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_check_para_begin_show:nn #1 #2 
  %#1 color, #2 prefix
@@ -957,26 +928,71 @@
         \tag_mc_end:
       }
   }
+%    \end{macrocode}
+%
+% The para/begin and para/end code.
+% We have two variants here: a simpler one, which must be used
+% if the block code is not used (and so probably will disappear
+% at some time) and a more sophisticated one that must
+% be used if the block code is used.
+% It is possible that we will need more variants, so
+% we setup a socket so that the code can be easily switched.  
+%    \begin{macrocode}
+\socket_new:nn      {tagsupport/para/begin}{0}
+\socket_new:nn      {tagsupport/para/end}{0}
 
-\AddToHook{para/begin}
-  {
+\socket_new_plug:nnn{tagsupport/para/begin}{plain}
+ {
    \bool_if:NT \l_@@_para_bool
      {
        \bool_if:NF \l_@@_para_flattened_bool
+          {
+            \@@_gincr_para_main_begin_int:
+            \tag_struct_begin:n
+              {
+                tag=\l_@@_para_main_tag_tl,
+              }
+            \@@_para_main_store_struct:   
+          }
+        \@@_gincr_para_begin_int:
+        \tag_struct_begin:n {tag=\l_@@_para_tag_tl}
+        \@@_check_para_begin_show:nn {green}{}
+        \tag_mc_begin:n {}
+     }   
+ }
+\socket_new_plug:nnn{tagsupport/para/begin}{block}
+ {
+   \bool_if:NT \l_@@_para_bool
+     {
+      \__block_debug_typeout:n
+        { @endpe = \legacy_if:nTF { @endpe }{true}{false}
+          \on at line }
+      \legacy_if:nF { @endpe }
+       {
+         \bool_if:NF \l_@@_para_flattened_bool
+            {
+              \@@_gincr_para_main_begin_int:
+              \tag_struct_begin:n
+               {
+                tag=\l_@@_para_main_tag_tl,
+                attribute-class=\l_@@_para_main_attr_class_tl,
+               }
+              \@@_para_main_store_struct: 
+            }
+        }
+       \@@_gincr_para_begin_int:
+       \__block_debug_typeout:n{increment~ P \on at line }
+       \tag_struct_begin:n
          {
-           \@@_gincr_para_main_begin_int:
-           \tag_struct_begin:n
-             {
-               tag=\l_@@_para_main_tag_tl,
-             }
+           tag=\l_@@_para_tag_tl
+           ,attribute-class=\l_@@_para_attr_class_tl
          }
-       \@@_gincr_para_begin_int:
-       \tag_struct_begin:n {tag=\l_@@_para_tag_tl}
-       \@@_check_para_begin_show:nn {green}{}
+       \@@_check_para_begin_show:nn {green}{\PARALABEL}    
        \tag_mc_begin:n {}
-     }
-  }
-\AddToHook{para/end}
+      }
+ }
+
+\socket_new_plug:nnn{tagsupport/para/end}{plain}
   {
     \bool_if:NT \l_@@_para_bool
       {
@@ -992,6 +1008,65 @@
       }
   }
 %    \end{macrocode}
+% there is no real difference in the block variant. Only 
+% a debug message. TODO: unify this. 
+%    \begin{macrocode}
+\socket_new_plug:nnn{tagsupport/para/end}{block}
+  {
+    \bool_if:NT \l_@@_para_bool
+      {
+        \@@_gincr_para_end_int:
+        \__block_debug_typeout:n{increment~ /P \on at line }
+        \tag_mc_end:
+        \@@_check_para_end_show:nn {red}{}
+        \tag_struct_end:
+        \bool_if:NF \l__tag_para_flattened_bool
+         {
+           \__tag_gincr_para_main_end_int:
+           \tag_struct_end:
+         }
+      }  
+  }
+ 
+%    \end{macrocode}
+% By default we assign the plain plug:
+%    \begin{macrocode}
+\socket_assign_plug:nn { tagsupport/para/begin}{plain}
+\socket_assign_plug:nn { tagsupport/para/end}{plain}
+%    \end{macrocode}
+% And use the sockets in the hooks:
+%    \begin{macrocode}
+\AddToHook{para/begin}
+  {
+    \socket_use:n { tagsupport/para/begin }
+  }
+\AddToHook{para/end}
+  {
+    \socket_use:n { tagsupport/para/end }
+  }
+%    \end{macrocode}
+%
+% If the block code is loaded we need to ensure that it doesn't overwrite
+% the hook again. And we must reassign the plug.
+%    \begin{macrocode}
+\AddToHook{package/latex-lab-testphase-block/after}
+ {
+   \RemoveFromHook{para/begin}[latex-lab-testphase-block]
+   \RemoveFromHook{para/end}[latex-lab-testphase-block]
+   \AddToHook{para/begin}[tagpdf]
+    {
+      \socket_use:n { tagsupport/para/begin }
+    }
+  \AddToHook{para/end}[tagpdf]
+    {
+      \socket_use:n { tagsupport/para/end }
+    }
+  \socket_assign_plug:nn { tagsupport/para/begin}{block}
+  \socket_assign_plug:nn { tagsupport/para/end}{block}
+ } 
+
+%    \end{macrocode}
+%
 % We check the para count at the end. If tagging is not active it is not a error,
 % but we issue a warning as it perhaps indicates that the testphase code didn't guard
 % everything correctly.





More information about the latex3-commits mailing list.