[latex3-commits] [git/LaTeX3-latex3-latex3] master: Allow key inheritance for choice keys (fixes #483) (f1689b4)

Joseph Wright joseph.wright at morningstar2.co.uk
Sun Sep 30 12:42:02 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/f1689b495e655a14ed941d5ca977642e51217b3d

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

commit f1689b495e655a14ed941d5ca977642e51217b3d
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Sun Sep 30 11:41:54 2018 +0100

    Allow key inheritance for choice keys (fixes #483)


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

f1689b495e655a14ed941d5ca977642e51217b3d
 l3kernel/CHANGELOG.md                   |    4 ++++
 l3kernel/l3keys.dtx                     |   23 +++++++++++++++++++++--
 l3kernel/testfiles/m3expl001.luatex.tlg |    2 ++
 l3kernel/testfiles/m3expl001.ptex.tlg   |    2 ++
 l3kernel/testfiles/m3expl001.tlg        |    2 ++
 l3kernel/testfiles/m3expl001.uptex.tlg  |    2 ++
 l3kernel/testfiles/m3expl001.xetex.tlg  |    2 ++
 l3kernel/testfiles/m3expl003.luatex.tlg |    2 ++
 l3kernel/testfiles/m3expl003.ptex.tlg   |    2 ++
 l3kernel/testfiles/m3expl003.tlg        |    2 ++
 l3kernel/testfiles/m3expl003.uptex.tlg  |    2 ++
 l3kernel/testfiles/m3expl003.xetex.tlg  |    2 ++
 l3kernel/testfiles/m3keys003.lvt        |    9 ++++++---
 l3kernel/testfiles/m3keys003.tlg        |   28 +++++++++++++++++++++++++---
 14 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 74cae99..8dfb9b7 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -7,6 +7,10 @@ this project uses date-based 'snapshot' version identifiers.
 
 ## [Unreleased]
 
+### Fixed
+
+- Handling of inheritance for choice keys (fixes #483)
+
 ## [2018-09-24]
 
 ### Added
diff --git a/l3kernel/l3keys.dtx b/l3kernel/l3keys.dtx
index 7195061..9105572 100644
--- a/l3kernel/l3keys.dtx
+++ b/l3kernel/l3keys.dtx
@@ -1207,6 +1207,12 @@
 %    \end{macrocode}
 % \end{variable}
 %
+% \begin{variable}{\l_@@_inherit_tl}
+%    \begin{macrocode}
+\tl_new:N \l_@@_inherit_tl
+%    \end{macrocode}
+% \end{variable}
+%
 % \begin{variable}{\l_@@_property_tl}
 %   The \enquote{property} begin set for a key at definition time is
 %   stored here.
@@ -2339,6 +2345,7 @@
         \cs_if_exist:cT
           { \c_@@_code_root_tl ##1 / \l_keys_key_tl }
           {
+            \tl_set:Nn \l_@@_inherit_tl {##1}
             \cs:w \c_@@_code_root_tl ##1 / \l_keys_key_tl
               \exp_after:wN \cs_end: \exp_after:wN
               { \l_keys_value_tl }
@@ -2384,6 +2391,7 @@
 % \end{macro}
 %
 % \begin{macro}[EXP]{\@@_choice_find:n}
+% \begin{macro}[EXP]{\@@_choice_find:nn}
 % \begin{macro}[EXP]{\@@_multichoice_find:n}
 %   Executing a choice has two parts. First, try the choice given, then
 %   if that fails call the unknown key. That always exists, as it is created
@@ -2392,14 +2400,25 @@
 %    \begin{macrocode}
 \cs_new:Npn \@@_choice_find:n #1
   {
-    \@@_execute:nn { \l_keys_path_tl / \@@_remove_spaces:n {#1} }
-      { \@@_execute:nn { \l_keys_path_tl / unknown } { } }
+    \tl_if_empty:NTF \l_@@_inherit_tl
+      { \@@_choice_find:nn { \l_keys_path_tl } {#1} }
+      {
+        \@@_choice_find:nn
+          { \l_@@_inherit_tl / \l_keys_key_tl } {#1}
+      }
+  }
+\cs_new:Npn \@@_choice_find:nn #1#2
+  {
+    \cs_if_exist:cTF { \c_@@_code_root_tl #1 / \@@_remove_spaces:n {#2} }
+      { \use:c { \c_@@_code_root_tl #1 / \@@_remove_spaces:n {#2} } {#2} }
+      { \use:c { \c_@@_code_root_tl #1 / unknown } {#2} }
   }
 \cs_new:Npn \@@_multichoice_find:n #1
   { \clist_map_function:nN {#1} \@@_choice_find:n }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
+% \end{macro}
 %
 % \subsection{Utilities}
 %
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 5f23e40..53f3b2d 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -3179,6 +3179,7 @@ Defining \l__keys_module_tl on line ...
 Defining \l__keys_no_value_bool on line ...
 Defining \l__keys_only_known_bool on line ...
 Defining \l_keys_path_tl on line ...
+Defining \l__keys_inherit_tl on line ...
 Defining \l__keys_property_tl on line ...
 Defining \l__keys_selective_bool on line ...
 Defining \l__keys_filtered_bool on line ...
@@ -3340,6 +3341,7 @@ Defining \__keys_execute_unknown: on line ...
 Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
+Defining \__keys_choice_find:nn on line ...
 Defining \__keys_multichoice_find:n on line ...
 Defining \__keys_parent:n on line ...
 Defining \__keys_parent:o on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 8ff9edd..d85dbe9 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -3472,6 +3472,7 @@ Defining \l__keys_module_tl on line ...
 Defining \l__keys_no_value_bool on line ...
 Defining \l__keys_only_known_bool on line ...
 Defining \l_keys_path_tl on line ...
+Defining \l__keys_inherit_tl on line ...
 Defining \l__keys_property_tl on line ...
 Defining \l__keys_selective_bool on line ...
 Defining \l__keys_filtered_bool on line ...
@@ -3633,6 +3634,7 @@ Defining \__keys_execute_unknown: on line ...
 Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
+Defining \__keys_choice_find:nn on line ...
 Defining \__keys_multichoice_find:n on line ...
 Defining \__keys_parent:n on line ...
 Defining \__keys_parent:o on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 2bffb8c..b5028b3 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -3472,6 +3472,7 @@ Defining \l__keys_module_tl on line ...
 Defining \l__keys_no_value_bool on line ...
 Defining \l__keys_only_known_bool on line ...
 Defining \l_keys_path_tl on line ...
+Defining \l__keys_inherit_tl on line ...
 Defining \l__keys_property_tl on line ...
 Defining \l__keys_selective_bool on line ...
 Defining \l__keys_filtered_bool on line ...
@@ -3633,6 +3634,7 @@ Defining \__keys_execute_unknown: on line ...
 Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
+Defining \__keys_choice_find:nn on line ...
 Defining \__keys_multichoice_find:n on line ...
 Defining \__keys_parent:n on line ...
 Defining \__keys_parent:o on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 26aff89..7a3a1cb 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -3472,6 +3472,7 @@ Defining \l__keys_module_tl on line ...
 Defining \l__keys_no_value_bool on line ...
 Defining \l__keys_only_known_bool on line ...
 Defining \l_keys_path_tl on line ...
+Defining \l__keys_inherit_tl on line ...
 Defining \l__keys_property_tl on line ...
 Defining \l__keys_selective_bool on line ...
 Defining \l__keys_filtered_bool on line ...
@@ -3633,6 +3634,7 @@ Defining \__keys_execute_unknown: on line ...
 Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
+Defining \__keys_choice_find:nn on line ...
 Defining \__keys_multichoice_find:n on line ...
 Defining \__keys_parent:n on line ...
 Defining \__keys_parent:o on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index f373fa4..95306aa 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -3217,6 +3217,7 @@ Defining \l__keys_module_tl on line ...
 Defining \l__keys_no_value_bool on line ...
 Defining \l__keys_only_known_bool on line ...
 Defining \l_keys_path_tl on line ...
+Defining \l__keys_inherit_tl on line ...
 Defining \l__keys_property_tl on line ...
 Defining \l__keys_selective_bool on line ...
 Defining \l__keys_filtered_bool on line ...
@@ -3378,6 +3379,7 @@ Defining \__keys_execute_unknown: on line ...
 Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
+Defining \__keys_choice_find:nn on line ...
 Defining \__keys_multichoice_find:n on line ...
 Defining \__keys_parent:n on line ...
 Defining \__keys_parent:o on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 5f23e40..53f3b2d 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -3179,6 +3179,7 @@ Defining \l__keys_module_tl on line ...
 Defining \l__keys_no_value_bool on line ...
 Defining \l__keys_only_known_bool on line ...
 Defining \l_keys_path_tl on line ...
+Defining \l__keys_inherit_tl on line ...
 Defining \l__keys_property_tl on line ...
 Defining \l__keys_selective_bool on line ...
 Defining \l__keys_filtered_bool on line ...
@@ -3340,6 +3341,7 @@ Defining \__keys_execute_unknown: on line ...
 Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
+Defining \__keys_choice_find:nn on line ...
 Defining \__keys_multichoice_find:n on line ...
 Defining \__keys_parent:n on line ...
 Defining \__keys_parent:o on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 8ff9edd..d85dbe9 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -3472,6 +3472,7 @@ Defining \l__keys_module_tl on line ...
 Defining \l__keys_no_value_bool on line ...
 Defining \l__keys_only_known_bool on line ...
 Defining \l_keys_path_tl on line ...
+Defining \l__keys_inherit_tl on line ...
 Defining \l__keys_property_tl on line ...
 Defining \l__keys_selective_bool on line ...
 Defining \l__keys_filtered_bool on line ...
@@ -3633,6 +3634,7 @@ Defining \__keys_execute_unknown: on line ...
 Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
+Defining \__keys_choice_find:nn on line ...
 Defining \__keys_multichoice_find:n on line ...
 Defining \__keys_parent:n on line ...
 Defining \__keys_parent:o on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 2bffb8c..b5028b3 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -3472,6 +3472,7 @@ Defining \l__keys_module_tl on line ...
 Defining \l__keys_no_value_bool on line ...
 Defining \l__keys_only_known_bool on line ...
 Defining \l_keys_path_tl on line ...
+Defining \l__keys_inherit_tl on line ...
 Defining \l__keys_property_tl on line ...
 Defining \l__keys_selective_bool on line ...
 Defining \l__keys_filtered_bool on line ...
@@ -3633,6 +3634,7 @@ Defining \__keys_execute_unknown: on line ...
 Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
+Defining \__keys_choice_find:nn on line ...
 Defining \__keys_multichoice_find:n on line ...
 Defining \__keys_parent:n on line ...
 Defining \__keys_parent:o on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 26aff89..7a3a1cb 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -3472,6 +3472,7 @@ Defining \l__keys_module_tl on line ...
 Defining \l__keys_no_value_bool on line ...
 Defining \l__keys_only_known_bool on line ...
 Defining \l_keys_path_tl on line ...
+Defining \l__keys_inherit_tl on line ...
 Defining \l__keys_property_tl on line ...
 Defining \l__keys_selective_bool on line ...
 Defining \l__keys_filtered_bool on line ...
@@ -3633,6 +3634,7 @@ Defining \__keys_execute_unknown: on line ...
 Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
+Defining \__keys_choice_find:nn on line ...
 Defining \__keys_multichoice_find:n on line ...
 Defining \__keys_parent:n on line ...
 Defining \__keys_parent:o on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index f373fa4..95306aa 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -3217,6 +3217,7 @@ Defining \l__keys_module_tl on line ...
 Defining \l__keys_no_value_bool on line ...
 Defining \l__keys_only_known_bool on line ...
 Defining \l_keys_path_tl on line ...
+Defining \l__keys_inherit_tl on line ...
 Defining \l__keys_property_tl on line ...
 Defining \l__keys_selective_bool on line ...
 Defining \l__keys_filtered_bool on line ...
@@ -3378,6 +3379,7 @@ Defining \__keys_execute_unknown: on line ...
 Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
+Defining \__keys_choice_find:nn on line ...
 Defining \__keys_multichoice_find:n on line ...
 Defining \__keys_parent:n on line ...
 Defining \__keys_parent:o on line ...
diff --git a/l3kernel/testfiles/m3keys003.lvt b/l3kernel/testfiles/m3keys003.lvt
index 761b208..3708f824 100644
--- a/l3kernel/testfiles/m3keys003.lvt
+++ b/l3kernel/testfiles/m3keys003.lvt
@@ -159,7 +159,8 @@
   {
     \keys_define:nn { module }
       {
-        key-one .code:n = \tl_show:n {#1}
+        key-one .code:n = \tl_show:n {#1} , 
+        key-two .choices:nn = { a , b } { \tl_show:n {#1} }
       }
     \keys_define:nn { module-two }
       {
@@ -167,11 +168,13 @@
       }
     \keys_set:nn { module-two / path }
       {
-        key-one = a
+        key-one = a ,
+        key-two = b
       }
     \keys_set:nn { module-two / path }
       {
-        key-not-defined = a
+        key-not-defined = a ,
+        key-two = c
       }
   }
 
diff --git a/l3kernel/testfiles/m3keys003.tlg b/l3kernel/testfiles/m3keys003.tlg
index 008eb1b..e85cd4b 100644
--- a/l3kernel/testfiles/m3keys003.tlg
+++ b/l3kernel/testfiles/m3keys003.tlg
@@ -114,7 +114,7 @@ Defining key module/key-one/a on line ...
 Defining key module/key-one/b on line ...
 Defining key module/key-one/c on line ...
 "a"
-"a,c"
+"c"
 "c"
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !
@@ -132,8 +132,8 @@ l. ...  }
 | of these.
 |...............................................
 "a"
-"c,d"
-"c,d"
+"c"
+"d"
 ============================================================
 ============================================================
 TEST 4: .multichoices:nn
@@ -216,9 +216,16 @@ l. ...  }
 TEST 6: .inherit:n
 ============================================================
 Defining key module/key-one on line ...
+Defining key module/key-two on line ...
+Defining key module/key-two/unknown on line ...
+Defining key module/key-two/a on line ...
+Defining key module/key-two/b on line ...
 > a.
 <recently read> }
 l. ...  }
+> b.
+<recently read> }
+l. ...  }
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !
 ! LaTeX error: "kernel/key-unknown"
@@ -235,4 +242,19 @@ l. ...  }
 | 'module-two/path/key-not-defined'.
 | Check that you have spelled the key name correctly.
 |...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "kernel/key-choice-unknown"
+! 
+! Key 'module-two/path/key-two' accepts only a fixed set of choices.
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| The key 'module-two/path/key-two' only accepts predefined values, and 'c' is
+| not one of these.
+|...............................................
 ============================================================





More information about the latex3-commits mailing list