[latex3-commits] [l3svn] 02/02: Ignore spaces in key names

noreply at latex-project.org noreply at latex-project.org
Sun Nov 8 00:06:06 CET 2015


This is an automated email from the git hooks/post-receive script.

joseph pushed a commit to branch master
in repository l3svn.

commit f31f6fa7795add14d3bb0d797581c7eee8f69806
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Sat Nov 7 23:05:30 2015 +0000

    Ignore spaces in key names
    
    As discussed on LaTeX-L, there is a reasonable logic to this.
---
 l3kernel/l3keys.dtx                     |   70 ++++++++++++++++++++++---------
 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/m3keys005.lvt        |    9 ++++
 l3kernel/testfiles/m3keys005.tlg        |   14 +++++++
 13 files changed, 93 insertions(+), 20 deletions(-)

diff --git a/l3kernel/l3keys.dtx b/l3kernel/l3keys.dtx
index 38b0553..1d465bf 100644
--- a/l3kernel/l3keys.dtx
+++ b/l3kernel/l3keys.dtx
@@ -122,7 +122,8 @@
 % \end{verbatim}
 %
 % Key names may contain any tokens, as they are handled internally
-% using \cs{tl_to_str:n}. As will be discussed in
+% using \cs{tl_to_str:n}; spaces are \emph{ignored} in key names.
+% As will be discussed in
 % section~\ref{sec:l3keys:subdivision}, it is suggested that the character
 % |/| is reserved for sub-division of keys into logical
 % groups. Functions and variables are \emph{not} expanded when creating
@@ -139,7 +140,7 @@
 %
 % \section{Creating keys}
 %
-% \begin{function}{\keys_define:nn}
+% \begin{function}[updated = 2015-11-07]{\keys_define:nn}
 %   \begin{syntax}
 %     \cs{keys_define:nn} \Arg{module} \Arg{keyval list}
 %   \end{syntax}
@@ -599,7 +600,7 @@
 %
 % \section{Setting keys}
 %
-% \begin{function}
+% \begin{function}[updated = 2015-11-07]
 %   {\keys_set:nn, \keys_set:nV, \keys_set:nv, \keys_set:no}
 %   \begin{syntax}
 %     \cs{keys_set:nn} \Arg{module} \Arg{keyval list}
@@ -656,7 +657,7 @@
 %     }
 % \end{verbatim}
 %
-% \begin{function}[added = 2011-08-23, updated = 2014-04-27]
+% \begin{function}[added = 2011-08-23, updated = 2015-11-07]
 %   {
 %     \keys_set_known:nnN, \keys_set_known:nVN,
 %     \keys_set_known:nvN, \keys_set_known:noN,
@@ -720,7 +721,7 @@
 % groups to be made \enquote{active}, or by marking one or more groups to
 % be ignored in key setting.
 %
-% \begin{function}[added = 2013-07-14, updated = 2014-04-27]
+% \begin{function}[added = 2013-07-14, updated = 2015-11-07]
 %   {
 %     \keys_set_filter:nnnN, \keys_set_filter:nnVN,
 %     \keys_set_filter:nnvN, \keys_set_filter:nnoN,
@@ -742,7 +743,7 @@
 %   \meta{keyval list} returned at each stage.
 % \end{function}
 %
-% \begin{function}[added = 2013-07-14]
+% \begin{function}[added = 2013-07-14, updated = 2015-11-07]
 %   {
 %     \keys_set_groups:nnn, \keys_set_groups:nnV,
 %     \keys_set_groups:nnv, \keys_set_groups:nno
@@ -758,7 +759,7 @@
 %
 % \section{Utility functions for keys}
 %
-% \begin{function}[EXP,pTF]{\keys_if_exist:nn}
+% \begin{function}[EXP, pTF, updated = 2015-11-07]{\keys_if_exist:nn}
 %   \begin{syntax}
 %     \cs{keys_if_exist_p:nn} \Arg{module} \Arg{key} \\
 %     \cs{keys_if_exist:nnTF} \Arg{module} \Arg{key} \Arg{true code} \Arg{false code}
@@ -767,7 +768,8 @@
 %   has been defined for \meta{key}.
 % \end{function}
 %
-% \begin{function}[added = 2011-08-21,EXP,pTF]{\keys_if_choice_exist:nnn}
+% \begin{function}[added = 2011-08-21,EXP,pTF, updated = 2015-11-07]
+%   {\keys_if_choice_exist:nnn}
 %   \begin{syntax}
 %     \cs{keys_if_choice_exist_p:nnn} \Arg{module} \Arg{key} \Arg{choice} \\
 %     \cs{keys_if_choice_exist:nnnTF} \Arg{module} \Arg{key} \Arg{choice} \Arg{true code} \Arg{false code}
@@ -1200,7 +1202,7 @@
   { \@@_define:onn \l_@@_module_tl }
 \cs_new_protected:Npn \@@_define:nnn #1#2#3
   {
-    \tl_set:Nx \l_@@_module_tl { \tl_to_str:n {#2} }
+    \tl_set:Nx \l_@@_module_tl { \@@_remove_spaces:n {#2} }
     \keyval_parse:NNn \@@_define_elt:n \@@_define_elt:nn {#3}
     \tl_set:Nn \l_@@_module_tl {#1}
   }
@@ -1263,7 +1265,11 @@
   }
 \cs_new_protected:Npn \@@_property_find:w #1 . #2 \q_stop
   {
-    \tl_set:Nx \l_keys_path_tl { \l_keys_path_tl \tl_to_str:n {#1} }
+    \tl_set:Nx \l_keys_path_tl
+      {
+        \l_keys_path_tl
+        \@@_remove_spaces:n {#1}
+      }
     \tl_if_in:nnTF {#2} { . }
       {
         \tl_set:Nx \l_keys_path_tl { \l_keys_path_tl . }
@@ -1455,7 +1461,7 @@
     \clist_map_inline:nn {#2}
       {
         \int_incr:N \l_keys_choice_int
-        \@@_cmd_set:nx { \l_keys_path_tl / \tl_to_str:n {##1} }
+        \@@_cmd_set:nx { \l_keys_path_tl / \@@_remove_spaces:n {##1} }
           {
             \tl_set:Nn \exp_not:N \l_keys_choice_tl {##1}
             \int_set:Nn \exp_not:N \l_keys_choice_int
@@ -1907,7 +1913,7 @@
   { \@@_set:onn { \l_@@_module_tl } }
 \cs_new_protected:Npn \@@_set:nnn #1#2#3
   {
-    \tl_set:Nx \l_@@_module_tl { \tl_to_str:n {#2} }
+    \tl_set:Nx \l_@@_module_tl { \@@_remove_spaces:n {#2} }
     \keyval_parse:NNn \@@_set_elt:n \@@_set_elt:nn {#3}
     \tl_set:Nn \l_@@_module_tl {#1}
   }
@@ -2040,7 +2046,8 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_set_elt_aux:nnn #1#2#3
   {
-    \tl_set:Nx \l_keys_path_tl { \l_@@_module_tl / \tl_to_str:n {#2} }
+    \tl_set:Nx \l_keys_path_tl
+      { \l_@@_module_tl / \@@_remove_spaces:n {#2} }
     \tl_clear:N \l_@@_module_tl
     \exp_after:wN \@@_find_key_module:w \l_keys_path_tl / \q_stop
     \@@_value_or_default:n {#3}
@@ -2241,7 +2248,7 @@
 %    \begin{macrocode}
 \cs_new:Npn \@@_choice_find:n #1
   {
-    \@@_execute:nn { \l_keys_path_tl / \tl_to_str:n {#1} }
+    \@@_execute:nn { \l_keys_path_tl / \@@_remove_spaces:n {#1} }
       { \@@_execute:nn { \l_keys_path_tl / unknown } { } }
   }
 \cs_new:Npn \@@_multichoice_find:n #1
@@ -2252,12 +2259,34 @@
 %
 % \subsection{Utilities}
 %
+% \begin{macro}[EXP, int]{\@@_remove_spaces:n}
+% \begin{macro}[EXP, aux]{\@@_remove_spaces:w}
+%   Removes all spaces from the input which is detokenized as a result.
+%   This function is set up to be fast (and almost identical to \tn{zap at space}
+%   in \LaTeXe{}) as the use case here is tightly defined.
+%    \begin{macrocode}
+\cs_new:Npn \@@_remove_spaces:n #1
+  { \exp_after:wN \@@_remove_spaces:w \tl_to_str:n {#1} ~ \c_empty_tl }
+\cs_new:Npn \@@_remove_spaces:w #1 ~ #2
+  {
+    #1
+    \if_meaning:w #2 \c_empty_tl
+    \else:
+      \exp_after:wN \@@_remove_spaces:w
+    \fi:
+    #2
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
 % \begin{macro}[EXP,pTF]{\keys_if_exist:nn}
 %   A utility for others to see if a key exists.
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \keys_if_exist:nn #1#2 { p , T , F , TF }
   {
-    \cs_if_exist:cTF { \c_@@_code_root_tl \tl_to_str:n { #1 / #2 } }
+    \cs_if_exist:cTF
+      { \c_@@_code_root_tl \@@_remove_spaces:n { #1 / #2 } }
       { \prg_return_true: }
       { \prg_return_false: }
   }
@@ -2270,7 +2299,8 @@
 \prg_new_conditional:Npnn \keys_if_choice_exist:nnn #1#2#3
   { p , T , F , TF }
   {
-    \cs_if_exist:cTF { \c_@@_code_root_tl \tl_to_str:n { #1 / #2 / #3 } }
+    \cs_if_exist:cTF
+      { \c_@@_code_root_tl \@@_remove_spaces:n { #1 / #2 / #3 } }
       { \prg_return_true: }
       { \prg_return_false: }
   }
@@ -2291,14 +2321,14 @@
     \keys_if_exist:nnTF {#1} {#2}
       {
         \__msg_show_pre:nnxxxx { LaTeX / kernel } { show-key }
-          { \tl_to_str:n { #1 / #2 } } { t } { } { }
+          { \@@_remove_spaces:n { #1 / #2 } } { t } { } { }
         \exp_args:Ncc \@@_show:NN
-          { \c_@@_code_root_tl \tl_to_str:n { #1 / #2 } }
-          { \c_@@_info_root_tl \tl_to_str:n { #1 / #2 } }
+          { \c_@@_code_root_tl \@@_remove_spaces:n { #1 / #2 } }
+          { \c_@@_info_root_tl \@@_remove_spaces:n { #1 / #2 } }
       }
       {
         \__msg_show_pre:nnxxxx { LaTeX / kernel } { show-key }
-          { \tl_to_str:n { #1 / #2 } } { f } { } { }
+          { \@@_remove_spaces:n { #1 / #2 } } { f } { } { }
         \__msg_show_wrap:n { }
       }
   }
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 8a756e6..695a87b 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -2954,6 +2954,8 @@ Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
 Defining \__keys_multichoice_find:n on line ...
+Defining \__keys_remove_spaces:n on line ...
+Defining \__keys_remove_spaces:w on line ...
 Defining \keys_if_exist_p:nn on line ...
 Defining \keys_if_exist:nnT on line ...
 Defining \keys_if_exist:nnF on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index b5fa3b9..60f1210 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -2952,6 +2952,8 @@ Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
 Defining \__keys_multichoice_find:n on line ...
+Defining \__keys_remove_spaces:n on line ...
+Defining \__keys_remove_spaces:w on line ...
 Defining \keys_if_exist_p:nn on line ...
 Defining \keys_if_exist:nnT on line ...
 Defining \keys_if_exist:nnF on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 77e197f..df5e020 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -2952,6 +2952,8 @@ Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
 Defining \__keys_multichoice_find:n on line ...
+Defining \__keys_remove_spaces:n on line ...
+Defining \__keys_remove_spaces:w on line ...
 Defining \keys_if_exist_p:nn on line ...
 Defining \keys_if_exist:nnT on line ...
 Defining \keys_if_exist:nnF on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index b5fa3b9..60f1210 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -2952,6 +2952,8 @@ Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
 Defining \__keys_multichoice_find:n on line ...
+Defining \__keys_remove_spaces:n on line ...
+Defining \__keys_remove_spaces:w on line ...
 Defining \keys_if_exist_p:nn on line ...
 Defining \keys_if_exist:nnT on line ...
 Defining \keys_if_exist:nnF on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index f44f53e..a6e1b56 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -2952,6 +2952,8 @@ Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
 Defining \__keys_multichoice_find:n on line ...
+Defining \__keys_remove_spaces:n on line ...
+Defining \__keys_remove_spaces:w on line ...
 Defining \keys_if_exist_p:nn on line ...
 Defining \keys_if_exist:nnT on line ...
 Defining \keys_if_exist:nnF on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index decab16..dcc129c 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -2955,6 +2955,8 @@ Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
 Defining \__keys_multichoice_find:n on line ...
+Defining \__keys_remove_spaces:n on line ...
+Defining \__keys_remove_spaces:w on line ...
 Defining \keys_if_exist_p:nn on line ...
 Defining \keys_if_exist:nnT on line ...
 Defining \keys_if_exist:nnF on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 1be6057..3d4badd 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -2953,6 +2953,8 @@ Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
 Defining \__keys_multichoice_find:n on line ...
+Defining \__keys_remove_spaces:n on line ...
+Defining \__keys_remove_spaces:w on line ...
 Defining \keys_if_exist_p:nn on line ...
 Defining \keys_if_exist:nnT on line ...
 Defining \keys_if_exist:nnF on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 7c8a4b8..2d48108 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -2953,6 +2953,8 @@ Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
 Defining \__keys_multichoice_find:n on line ...
+Defining \__keys_remove_spaces:n on line ...
+Defining \__keys_remove_spaces:w on line ...
 Defining \keys_if_exist_p:nn on line ...
 Defining \keys_if_exist:nnT on line ...
 Defining \keys_if_exist:nnF on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 1be6057..3d4badd 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -2953,6 +2953,8 @@ Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
 Defining \__keys_multichoice_find:n on line ...
+Defining \__keys_remove_spaces:n on line ...
+Defining \__keys_remove_spaces:w on line ...
 Defining \keys_if_exist_p:nn on line ...
 Defining \keys_if_exist:nnT on line ...
 Defining \keys_if_exist:nnF on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index f1f6ba4..afb0b78 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -2953,6 +2953,8 @@ Defining \__keys_execute:nn on line ...
 Defining \__keys_store_unused: on line ...
 Defining \__keys_choice_find:n on line ...
 Defining \__keys_multichoice_find:n on line ...
+Defining \__keys_remove_spaces:n on line ...
+Defining \__keys_remove_spaces:w on line ...
 Defining \keys_if_exist_p:nn on line ...
 Defining \keys_if_exist:nnT on line ...
 Defining \keys_if_exist:nnF on line ...
diff --git a/l3kernel/testfiles/m3keys005.lvt b/l3kernel/testfiles/m3keys005.lvt
index 302d003..660fe85 100644
--- a/l3kernel/testfiles/m3keys005.lvt
+++ b/l3kernel/testfiles/m3keys005.lvt
@@ -49,5 +49,14 @@
     \keys_set:nn { moduleA } { foobar / test = xxx }
   }
 
+\TEST { Space~handling }
+  {
+    \keys_define:nn { foo }
+      { bar ~ baz .code:n = \tl_show:n {#1} }
+    \keys_set:nn { foo } { barbaz = value-a }
+    \keys_set:nn { foo } { bar ~ baz = value-b }
+    \keys_set:nn { f ~ o ~ o } { barbaz = value-c }
+  }
+
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \END
diff --git a/l3kernel/testfiles/m3keys005.tlg b/l3kernel/testfiles/m3keys005.tlg
index 48a70e0..3001157 100644
--- a/l3kernel/testfiles/m3keys005.tlg
+++ b/l3kernel/testfiles/m3keys005.tlg
@@ -35,3 +35,17 @@ Defining key moduleB/test on line ...
 > xxx.
 > xxx.
 ============================================================
+============================================================
+TEST 3: Space handling
+============================================================
+Defining key foo/barbaz on line ...
+> value-a.
+<recently read> }
+l. ...  }
+> value-b.
+<recently read> }
+l. ...  }
+> value-c.
+<recently read> }
+l. ...  }
+============================================================

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the latex3-commits mailing list