[latex3-commits] [git/LaTeX3-latex3-latex2e] options: Implement load/preamble restrictions (628382e8)

Joseph Wright joseph.wright at morningstar2.co.uk
Wed Jan 12 18:26:18 CET 2022


Repository : https://github.com/latex3/latex2e
On branch  : options
Link       : https://github.com/latex3/latex2e/commit/628382e81261eaf2ea8bf8c20c4933f297cf88f3

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

commit 628382e81261eaf2ea8bf8c20c4933f297cf88f3
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Tue Nov 30 13:41:19 2021 +0000

    Implement load/preamble restrictions
    
    This uses Ulrike's scheme: next task is to swap out
    option clash detection.


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

628382e81261eaf2ea8bf8c20c4933f297cf88f3
 base/ltkeys.dtx | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 77 insertions(+), 7 deletions(-)

diff --git a/base/ltkeys.dtx b/base/ltkeys.dtx
index 4358f41e..6b7746c4 100644
--- a/base/ltkeys.dtx
+++ b/base/ltkeys.dtx
@@ -143,6 +143,21 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{variable}{\l_@@_options_loading_bool}
+%   Used to indicate we are in the loading phase: controls the outcome
+%   of warnings.
+%    \begin{macrocode}
+\bool_new:N \l_@@_options_loading_bool
+%    \end{macrocode}
+% \end{variable}
+%
+% \begin{variable}{\l_@@_options_module_prop}
+%   To track non-standard module names.
+%    \begin{macrocode}
+\prop_new:N \l_@@_options_module_prop
+%    \end{macrocode}
+% \end{variable}
+%
 % \begin{macro}{\@@_options:Nn}
 % \begin{macro}{\@@_options_end:}
 %   The main function calls functions to collect up the global and local
@@ -154,6 +169,8 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_options:Nn #1#2
   {
+    \str_if_eq:nVF {#2} \@currname
+      { \prop_put:NnV \l_@@_options_module_prop {#2} \@currname }
     \cs_set_protected:Npn \@@_option_end: { }
     \clist_clear:N \l_@@_options_clist
     \@@_options_global:Nn #1 {#2}
@@ -171,7 +188,9 @@
         \cs_set_protected:Npn \@@_option_end:
           { \keys_define:nn {#2} { unknown .undefine: } }
       }
+    \bool_set_true: \l_@@_options_loading_bool
     \keys_set:nn {#2} \l_@@_options_clist
+    \bool_set_false:N \l_@@_options_loading_bool
     \cs_set_eq:NN \@unprocessedoptions \scan_stop:
     \@@_option_end:
   }
@@ -317,13 +336,19 @@
   {
     \IfNoValueTF {#1}
       { \@@_options_group_check:N \c_true_bool }
-      { \@@_options:Nn \c_true_bool {#1} }
+      {
+        \@@_options:Nn \c_true_bool {#1}
+        \@@_options_loaded:n {#1}
+      }
   }
 \NewDocumentCommand \ProcessKeysPackageOptions { o }
   {
     \IfNoValueTF {#1}
       { \@@_options_group_check:N \c_false_bool }
-      { \@@_options:Nn \c_false_bool {#1} }
+      {
+        \@@_options:Nn \c_false_bool {#1}
+        \@@_options_loaded:n {#1}
+      }
   }
 \@onlypreamble \ProcessKeysOptions
 \@onlypreamble \ProcessKeysPackageOptions
@@ -333,6 +358,7 @@
       { \@@_options:Nn #1 }
       {
         \exp_args:NNV \@@_options:Nn #1 \@currname
+        \exp_args:NV \@@_options_loaded:n \@currname
       }
   }
 %    \end{macrocode}
@@ -341,17 +367,61 @@
 %
 % \subsection{Option usage scope}
 %
+% \begin{macro}{\@@_options_loaded:n}
+% \begin{macro}{\@@_options_loaded:nn}
+%   Indicates that the load-time options for a package have been processed:
+%   once this has happened, make them unavailable either with a warning or
+%   an error.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_options_loaded:n #1
+  {
+    \prop_get:NnNT \l_keys_usage_load_prop {#1} \l_@@_tmpa_tl
+      {
+        \clist_map_inline:Nn \l_@@_tmpa_tl
+          {
+            \keys_set:nn {#1}
+              {
+                ##1 .code:n =
+                  \prop_get:NnNTF \l_@@_options_module_prop {#1} \l_@@_tmpa_tl
+                    { \exp_args:NV \@@_options_loaded:nn \l_@@_tmpa_tl }
+                    { \@@_options_loaded:nn {#1} }
+                      {##1}
+              }
+          }
+      }
+  }
+\cs_new_protected:Npn \@@_options_loaded:nn
+  {
+    \bool_if:NTF \l_@@_options_loading_bool
+      { \msg_warning:nnn { keys } { load-option-ignored } }
+      { \msg_error:nnnn { keys } { load-only } }
+        {#1} {#2}
+  }
+\msg_new:nnn { keys } { load-option-ignored }
+  { Package~"#1"~has~already~been~loaded:~ignoring~load-time~option~"#2". }
+\msg_new:nnnn { keys } { load-only }
+  { Key~"#2"~may~only~be~used~in~the~during~loading~of~package~"#1". }
+  {
+    LaTeX~was~asked~to~set~a~key~called~"#2",~but~this~is~only~allowed~
+    in~the~optional~argument~when~loading~package~"#1".
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
 %  Disable all preamble options in one shot.
 %    \begin{macrocode}
 \tl_gput_left:Nn \@kernel at after@begindocument
   {
-    \seq_map_inline:Nn \l_keys_usage_preamble_seq
+    \prop_map_inline:Nn \l_keys_usage_preamble_prop
       {
-        \keys_set:nn { }
+        \clist_map_inline:nn {#1}
           {
-            #1 .code:n =
-              \msg_error:nnx { keys } { preamble-only }
-                { \l_keys_key_str }
+            \keys_set:nn {#1}
+              {
+                ##1 .code:n =
+                  \msg_error:nnn { keys } { preamble-only } {##1}
+              }
           }
       }
   }





More information about the latex3-commits mailing list.